chatlas 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chatlas might be problematic. Click here for more details.
- chatlas-0.2.0/.github/workflows/check-update-types.yml +42 -0
- chatlas-0.2.0/.github/workflows/docs-publish.yml +65 -0
- chatlas-0.2.0/.github/workflows/release.yml +54 -0
- chatlas-0.2.0/.github/workflows/test.yml +56 -0
- chatlas-0.2.0/.gitignore +14 -0
- chatlas-0.2.0/.vscode/extensions.json +5 -0
- chatlas-0.2.0/.vscode/settings.json +11 -0
- chatlas-0.2.0/CHANGELOG.md +12 -0
- chatlas-0.2.0/Makefile +89 -0
- chatlas-0.2.0/PKG-INFO +319 -0
- chatlas-0.2.0/README.md +271 -0
- chatlas-0.2.0/chatlas/__init__.py +38 -0
- chatlas-0.2.0/chatlas/_anthropic.py +643 -0
- chatlas-0.2.0/chatlas/_chat.py +1279 -0
- chatlas-0.2.0/chatlas/_content.py +242 -0
- chatlas-0.2.0/chatlas/_content_image.py +272 -0
- chatlas-0.2.0/chatlas/_display.py +139 -0
- chatlas-0.2.0/chatlas/_github.py +147 -0
- chatlas-0.2.0/chatlas/_google.py +456 -0
- chatlas-0.2.0/chatlas/_groq.py +143 -0
- chatlas-0.2.0/chatlas/_interpolate.py +133 -0
- chatlas-0.2.0/chatlas/_logging.py +61 -0
- chatlas-0.2.0/chatlas/_merge.py +103 -0
- chatlas-0.2.0/chatlas/_ollama.py +125 -0
- chatlas-0.2.0/chatlas/_openai.py +654 -0
- chatlas-0.2.0/chatlas/_perplexity.py +148 -0
- chatlas-0.2.0/chatlas/_provider.py +143 -0
- chatlas-0.2.0/chatlas/_tokens.py +87 -0
- chatlas-0.2.0/chatlas/_tokens_old.py +148 -0
- chatlas-0.2.0/chatlas/_tools.py +134 -0
- chatlas-0.2.0/chatlas/_turn.py +147 -0
- chatlas-0.2.0/chatlas/_typing_extensions.py +26 -0
- chatlas-0.2.0/chatlas/_utils.py +106 -0
- chatlas-0.2.0/chatlas/types/__init__.py +32 -0
- chatlas-0.2.0/chatlas/types/anthropic/__init__.py +14 -0
- chatlas-0.2.0/chatlas/types/anthropic/_client.py +29 -0
- chatlas-0.2.0/chatlas/types/anthropic/_client_bedrock.py +23 -0
- chatlas-0.2.0/chatlas/types/anthropic/_submit.py +57 -0
- chatlas-0.2.0/chatlas/types/google/__init__.py +12 -0
- chatlas-0.2.0/chatlas/types/google/_client.py +101 -0
- chatlas-0.2.0/chatlas/types/google/_submit.py +113 -0
- chatlas-0.2.0/chatlas/types/openai/__init__.py +14 -0
- chatlas-0.2.0/chatlas/types/openai/_client.py +22 -0
- chatlas-0.2.0/chatlas/types/openai/_client_azure.py +25 -0
- chatlas-0.2.0/chatlas/types/openai/_submit.py +135 -0
- chatlas-0.2.0/docs/.gitignore +5 -0
- chatlas-0.2.0/docs/_extensions/machow/interlinks/.gitignore +3 -0
- chatlas-0.2.0/docs/_extensions/machow/interlinks/_extension.yml +7 -0
- chatlas-0.2.0/docs/_extensions/machow/interlinks/interlinks.lua +254 -0
- chatlas-0.2.0/docs/_quarto.yml +130 -0
- chatlas-0.2.0/docs/_sidebar.yml +54 -0
- chatlas-0.2.0/docs/congressional-assets.png +0 -0
- chatlas-0.2.0/docs/examples/third-party-testing.txt +126 -0
- chatlas-0.2.0/docs/get-started.qmd +108 -0
- chatlas-0.2.0/docs/images/congressional-assets.png +0 -0
- chatlas-0.2.0/docs/images/tool-calling-right.svg +1 -0
- chatlas-0.2.0/docs/images/tool-calling-wrong.svg +1 -0
- chatlas-0.2.0/docs/index.py +20 -0
- chatlas-0.2.0/docs/logos/favicon/android-chrome-192x192.png +0 -0
- chatlas-0.2.0/docs/logos/favicon/android-chrome-512x512.png +0 -0
- chatlas-0.2.0/docs/logos/favicon/apple-touch-icon.png +0 -0
- chatlas-0.2.0/docs/logos/favicon/favicon-16x16.png +0 -0
- chatlas-0.2.0/docs/logos/favicon/favicon-32x32.png +0 -0
- chatlas-0.2.0/docs/logos/favicon/favicon.ico +0 -0
- chatlas-0.2.0/docs/logos/icon/brand-yml-icon-black.png +0 -0
- chatlas-0.2.0/docs/logos/icon/brand-yml-icon-black.svg +12 -0
- chatlas-0.2.0/docs/logos/icon/brand-yml-icon-color.png +0 -0
- chatlas-0.2.0/docs/logos/icon/brand-yml-icon-color.svg +36 -0
- chatlas-0.2.0/docs/logos/icon/brand-yml-icon-white.png +0 -0
- chatlas-0.2.0/docs/logos/icon/brand-yml-icon-white.svg +12 -0
- chatlas-0.2.0/docs/logos/tall/brand-yml-tall-black.png +0 -0
- chatlas-0.2.0/docs/logos/tall/brand-yml-tall-black.svg +35 -0
- chatlas-0.2.0/docs/logos/tall/brand-yml-tall-color.png +0 -0
- chatlas-0.2.0/docs/logos/tall/brand-yml-tall-color.svg +81 -0
- chatlas-0.2.0/docs/logos/tall/brand-yml-tall-white.png +0 -0
- chatlas-0.2.0/docs/logos/tall/brand-yml-tall-white.svg +35 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-black.png +0 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-black.svg +35 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-color.png +0 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-color.svg +81 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-large-black.png +0 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-large-color.png +0 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-large-white.png +0 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-white.png +0 -0
- chatlas-0.2.0/docs/logos/wide/brand-yml-wide-white.svg +35 -0
- chatlas-0.2.0/docs/prompt-design.qmd +344 -0
- chatlas-0.2.0/docs/reference/Chat.qmd +296 -0
- chatlas-0.2.0/docs/reference/ChatAnthropic.qmd +99 -0
- chatlas-0.2.0/docs/reference/ChatAzureOpenAI.qmd +64 -0
- chatlas-0.2.0/docs/reference/ChatBedrockAnthropic.qmd +75 -0
- chatlas-0.2.0/docs/reference/ChatGithub.qmd +103 -0
- chatlas-0.2.0/docs/reference/ChatGoogle.qmd +96 -0
- chatlas-0.2.0/docs/reference/ChatGroq.qmd +101 -0
- chatlas-0.2.0/docs/reference/ChatOllama.qmd +66 -0
- chatlas-0.2.0/docs/reference/ChatOpenAI.qmd +100 -0
- chatlas-0.2.0/docs/reference/ChatPerplexity.qmd +103 -0
- chatlas-0.2.0/docs/reference/Provider.qmd +16 -0
- chatlas-0.2.0/docs/reference/Tool.qmd +17 -0
- chatlas-0.2.0/docs/reference/Turn.qmd +47 -0
- chatlas-0.2.0/docs/reference/content_image_file.qmd +43 -0
- chatlas-0.2.0/docs/reference/content_image_plot.qmd +46 -0
- chatlas-0.2.0/docs/reference/content_image_url.qmd +41 -0
- chatlas-0.2.0/docs/reference/image_file.qmd +43 -0
- chatlas-0.2.0/docs/reference/image_plot.qmd +46 -0
- chatlas-0.2.0/docs/reference/image_url.qmd +41 -0
- chatlas-0.2.0/docs/reference/index.qmd +83 -0
- chatlas-0.2.0/docs/reference/token_usage.qmd +16 -0
- chatlas-0.2.0/docs/reference/types.ChatResponse.qmd +52 -0
- chatlas-0.2.0/docs/reference/types.ChatResponseAsync.qmd +50 -0
- chatlas-0.2.0/docs/reference/types.Content.qmd +7 -0
- chatlas-0.2.0/docs/reference/types.ContentImage.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ContentImageInline.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ContentImageRemote.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ContentJson.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ContentText.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ContentToolRequest.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ContentToolResult.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.ImageContentTypes.qmd +5 -0
- chatlas-0.2.0/docs/reference/types.MISSING.qmd +4 -0
- chatlas-0.2.0/docs/reference/types.MISSING_TYPE.qmd +7 -0
- chatlas-0.2.0/docs/reference/types.SubmitInputArgsT.qmd +6 -0
- chatlas-0.2.0/docs/reference/types.TokenUsage.qmd +7 -0
- chatlas-0.2.0/docs/structured-data.qmd +341 -0
- chatlas-0.2.0/docs/styles.scss +16 -0
- chatlas-0.2.0/docs/tool-calling.qmd +110 -0
- chatlas-0.2.0/docs/web-apps.qmd +77 -0
- chatlas-0.2.0/pyproject.toml +160 -0
- chatlas-0.2.0/pytest.ini +3 -0
- chatlas-0.2.0/scripts/_generate_anthropic_types.py +72 -0
- chatlas-0.2.0/scripts/_generate_google_types.py +57 -0
- chatlas-0.2.0/scripts/_generate_openai_types.py +68 -0
- chatlas-0.2.0/scripts/_utils.py +186 -0
- chatlas-0.2.0/scripts/main.py +13 -0
- chatlas-0.2.0/tests/__init__.py +1 -0
- chatlas-0.2.0/tests/__snapshots__/test_chat.ambr +62 -0
- chatlas-0.2.0/tests/conftest.py +205 -0
- chatlas-0.2.0/tests/test_chat.py +165 -0
- chatlas-0.2.0/tests/test_content.py +12 -0
- chatlas-0.2.0/tests/test_content_image.py +80 -0
- chatlas-0.2.0/tests/test_content_tools.py +152 -0
- chatlas-0.2.0/tests/test_interpolate.py +20 -0
- chatlas-0.2.0/tests/test_provider_anthropic.py +86 -0
- chatlas-0.2.0/tests/test_provider_azure.py +39 -0
- chatlas-0.2.0/tests/test_provider_bedrock.py +72 -0
- chatlas-0.2.0/tests/test_provider_google.py +87 -0
- chatlas-0.2.0/tests/test_provider_openai.py +84 -0
- chatlas-0.2.0/tests/test_tokens.py +34 -0
- chatlas-0.2.0/tests/test_turns.py +30 -0
- chatlas-0.2.0/tests/test_utils_merge.py +50 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Test - Python
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches: ["main", "rc-*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
|
|
12
|
+
env:
|
|
13
|
+
UV_VERSION: "0.4.x"
|
|
14
|
+
PYTHON_VERSION: 3.13
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
check-types-updated:
|
|
18
|
+
name: Check provider types
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: 🚀 Install uv
|
|
25
|
+
uses: astral-sh/setup-uv@v3
|
|
26
|
+
|
|
27
|
+
- name: 🐍 Set up Python ${{ env.PYTHON_VERSION }}
|
|
28
|
+
run: uv python install ${{ env.PYTHON_VERSION }}
|
|
29
|
+
|
|
30
|
+
- name: 📦 Install the project
|
|
31
|
+
run: uv sync --python ${{ env.PYTHON_VERSION }} --all-extras
|
|
32
|
+
|
|
33
|
+
- name: Run type update
|
|
34
|
+
run: make update-types
|
|
35
|
+
|
|
36
|
+
# Fail if there are changes under chatlas/types and throw a useful error message
|
|
37
|
+
- name: Check for changes
|
|
38
|
+
run: |
|
|
39
|
+
if [[ -n $(git diff chatlas/types) ]]; then
|
|
40
|
+
echo "::error::Types are out of date. Please run 'make update-types' and commit the changes."
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
on:
|
|
2
|
+
push:
|
|
3
|
+
branches:
|
|
4
|
+
- main
|
|
5
|
+
paths:
|
|
6
|
+
- "docs/**/*"
|
|
7
|
+
- .github/workflows/docs-publish.yml
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
name: Docs - Publish
|
|
11
|
+
|
|
12
|
+
env:
|
|
13
|
+
UV_VERSION: "0.4.x"
|
|
14
|
+
PYTHON_VERSION: 3.12
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: write
|
|
18
|
+
pages: write
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
docs-publish:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
|
|
24
|
+
env:
|
|
25
|
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
26
|
+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
27
|
+
|
|
28
|
+
steps:
|
|
29
|
+
- name: Check out repository
|
|
30
|
+
uses: actions/checkout@v4
|
|
31
|
+
with:
|
|
32
|
+
fetch-depth: 0 # full history needed for correct versioning of py pkg
|
|
33
|
+
|
|
34
|
+
- name: 🔵 Set up Quarto
|
|
35
|
+
uses: quarto-dev/quarto-actions/setup@v2
|
|
36
|
+
with:
|
|
37
|
+
version: 1.6.26
|
|
38
|
+
|
|
39
|
+
- name: 🚀 Install uv
|
|
40
|
+
uses: astral-sh/setup-uv@v3
|
|
41
|
+
with:
|
|
42
|
+
version: ${{ env.UV_VERSION }}
|
|
43
|
+
|
|
44
|
+
- name: 🐍 Set up Python ${{ env.PYTHON_VERSION }}
|
|
45
|
+
run: uv python install ${{ env.PYTHON_VERSION }}
|
|
46
|
+
|
|
47
|
+
- name: 📦 Install chatlas and dependencies
|
|
48
|
+
run: uv sync --python ${{ env.PYTHON_VERSION }} --all-extras
|
|
49
|
+
|
|
50
|
+
- name: 🔌 Activate venv
|
|
51
|
+
run: |
|
|
52
|
+
source .venv/bin/activate
|
|
53
|
+
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
|
|
54
|
+
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
|
|
55
|
+
|
|
56
|
+
- name: Run quartodoc
|
|
57
|
+
run: make quartodoc
|
|
58
|
+
|
|
59
|
+
- name: 🚢 Publish to GitHub Pages (and render)
|
|
60
|
+
uses: quarto-dev/quarto-actions/publish@v2
|
|
61
|
+
with:
|
|
62
|
+
target: gh-pages
|
|
63
|
+
path: docs
|
|
64
|
+
env:
|
|
65
|
+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Python - Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
env:
|
|
8
|
+
UV_VERSION: "0.4.x"
|
|
9
|
+
PYTHON_VERSION: 3.13
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
pypi-release:
|
|
13
|
+
name: Build and release Python package
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
17
|
+
|
|
18
|
+
environment:
|
|
19
|
+
name: pypi
|
|
20
|
+
url: https://pypi.org/project/chatlas/
|
|
21
|
+
|
|
22
|
+
permissions: # for trusted publishing
|
|
23
|
+
id-token: write
|
|
24
|
+
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
|
|
28
|
+
- name: 🚀 Install uv
|
|
29
|
+
uses: astral-sh/setup-uv@v3
|
|
30
|
+
with:
|
|
31
|
+
version: ${{ env.UV_VERSION }}
|
|
32
|
+
|
|
33
|
+
- name: 🐍 Set up Python ${{ env.PYTHON_VERSION }}
|
|
34
|
+
run: uv python install ${{ env.PYTHON_VERSION }}
|
|
35
|
+
|
|
36
|
+
- name: 📦 Install the project
|
|
37
|
+
run: uv sync --python ${{ env.PYTHON_VERSION }} --all-extras
|
|
38
|
+
|
|
39
|
+
# Tests require API keys, and can be flaky at times due to quota limits,
|
|
40
|
+
# we skip them for release
|
|
41
|
+
#- name: 🧪 Check tests
|
|
42
|
+
# run: make check-tests
|
|
43
|
+
|
|
44
|
+
- name: 📝 Check types
|
|
45
|
+
run: make check-types
|
|
46
|
+
|
|
47
|
+
- name: 📐 Check formatting
|
|
48
|
+
run: make check-format
|
|
49
|
+
|
|
50
|
+
- name: 🧳 Build package
|
|
51
|
+
run: uv build
|
|
52
|
+
|
|
53
|
+
- name: 🚢 Publish release on PyPI
|
|
54
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: Test - Python
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches: ["main", "rc-*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
types: [opened, synchronize, reopened, ready_for_review]
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
test:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
strategy:
|
|
19
|
+
matrix:
|
|
20
|
+
config:
|
|
21
|
+
- { python-version: "3.9", test_google: false, test_azure: false }
|
|
22
|
+
- { python-version: "3.10", test_google: false, test_azure: false }
|
|
23
|
+
- { python-version: "3.11", test_google: false, test_azure: false }
|
|
24
|
+
- { python-version: "3.12", test_google: true, test_azure: true }
|
|
25
|
+
- { python-version: "3.13", test_google: false, test_azure: false }
|
|
26
|
+
|
|
27
|
+
env:
|
|
28
|
+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
29
|
+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
30
|
+
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
|
31
|
+
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
|
|
32
|
+
# Free tier of Google is rate limited, so we only test on 3.12
|
|
33
|
+
TEST_GOOGLE: ${{ matrix.config.test_google }}
|
|
34
|
+
# Free tier of Azure is rate limited, so we only test on 3.12
|
|
35
|
+
TEST_AZURE: ${{ matrix.config.test_azure }}
|
|
36
|
+
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
|
|
40
|
+
- name: 🚀 Install uv
|
|
41
|
+
uses: astral-sh/setup-uv@v3
|
|
42
|
+
|
|
43
|
+
- name: 🐍 Set up Python ${{ matrix.config.python-version }}
|
|
44
|
+
run: uv python install ${{matrix.config.python-version }}
|
|
45
|
+
|
|
46
|
+
- name: 📦 Install the project
|
|
47
|
+
run: uv sync --python ${{ matrix.config.python-version }} --all-extras
|
|
48
|
+
|
|
49
|
+
- name: 🧪 Check tests
|
|
50
|
+
run: make check-tests
|
|
51
|
+
|
|
52
|
+
- name: 📝 Check types
|
|
53
|
+
run: make check-types
|
|
54
|
+
|
|
55
|
+
- name: 📐 Check formatting
|
|
56
|
+
run: make check-format
|
chatlas-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"[python]": {
|
|
3
|
+
"editor.formatOnSave": true,
|
|
4
|
+
"editor.codeActionsOnSave": {
|
|
5
|
+
"source.fixAll": "explicit",
|
|
6
|
+
"source.organizeImports": "explicit"
|
|
7
|
+
},
|
|
8
|
+
"editor.defaultFormatter": "charliermarsh.ruff",
|
|
9
|
+
},
|
|
10
|
+
"flake8.args": ["--max-line-length=120"]
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
<!--
|
|
4
|
+
All notable changes to this project will be documented in this file.
|
|
5
|
+
|
|
6
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
|
+
-->
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2024-12-11
|
|
11
|
+
|
|
12
|
+
First stable release of `chatlas`, see the website to learn more <https://posit-dev.github.io/chatlas/>
|
chatlas-0.2.0/Makefile
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
.PHONY: setup
|
|
2
|
+
setup: ## [py] Setup python environment
|
|
3
|
+
uv sync --all-extras
|
|
4
|
+
|
|
5
|
+
.PHONY: build
|
|
6
|
+
build: ## [py] Build python package
|
|
7
|
+
@echo "🧳 Building python package"
|
|
8
|
+
@[ -d dist ] && rm -r dist || true
|
|
9
|
+
uv build
|
|
10
|
+
|
|
11
|
+
.PHONY: check
|
|
12
|
+
check: check-tests check-format check-types ## [py] Run python checks
|
|
13
|
+
|
|
14
|
+
.PHONY: check-tests
|
|
15
|
+
check-tests: ## [py] Run python tests
|
|
16
|
+
@echo ""
|
|
17
|
+
@echo "🧪 Running tests with pytest"
|
|
18
|
+
uv run pytest
|
|
19
|
+
|
|
20
|
+
.PHONY: check-types
|
|
21
|
+
check-types: ## [py] Run python type checks
|
|
22
|
+
@echo ""
|
|
23
|
+
@echo "📝 Checking types with pyright"
|
|
24
|
+
uv run pyright
|
|
25
|
+
|
|
26
|
+
.PHONY: check-format
|
|
27
|
+
check-format:
|
|
28
|
+
@echo ""
|
|
29
|
+
@echo "📐 Checking format with ruff"
|
|
30
|
+
uv run ruff check chatlas --config pyproject.toml
|
|
31
|
+
|
|
32
|
+
.PHONY: format
|
|
33
|
+
format: ## [py] Format python code
|
|
34
|
+
uv run ruff check --fix chatlas --config pyproject.toml
|
|
35
|
+
uv run ruff format chatlas --config pyproject.toml
|
|
36
|
+
|
|
37
|
+
.PHONY: check-tox
|
|
38
|
+
check-tox: ## [py] Run python 3.9 - 3.12 checks with tox
|
|
39
|
+
@echo ""
|
|
40
|
+
@echo "🔄 Running tests and type checking with tox for Python 3.9--3.12"
|
|
41
|
+
uv run tox run-parallel
|
|
42
|
+
|
|
43
|
+
.PHONY: docs
|
|
44
|
+
docs: quartodoc
|
|
45
|
+
quarto render docs
|
|
46
|
+
|
|
47
|
+
.PHONY: docs-preview
|
|
48
|
+
docs-preview: quartodoc
|
|
49
|
+
quarto preview docs
|
|
50
|
+
|
|
51
|
+
.PHONY: quartodoc
|
|
52
|
+
quartodoc:
|
|
53
|
+
@echo "📖 Generating python docs with quartodoc"
|
|
54
|
+
@$(eval export IN_QUARTODOC=true)
|
|
55
|
+
cd docs && uv run quartodoc build
|
|
56
|
+
cd docs && uv run quartodoc interlinks
|
|
57
|
+
|
|
58
|
+
.PHONY: quartodoc-watch
|
|
59
|
+
quartodoc-watch:
|
|
60
|
+
@echo "📖 Generating python docs with quartodoc"
|
|
61
|
+
@$(eval export IN_QUARTODOC=true)
|
|
62
|
+
uv run quartodoc build --config docs/_quarto.yml --watch
|
|
63
|
+
|
|
64
|
+
.PHONY: update-snaps
|
|
65
|
+
update-snaps:
|
|
66
|
+
@echo "📸 Updating pytest snapshots"
|
|
67
|
+
uv run pytest --snapshot-update
|
|
68
|
+
|
|
69
|
+
.PHONY: update-types
|
|
70
|
+
update-types:
|
|
71
|
+
@echo "📝 Updating chat provider types"
|
|
72
|
+
uv run python scripts/main.py
|
|
73
|
+
|
|
74
|
+
.PHONY: help
|
|
75
|
+
help: ## Show help messages for make targets
|
|
76
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; { \
|
|
77
|
+
printf "\033[32m%-18s\033[0m", $$1; \
|
|
78
|
+
if ($$2 ~ /^\[docs\]/) { \
|
|
79
|
+
printf "\033[34m[docs]\033[0m%s\n", substr($$2, 7); \
|
|
80
|
+
} else if ($$2 ~ /^\[py\]/) { \
|
|
81
|
+
printf " \033[33m[py]\033[0m%s\n", substr($$2, 5); \
|
|
82
|
+
} else if ($$2 ~ /^\[r\]/) { \
|
|
83
|
+
printf " \033[31m[r]\033[0m%s\n", substr($$2, 4); \
|
|
84
|
+
} else { \
|
|
85
|
+
printf " %s\n", $$2; \
|
|
86
|
+
} \
|
|
87
|
+
}'
|
|
88
|
+
|
|
89
|
+
.DEFAULT_GOAL := help
|
chatlas-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: chatlas
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A simple and consistent interface for chatting with LLMs
|
|
5
|
+
Project-URL: Homepage, https://posit-dev.github.io/chatlas
|
|
6
|
+
Project-URL: Documentation, https://posit-dev.github.io/chatlas
|
|
7
|
+
Project-URL: Repository, https://github.com/posit-dev/chatlas
|
|
8
|
+
Project-URL: Issues, https://github.com/posit-dev/chatlas/issues/
|
|
9
|
+
Project-URL: Changelog, https://github.com/posit-dev/chatlas/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Carson Sievert <carson@posit.co>
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Requires-Dist: jinja2
|
|
21
|
+
Requires-Dist: pydantic>=2.0
|
|
22
|
+
Requires-Dist: rich
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: anthropic[bedrock]; extra == 'dev'
|
|
25
|
+
Requires-Dist: google-generativeai>=0.8.3; extra == 'dev'
|
|
26
|
+
Requires-Dist: matplotlib; extra == 'dev'
|
|
27
|
+
Requires-Dist: numpy>1.24.4; extra == 'dev'
|
|
28
|
+
Requires-Dist: openai; extra == 'dev'
|
|
29
|
+
Requires-Dist: pillow; extra == 'dev'
|
|
30
|
+
Requires-Dist: python-dotenv; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.6.5; extra == 'dev'
|
|
32
|
+
Requires-Dist: shiny; extra == 'dev'
|
|
33
|
+
Provides-Extra: docs
|
|
34
|
+
Requires-Dist: griffe>=1; extra == 'docs'
|
|
35
|
+
Requires-Dist: ipykernel; extra == 'docs'
|
|
36
|
+
Requires-Dist: ipywidgets; extra == 'docs'
|
|
37
|
+
Requires-Dist: nbclient; extra == 'docs'
|
|
38
|
+
Requires-Dist: nbformat; extra == 'docs'
|
|
39
|
+
Requires-Dist: pandas; extra == 'docs'
|
|
40
|
+
Requires-Dist: pyyaml; extra == 'docs'
|
|
41
|
+
Requires-Dist: quartodoc>=0.7; extra == 'docs'
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: pyright>=1.1.379; extra == 'test'
|
|
44
|
+
Requires-Dist: pytest-asyncio; extra == 'test'
|
|
45
|
+
Requires-Dist: pytest>=8.3.2; extra == 'test'
|
|
46
|
+
Requires-Dist: syrupy>=4; extra == 'test'
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# chatlas
|
|
50
|
+
|
|
51
|
+
chatlas provides a simple and unified interface across large language model (llm) providers in Python.
|
|
52
|
+
It abstracts away complexity from common tasks like streaming chat interfaces, tool calling, structured output, and much more.
|
|
53
|
+
chatlas helps you prototype faster without painting you into a corner; for example, switching providers is as easy as changing one line of code, but provider specific features are still accessible when needed.
|
|
54
|
+
Developer experience is also a key focus of chatlas: typing support, rich console output, and built-in tooling are all included.
|
|
55
|
+
|
|
56
|
+
(Looking for something similar to chatlas, but in R? Check out [elmer](https://elmer.tidyverse.org/)!)
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
Install the latest stable release from PyPI:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install -U chatlas
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or, install the latest development version from GitHub:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install -U git+https://github.com/posit-dev/chatlas
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Model providers
|
|
73
|
+
|
|
74
|
+
`chatlas` supports a variety of model providers. See the [API reference](https://posit-dev.github.io/chatlas/reference/index.html) for more details (like managing credentials) on each provider.
|
|
75
|
+
|
|
76
|
+
* Anthropic (Claude): [`ChatAnthropic()`](https://posit-dev.github.io/chatlas/reference/ChatAnthropic.html).
|
|
77
|
+
* GitHub model marketplace: [`ChatGithub()`](https://posit-dev.github.io/chatlas/reference/ChatGithub.html).
|
|
78
|
+
* Google (Gemini): [`ChatGoogle()`](https://posit-dev.github.io/chatlas/reference/ChatGoogle.html).
|
|
79
|
+
* Groq: [`ChatGroq()`](https://posit-dev.github.io/chatlas/reference/ChatGroq.html).
|
|
80
|
+
* Ollama local models: [`ChatOllama()`](https://posit-dev.github.io/chatlas/reference/ChatOllama.html).
|
|
81
|
+
* OpenAI: [`ChatOpenAI()`](https://posit-dev.github.io/chatlas/reference/ChatOpenAI.html).
|
|
82
|
+
* perplexity.ai: [`ChatPerplexity()`](https://posit-dev.github.io/chatlas/reference/ChatPerplexity.html).
|
|
83
|
+
|
|
84
|
+
It also supports the following enterprise cloud providers:
|
|
85
|
+
|
|
86
|
+
* AWS Bedrock: [`ChatBedrockAnthropic()`](https://posit-dev.github.io/chatlas/reference/ChatBedrockAnthropic.html).
|
|
87
|
+
* Azure OpenAI: [`ChatAzureOpenAI()`](https://posit-dev.github.io/chatlas/reference/ChatAzureOpenAI.html).
|
|
88
|
+
|
|
89
|
+
To use a model provider that isn't listed here, you have two options:
|
|
90
|
+
|
|
91
|
+
1. If the model is OpenAI compatible, use `ChatOpenAI()` with the appropriate `base_url` and `api_key` (see [`ChatGithub`](https://github.com/posit-dev/chatlas/blob/main/chatlas/_github.py) for a reference).
|
|
92
|
+
2. If you're motivated, implement a new provider by subclassing [`Provider`](https://github.com/posit-dev/chatlas/blob/main/chatlas/_provider.py) and implementing the required methods.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Model choice
|
|
96
|
+
|
|
97
|
+
If you're using chatlas inside your organisation, you'll be limited to what your org allows, which is likely to be one provided by a big cloud provider (e.g. `ChatAzureOpenAI()` and `ChatBedrockAnthropic()`). If you're using chatlas for your own personal exploration, you have a lot more freedom so we have a few recommendations to help you get started:
|
|
98
|
+
|
|
99
|
+
- `ChatOpenAI()` or `ChatAnthropic()` are both good places to start. `ChatOpenAI()` defaults to **GPT-4o**, but you can use `model = "gpt-4o-mini"` for a cheaper lower-quality model, or `model = "o1-mini"` for more complex reasoning. `ChatAnthropic()` is similarly good; it defaults to **Claude 3.5 Sonnet** which we have found to be particularly good at writing code.
|
|
100
|
+
|
|
101
|
+
- `ChatGoogle()` is great for large prompts, because it has a much larger context window than other models. It allows up to 1 million tokens, compared to Claude 3.5 Sonnet's 200k and GPT-4o's 128k.
|
|
102
|
+
|
|
103
|
+
- `ChatOllama()`, which uses [Ollama](https://ollama.com), allows you to run models on your own computer. The biggest models you can run locally aren't as good as the state of the art hosted models, but they also don't share your data and and are effectively free.
|
|
104
|
+
|
|
105
|
+
## Using chatlas
|
|
106
|
+
|
|
107
|
+
You can chat via `chatlas` in several different ways, depending on whether you are working interactively or programmatically. They all start with creating a new chat object:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from chatlas import ChatOpenAI
|
|
111
|
+
|
|
112
|
+
chat = ChatOpenAI(
|
|
113
|
+
model = "gpt-4o",
|
|
114
|
+
system_prompt = "You are a friendly but terse assistant.",
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Interactive console
|
|
119
|
+
|
|
120
|
+
From a `chat` instance, it's simple to start a web-based or terminal-based chat console, which is great for testing the capabilities of the model. In either case, responses stream in real-time, and context is preserved across turns.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
chat.app()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
<div style="display:flex;justify-content:center;">
|
|
127
|
+
<img width="500" alt="A web app for chatting with an LLM via chatlas" src="https://github.com/user-attachments/assets/e43f60cb-3686-435a-bd11-8215cb024d2e" class="border rounded">
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
Or, if you prefer to work from the terminal:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
chat.console()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
Entering chat console. Press Ctrl+C to quit.
|
|
139
|
+
|
|
140
|
+
?> Who created Python?
|
|
141
|
+
|
|
142
|
+
Python was created by Guido van Rossum. He began development in the late 1980s and released the first version in 1991.
|
|
143
|
+
|
|
144
|
+
?> Where did he develop it?
|
|
145
|
+
|
|
146
|
+
Guido van Rossum developed Python while working at Centrum Wiskunde & Informatica (CWI) in the Netherlands.
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
### The `.chat()` method
|
|
151
|
+
|
|
152
|
+
For a more programmatic approach, you can use the `.chat()` method to ask a question and get a response. By default, the response prints to a [rich](https://github.com/Textualize/rich) console as it streams in:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
chat.chat("What preceding languages most influenced Python?")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
Python was primarily influenced by ABC, with additional inspiration from C,
|
|
160
|
+
Modula-3, and various other languages.
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
To ask a question about an image, pass one or more additional input arguments using `content_image_file()` and/or `content_image_url()`:
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from chatlas import content_image_url
|
|
167
|
+
|
|
168
|
+
chat.chat(
|
|
169
|
+
content_image_url("https://www.python.org/static/img/python-logo.png"),
|
|
170
|
+
"Can you explain this logo?"
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
The Python logo features two intertwined snakes in yellow and blue,
|
|
176
|
+
representing the Python programming language. The design symbolizes...
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
To get the full response as a string, use the built-in `str()` function. Optionally, you can also suppress the rich console output by setting `echo="none"`:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
response = chat.chat("Who is Posit?", echo="none")
|
|
183
|
+
print(str(response))
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
As we'll see in later articles, `echo="all"` can also be useful for debugging, as it shows additional information, such as tool calls.
|
|
187
|
+
|
|
188
|
+
### The `.stream()` method
|
|
189
|
+
|
|
190
|
+
If you want to do something with the response in real-time (i.e., as it arrives in chunks), use the `.stream()` method. This method returns an iterator that yields each chunk of the response as it arrives:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
response = chat.stream("Who is Posit?")
|
|
194
|
+
for chunk in response:
|
|
195
|
+
print(chunk, end="")
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The `.stream()` method can also be useful if you're [building a chatbot](https://posit-dev.github.io/chatlas/web-apps.html) or other programs that needs to display responses as they arrive.
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### Tool calling
|
|
202
|
+
|
|
203
|
+
Tool calling is as simple as passing a function with type hints and docstring to `.register_tool()`.
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
import sys
|
|
207
|
+
|
|
208
|
+
def get_current_python_version() -> str:
|
|
209
|
+
"""Get the current version of Python."""
|
|
210
|
+
return sys.version
|
|
211
|
+
|
|
212
|
+
chat.register_tool(get_current_python_version)
|
|
213
|
+
chat.chat("What's the current version of Python?")
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
The current version of Python is 3.13.
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Learn more in the [tool calling article](https://posit-dev.github.io/chatlas/tool-calling.html)
|
|
221
|
+
|
|
222
|
+
### Structured data
|
|
223
|
+
|
|
224
|
+
Structured data (i.e., structured output) is as simple as passing a [pydantic](https://docs.pydantic.dev/latest/) model to `.extract_data()`.
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from pydantic import BaseModel
|
|
228
|
+
|
|
229
|
+
class Person(BaseModel):
|
|
230
|
+
name: str
|
|
231
|
+
age: int
|
|
232
|
+
|
|
233
|
+
chat.extract_data(
|
|
234
|
+
"My name is Susan and I'm 13 years old",
|
|
235
|
+
data_model=Person,
|
|
236
|
+
)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
{'name': 'Susan', 'age': 13}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Learn more in the [structured data article](https://posit-dev.github.io/chatlas/structured-data.html)
|
|
244
|
+
|
|
245
|
+
### Export chat
|
|
246
|
+
|
|
247
|
+
Easily get a full markdown or HTML export of a conversation:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
chat.export("index.html", title="Python Q&A")
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
If the export doesn't have all the information you need, you can also access the full conversation history via the `.get_turns()` method:
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
chat.get_turns()
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
And, if the conversation is too long, you can specify which turns to include:
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
chat.export("index.html", turns=chat.get_turns()[-5:])
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Async
|
|
266
|
+
|
|
267
|
+
`chat` methods tend to be synchronous by default, but you can use the async flavor by appending `_async` to the method name:
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
import asyncio
|
|
271
|
+
|
|
272
|
+
async def main():
|
|
273
|
+
await chat.chat_async("What is the capital of France?")
|
|
274
|
+
|
|
275
|
+
asyncio.run(main())
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Typing support
|
|
279
|
+
|
|
280
|
+
`chatlas` has full typing support, meaning that, among other things, autocompletion just works in your favorite editor:
|
|
281
|
+
|
|
282
|
+
<div style="display:flex;justify-content:center;">
|
|
283
|
+
<img width="500" alt="Autocompleting model options in ChatOpenAI" src="https://github.com/user-attachments/assets/163d6d8a-7d58-422d-b3af-cc9f2adee759" class="rounded">
|
|
284
|
+
</div>
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
### Troubleshooting
|
|
289
|
+
|
|
290
|
+
Sometimes things like token limits, tool errors, or other issues can cause problems that are hard to diagnose.
|
|
291
|
+
In these cases, the `echo="all"` option is helpful for getting more information about what's going on under the hood.
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
chat.chat("What is the capital of France?", echo="all")
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
This shows important information like tool call results, finish reasons, and more.
|
|
298
|
+
|
|
299
|
+
If the problem isn't self-evident, you can also reach into the `.get_last_turn()`, which contains the full response object, with full details about the completion.
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
<div style="display:flex;justify-content:center;">
|
|
303
|
+
<img width="500" alt="Turn completion details with typing support" src="https://github.com/user-attachments/assets/eaea338d-e44a-4e23-84a7-2e998d8af3ba" class="rounded">
|
|
304
|
+
</div>
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
For monitoring issues in a production (or otherwise non-interactive) environment, you may want to enabling logging. Also, since `chatlas` builds on top of packages like `anthropic` and `openai`, you can also enable their debug logging to get lower-level information, like HTTP requests and response codes.
|
|
308
|
+
|
|
309
|
+
```shell
|
|
310
|
+
$ export CHATLAS_LOG=info
|
|
311
|
+
$ export OPENAI_LOG=info
|
|
312
|
+
$ export ANTHROPIC_LOG=info
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Next steps
|
|
316
|
+
|
|
317
|
+
If you're new to world LLMs, you might want to read the [Get Started](https://posit-dev.github.io/chatlas/get-started.html) guide, which covers some basic concepts and terminology.
|
|
318
|
+
|
|
319
|
+
Once you're comfortable with the basics, you can explore more in-depth topics like [prompt design](https://posit-dev.github.io/chatlas/prompt-design.html) or the [API reference](https://posit-dev.github.io/chatlas/reference/index.html).
|