diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..30c9120 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 }} diff --git a/chatpdb/__main__.py b/chatpdb/__main__.py index c84d9c3..bcef64a 100644 --- a/chatpdb/__main__.py +++ b/chatpdb/__main__.py @@ -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 diff --git a/chatpdb/chat/llm/openai.py b/chatpdb/chat/llm/openai.py index 6f3f482..1f4979a 100644 --- a/chatpdb/chat/llm/openai.py +++ b/chatpdb/chat/llm/openai.py @@ -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: @@ -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(), ) @@ -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, diff --git a/chatpdb/chat/prompts/util.py b/chatpdb/chat/prompts/util.py index abcec75..bcba351 100644 --- a/chatpdb/chat/prompts/util.py +++ b/chatpdb/chat/prompts/util.py @@ -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 = [] diff --git a/pyproject.toml b/pyproject.toml index 4f0d5bc..71cd2a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, @@ -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