Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Never-Over/chatpdb
Browse files Browse the repository at this point in the history
  • Loading branch information
caelean committed Apr 18, 2024
2 parents 8246f26 + 772f531 commit bf0d2b8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

name: Publish chatpdb

on:
release:
types: [published]

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 3 additions & 0 deletions chatpdb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def _get_debugger_cls():

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


Expand Down
20 changes: 12 additions & 8 deletions chatpdb/chat/llm/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
from pydantic import BaseModel


client = OpenAI(
api_key=os.environ.get("CHAT_PDB_OPENAI_API_KEY")
or os.environ.get("OPENAI_API_KEY"),
organization=os.environ.get("CHAT_PDB_OPENAI_ORG_ID")
or os.environ.get("OPENAI_ORG_ID"),
)
def get_client() -> OpenAI:
api_key = os.environ.get("CHAT_PDB_OPENAI_API_KEY") or os.environ.get(
"OPENAI_API_KEY"
)
organization = os.environ.get("CHAT_PDB_OPENAI_ORG_ID") or os.environ.get(
"OPENAI_ORG_ID"
)
if not api_key:
raise ValueError("OpenAI API key not set")
return OpenAI(api_key=api_key, organization=organization)


def get_model() -> str:
Expand All @@ -35,7 +39,7 @@ def user_message(cls, content: str) -> "OpenAIMessage":
def prompt(messages: List[OpenAIMessage]) -> str:
if not messages:
raise ValueError("messages must not be empty for OpenAI prompt")
response = client.chat.completions.create(
response = get_client().chat.completions.create(
messages=[message.model_dump() for message in messages], # type: ignore
model=get_model(),
)
Expand All @@ -45,7 +49,7 @@ def prompt(messages: List[OpenAIMessage]) -> str:
def prompt_streaming(messages: List[OpenAIMessage]) -> Iterable[str]:
if not messages:
raise ValueError("messages must not be empty for OpenAI prompt")
completion_stream = client.chat.completions.create( # type: ignore
completion_stream = get_client().chat.completions.create( # type: ignore
messages=[message.model_dump() for message in messages], # type: ignore
model=get_model(),
stream=True,
Expand Down
2 changes: 2 additions & 0 deletions chatpdb/chat/prompts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def format_stack_trace(stack_trace: List[traceback.FrameSummary]) -> str:
content.append(f" {i + 1} | {line}")
file_contents[filename] = "".join(content)
except (FileNotFoundError, IOError):
# Just continue if we can't read the file
# Later we can show a warning in verbose mode or similar
pass

files = []
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "chatpdb"
version = "0.1.10"
version = "0.1.13"
authors = [
{ name="Caelean Barnes", email="caeleanb@gmail.com" },
{ name="Evan Doyle", email="evanmdoyle@gmail.com" },
Expand Down Expand Up @@ -52,5 +52,7 @@ reportMissingTypeStubs = false
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["chatpdb", "chatpdb.chat", "chatpdb.parsing"]
[tool.setuptools.packages.find]
where = ["."]
include = ["chatpdb*"]
namespaces = false

0 comments on commit bf0d2b8

Please sign in to comment.