Skip to content

Commit c80add3

Browse files
committed
Version 0.1.11, add publish GHA, add some fixes and clean up error output when missing API key
1 parent 9b050ed commit c80add3

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
name: Publish chatpdb
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.x'
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install build
26+
- name: Build package
27+
run: python -m build
28+
- name: Publish package
29+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
30+
with:
31+
password: ${{ secrets.PYPI_API_TOKEN }}

chatpdb/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def _get_debugger_cls():
4949

5050
# Let IPython decide about which debugger class to use
5151
# This is especially important for tools that fiddle with stdout
52+
if getattr(type(shell), "__module__", "").startswith("google.colab"):
53+
# Google Colab has its own debugger, ChatPdb seems to work though
54+
return ChatPdb
5255
return ChatPdb if shell.simple_prompt else TerminalChatPdb
5356

5457

chatpdb/chat/llm/openai.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
from pydantic import BaseModel
66

77

8-
client = OpenAI(
9-
api_key=os.environ.get("CHAT_PDB_OPENAI_API_KEY")
10-
or os.environ.get("OPENAI_API_KEY"),
11-
organization=os.environ.get("CHAT_PDB_OPENAI_ORG_ID")
12-
or os.environ.get("OPENAI_ORG_ID"),
13-
)
8+
def get_client() -> OpenAI:
9+
api_key = os.environ.get("CHAT_PDB_OPENAI_API_KEY") or os.environ.get(
10+
"OPENAI_API_KEY"
11+
)
12+
organization = os.environ.get("CHAT_PDB_OPENAI_ORG_ID") or os.environ.get(
13+
"OPENAI_ORG_ID"
14+
)
15+
if not api_key:
16+
raise ValueError("OpenAI API key not set")
17+
return OpenAI(api_key=api_key, organization=organization)
1418

1519

1620
def get_model() -> str:
@@ -35,7 +39,7 @@ def user_message(cls, content: str) -> "OpenAIMessage":
3539
def prompt(messages: List[OpenAIMessage]) -> str:
3640
if not messages:
3741
raise ValueError("messages must not be empty for OpenAI prompt")
38-
response = client.chat.completions.create(
42+
response = get_client().chat.completions.create(
3943
messages=[message.model_dump() for message in messages], # type: ignore
4044
model=get_model(),
4145
)
@@ -45,7 +49,7 @@ def prompt(messages: List[OpenAIMessage]) -> str:
4549
def prompt_streaming(messages: List[OpenAIMessage]) -> Iterable[str]:
4650
if not messages:
4751
raise ValueError("messages must not be empty for OpenAI prompt")
48-
completion_stream = client.chat.completions.create( # type: ignore
52+
completion_stream = get_client().chat.completions.create( # type: ignore
4953
messages=[message.model_dump() for message in messages], # type: ignore
5054
model=get_model(),
5155
stream=True,

chatpdb/chat/prompts/util.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ def format_stack_trace(stack_trace: List[traceback.FrameSummary]) -> str:
2929
else:
3030
content.append(f" {i + 1} | {line}")
3131
file_contents[filename] = "".join(content)
32-
except FileNotFoundError:
33-
console.print(
34-
f"Warning: File found in traceback ('{filename}') does not exist."
35-
)
36-
except IOError:
37-
console.print(
38-
f"Warning: Could not read file found in traceback ('{filename}')."
39-
)
32+
except (FileNotFoundError, IOError):
33+
# Just continue if we can't read the file
34+
# Later we can show a warning in verbose mode or similar
35+
pass
4036

4137
files = []
4238
for frame in stack_trace:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "chatpdb"
3-
version = "0.1.10"
3+
version = "0.1.11"
44
authors = [
55
{ name="Caelean Barnes", email="[email protected]" },
66
{ name="Evan Doyle", email="[email protected]" },

0 commit comments

Comments
 (0)