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.

Files changed (149) hide show
  1. chatlas-0.2.0/.github/workflows/check-update-types.yml +42 -0
  2. chatlas-0.2.0/.github/workflows/docs-publish.yml +65 -0
  3. chatlas-0.2.0/.github/workflows/release.yml +54 -0
  4. chatlas-0.2.0/.github/workflows/test.yml +56 -0
  5. chatlas-0.2.0/.gitignore +14 -0
  6. chatlas-0.2.0/.vscode/extensions.json +5 -0
  7. chatlas-0.2.0/.vscode/settings.json +11 -0
  8. chatlas-0.2.0/CHANGELOG.md +12 -0
  9. chatlas-0.2.0/Makefile +89 -0
  10. chatlas-0.2.0/PKG-INFO +319 -0
  11. chatlas-0.2.0/README.md +271 -0
  12. chatlas-0.2.0/chatlas/__init__.py +38 -0
  13. chatlas-0.2.0/chatlas/_anthropic.py +643 -0
  14. chatlas-0.2.0/chatlas/_chat.py +1279 -0
  15. chatlas-0.2.0/chatlas/_content.py +242 -0
  16. chatlas-0.2.0/chatlas/_content_image.py +272 -0
  17. chatlas-0.2.0/chatlas/_display.py +139 -0
  18. chatlas-0.2.0/chatlas/_github.py +147 -0
  19. chatlas-0.2.0/chatlas/_google.py +456 -0
  20. chatlas-0.2.0/chatlas/_groq.py +143 -0
  21. chatlas-0.2.0/chatlas/_interpolate.py +133 -0
  22. chatlas-0.2.0/chatlas/_logging.py +61 -0
  23. chatlas-0.2.0/chatlas/_merge.py +103 -0
  24. chatlas-0.2.0/chatlas/_ollama.py +125 -0
  25. chatlas-0.2.0/chatlas/_openai.py +654 -0
  26. chatlas-0.2.0/chatlas/_perplexity.py +148 -0
  27. chatlas-0.2.0/chatlas/_provider.py +143 -0
  28. chatlas-0.2.0/chatlas/_tokens.py +87 -0
  29. chatlas-0.2.0/chatlas/_tokens_old.py +148 -0
  30. chatlas-0.2.0/chatlas/_tools.py +134 -0
  31. chatlas-0.2.0/chatlas/_turn.py +147 -0
  32. chatlas-0.2.0/chatlas/_typing_extensions.py +26 -0
  33. chatlas-0.2.0/chatlas/_utils.py +106 -0
  34. chatlas-0.2.0/chatlas/types/__init__.py +32 -0
  35. chatlas-0.2.0/chatlas/types/anthropic/__init__.py +14 -0
  36. chatlas-0.2.0/chatlas/types/anthropic/_client.py +29 -0
  37. chatlas-0.2.0/chatlas/types/anthropic/_client_bedrock.py +23 -0
  38. chatlas-0.2.0/chatlas/types/anthropic/_submit.py +57 -0
  39. chatlas-0.2.0/chatlas/types/google/__init__.py +12 -0
  40. chatlas-0.2.0/chatlas/types/google/_client.py +101 -0
  41. chatlas-0.2.0/chatlas/types/google/_submit.py +113 -0
  42. chatlas-0.2.0/chatlas/types/openai/__init__.py +14 -0
  43. chatlas-0.2.0/chatlas/types/openai/_client.py +22 -0
  44. chatlas-0.2.0/chatlas/types/openai/_client_azure.py +25 -0
  45. chatlas-0.2.0/chatlas/types/openai/_submit.py +135 -0
  46. chatlas-0.2.0/docs/.gitignore +5 -0
  47. chatlas-0.2.0/docs/_extensions/machow/interlinks/.gitignore +3 -0
  48. chatlas-0.2.0/docs/_extensions/machow/interlinks/_extension.yml +7 -0
  49. chatlas-0.2.0/docs/_extensions/machow/interlinks/interlinks.lua +254 -0
  50. chatlas-0.2.0/docs/_quarto.yml +130 -0
  51. chatlas-0.2.0/docs/_sidebar.yml +54 -0
  52. chatlas-0.2.0/docs/congressional-assets.png +0 -0
  53. chatlas-0.2.0/docs/examples/third-party-testing.txt +126 -0
  54. chatlas-0.2.0/docs/get-started.qmd +108 -0
  55. chatlas-0.2.0/docs/images/congressional-assets.png +0 -0
  56. chatlas-0.2.0/docs/images/tool-calling-right.svg +1 -0
  57. chatlas-0.2.0/docs/images/tool-calling-wrong.svg +1 -0
  58. chatlas-0.2.0/docs/index.py +20 -0
  59. chatlas-0.2.0/docs/logos/favicon/android-chrome-192x192.png +0 -0
  60. chatlas-0.2.0/docs/logos/favicon/android-chrome-512x512.png +0 -0
  61. chatlas-0.2.0/docs/logos/favicon/apple-touch-icon.png +0 -0
  62. chatlas-0.2.0/docs/logos/favicon/favicon-16x16.png +0 -0
  63. chatlas-0.2.0/docs/logos/favicon/favicon-32x32.png +0 -0
  64. chatlas-0.2.0/docs/logos/favicon/favicon.ico +0 -0
  65. chatlas-0.2.0/docs/logos/icon/brand-yml-icon-black.png +0 -0
  66. chatlas-0.2.0/docs/logos/icon/brand-yml-icon-black.svg +12 -0
  67. chatlas-0.2.0/docs/logos/icon/brand-yml-icon-color.png +0 -0
  68. chatlas-0.2.0/docs/logos/icon/brand-yml-icon-color.svg +36 -0
  69. chatlas-0.2.0/docs/logos/icon/brand-yml-icon-white.png +0 -0
  70. chatlas-0.2.0/docs/logos/icon/brand-yml-icon-white.svg +12 -0
  71. chatlas-0.2.0/docs/logos/tall/brand-yml-tall-black.png +0 -0
  72. chatlas-0.2.0/docs/logos/tall/brand-yml-tall-black.svg +35 -0
  73. chatlas-0.2.0/docs/logos/tall/brand-yml-tall-color.png +0 -0
  74. chatlas-0.2.0/docs/logos/tall/brand-yml-tall-color.svg +81 -0
  75. chatlas-0.2.0/docs/logos/tall/brand-yml-tall-white.png +0 -0
  76. chatlas-0.2.0/docs/logos/tall/brand-yml-tall-white.svg +35 -0
  77. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-black.png +0 -0
  78. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-black.svg +35 -0
  79. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-color.png +0 -0
  80. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-color.svg +81 -0
  81. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-large-black.png +0 -0
  82. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-large-color.png +0 -0
  83. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-large-white.png +0 -0
  84. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-white.png +0 -0
  85. chatlas-0.2.0/docs/logos/wide/brand-yml-wide-white.svg +35 -0
  86. chatlas-0.2.0/docs/prompt-design.qmd +344 -0
  87. chatlas-0.2.0/docs/reference/Chat.qmd +296 -0
  88. chatlas-0.2.0/docs/reference/ChatAnthropic.qmd +99 -0
  89. chatlas-0.2.0/docs/reference/ChatAzureOpenAI.qmd +64 -0
  90. chatlas-0.2.0/docs/reference/ChatBedrockAnthropic.qmd +75 -0
  91. chatlas-0.2.0/docs/reference/ChatGithub.qmd +103 -0
  92. chatlas-0.2.0/docs/reference/ChatGoogle.qmd +96 -0
  93. chatlas-0.2.0/docs/reference/ChatGroq.qmd +101 -0
  94. chatlas-0.2.0/docs/reference/ChatOllama.qmd +66 -0
  95. chatlas-0.2.0/docs/reference/ChatOpenAI.qmd +100 -0
  96. chatlas-0.2.0/docs/reference/ChatPerplexity.qmd +103 -0
  97. chatlas-0.2.0/docs/reference/Provider.qmd +16 -0
  98. chatlas-0.2.0/docs/reference/Tool.qmd +17 -0
  99. chatlas-0.2.0/docs/reference/Turn.qmd +47 -0
  100. chatlas-0.2.0/docs/reference/content_image_file.qmd +43 -0
  101. chatlas-0.2.0/docs/reference/content_image_plot.qmd +46 -0
  102. chatlas-0.2.0/docs/reference/content_image_url.qmd +41 -0
  103. chatlas-0.2.0/docs/reference/image_file.qmd +43 -0
  104. chatlas-0.2.0/docs/reference/image_plot.qmd +46 -0
  105. chatlas-0.2.0/docs/reference/image_url.qmd +41 -0
  106. chatlas-0.2.0/docs/reference/index.qmd +83 -0
  107. chatlas-0.2.0/docs/reference/token_usage.qmd +16 -0
  108. chatlas-0.2.0/docs/reference/types.ChatResponse.qmd +52 -0
  109. chatlas-0.2.0/docs/reference/types.ChatResponseAsync.qmd +50 -0
  110. chatlas-0.2.0/docs/reference/types.Content.qmd +7 -0
  111. chatlas-0.2.0/docs/reference/types.ContentImage.qmd +6 -0
  112. chatlas-0.2.0/docs/reference/types.ContentImageInline.qmd +6 -0
  113. chatlas-0.2.0/docs/reference/types.ContentImageRemote.qmd +6 -0
  114. chatlas-0.2.0/docs/reference/types.ContentJson.qmd +6 -0
  115. chatlas-0.2.0/docs/reference/types.ContentText.qmd +6 -0
  116. chatlas-0.2.0/docs/reference/types.ContentToolRequest.qmd +6 -0
  117. chatlas-0.2.0/docs/reference/types.ContentToolResult.qmd +6 -0
  118. chatlas-0.2.0/docs/reference/types.ImageContentTypes.qmd +5 -0
  119. chatlas-0.2.0/docs/reference/types.MISSING.qmd +4 -0
  120. chatlas-0.2.0/docs/reference/types.MISSING_TYPE.qmd +7 -0
  121. chatlas-0.2.0/docs/reference/types.SubmitInputArgsT.qmd +6 -0
  122. chatlas-0.2.0/docs/reference/types.TokenUsage.qmd +7 -0
  123. chatlas-0.2.0/docs/structured-data.qmd +341 -0
  124. chatlas-0.2.0/docs/styles.scss +16 -0
  125. chatlas-0.2.0/docs/tool-calling.qmd +110 -0
  126. chatlas-0.2.0/docs/web-apps.qmd +77 -0
  127. chatlas-0.2.0/pyproject.toml +160 -0
  128. chatlas-0.2.0/pytest.ini +3 -0
  129. chatlas-0.2.0/scripts/_generate_anthropic_types.py +72 -0
  130. chatlas-0.2.0/scripts/_generate_google_types.py +57 -0
  131. chatlas-0.2.0/scripts/_generate_openai_types.py +68 -0
  132. chatlas-0.2.0/scripts/_utils.py +186 -0
  133. chatlas-0.2.0/scripts/main.py +13 -0
  134. chatlas-0.2.0/tests/__init__.py +1 -0
  135. chatlas-0.2.0/tests/__snapshots__/test_chat.ambr +62 -0
  136. chatlas-0.2.0/tests/conftest.py +205 -0
  137. chatlas-0.2.0/tests/test_chat.py +165 -0
  138. chatlas-0.2.0/tests/test_content.py +12 -0
  139. chatlas-0.2.0/tests/test_content_image.py +80 -0
  140. chatlas-0.2.0/tests/test_content_tools.py +152 -0
  141. chatlas-0.2.0/tests/test_interpolate.py +20 -0
  142. chatlas-0.2.0/tests/test_provider_anthropic.py +86 -0
  143. chatlas-0.2.0/tests/test_provider_azure.py +39 -0
  144. chatlas-0.2.0/tests/test_provider_bedrock.py +72 -0
  145. chatlas-0.2.0/tests/test_provider_google.py +87 -0
  146. chatlas-0.2.0/tests/test_provider_openai.py +84 -0
  147. chatlas-0.2.0/tests/test_tokens.py +34 -0
  148. chatlas-0.2.0/tests/test_turns.py +30 -0
  149. 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
@@ -0,0 +1,14 @@
1
+ __pycache__
2
+
3
+ .ipynb_checkpoints/
4
+ Untitled*.ipynb
5
+
6
+ .venv
7
+ uv.lock
8
+
9
+ sandbox/
10
+
11
+ /.luarc.json
12
+
13
+ # Automatically generated by docs/index.py
14
+ docs/index.qmd
@@ -0,0 +1,5 @@
1
+ {
2
+ "recommendations": [
3
+ "charliermarsh.ruff"
4
+ ]
5
+ }
@@ -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).