chainlit 1.3.1__tar.gz → 2.0.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 chainlit might be problematic. Click here for more details.
- {chainlit-1.3.1 → chainlit-2.0.0}/PKG-INFO +17 -37
- {chainlit-1.3.1 → chainlit-2.0.0}/README.md +11 -31
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/__init__.py +58 -56
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/action.py +12 -10
- chainlit-1.3.1/chainlit/auth.py → chainlit-2.0.0/chainlit/auth/__init__.py +24 -34
- chainlit-2.0.0/chainlit/auth/cookie.py +123 -0
- chainlit-2.0.0/chainlit/auth/jwt.py +37 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/cache.py +4 -6
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/callbacks.py +65 -11
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/chat_context.py +2 -2
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/chat_settings.py +3 -1
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/cli/__init__.py +15 -2
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/config.py +46 -90
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/context.py +4 -3
- chainlit-2.0.0/chainlit/copilot/dist/index.js +12200 -0
- chainlit-2.0.0/chainlit/data/__init__.py +113 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/data/acl.py +3 -2
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/data/base.py +1 -15
- chainlit-2.0.0/chainlit/data/chainlit_data_layer.py +584 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/data/dynamodb.py +7 -4
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/data/literalai.py +4 -6
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/data/sql_alchemy.py +9 -8
- chainlit-1.3.1/chainlit/data/storage_clients.py → chainlit-2.0.0/chainlit/data/storage_clients/azure.py +2 -33
- chainlit-2.0.0/chainlit/data/storage_clients/azure_blob.py +80 -0
- chainlit-2.0.0/chainlit/data/storage_clients/base.py +22 -0
- chainlit-2.0.0/chainlit/data/storage_clients/gcs.py +78 -0
- chainlit-2.0.0/chainlit/data/storage_clients/s3.py +49 -0
- chainlit-2.0.0/chainlit/discord/__init__.py +6 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/discord/app.py +2 -1
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/element.py +41 -9
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/emitter.py +37 -16
- chainlit-1.3.1/chainlit/frontend/dist/assets/DailyMotion-CwoOhIL8.js → chainlit-2.0.0/chainlit/frontend/dist/assets/DailyMotion-DgRzV5GZ.js +1 -1
- chainlit-2.0.0/chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +22 -0
- chainlit-1.3.1/chainlit/frontend/dist/assets/Facebook-BhnGXlzq.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Facebook-C0vx6HWv.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/FilePlayer-CPSVT6fz.js → chainlit-2.0.0/chainlit/frontend/dist/assets/FilePlayer-CdhzeHPP.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Kaltura-COYaLzsL.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Kaltura-5iVmeUct.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Mixcloud-JdadNiQ5.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Mixcloud-C2zi77Ex.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Mux-CBN7RO2u.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Mux-Vkebogdf.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Preview-CxAFvvjV.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Preview-DwY_sEIl.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/SoundCloud-JlgmASWm.js → chainlit-2.0.0/chainlit/frontend/dist/assets/SoundCloud-CREBXAWo.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Streamable-CUWgr6Zw.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Streamable-B5Lu25uy.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Twitch-BiN1HEDM.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Twitch-y9iKCcM1.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Vidyard-qhPmrhDm.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Vidyard-ClYvcuEu.js +1 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/Vimeo-CrZVSCaT.js → chainlit-2.0.0/chainlit/frontend/dist/assets/Vimeo-D6HvM2jt.js +1 -1
- chainlit-2.0.0/chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +1 -0
- chainlit-1.3.1/chainlit/frontend/dist/assets/YouTube-DKjw5Hbn.js → chainlit-2.0.0/chainlit/frontend/dist/assets/YouTube-D10tR6CJ.js +1 -1
- chainlit-2.0.0/chainlit/frontend/dist/assets/index-CI4qFOt5.js +8665 -0
- chainlit-2.0.0/chainlit/frontend/dist/assets/index-CrrqM0nZ.css +1 -0
- chainlit-1.3.1/chainlit/frontend/dist/assets/react-plotly-Dpmqg5Sy.js → chainlit-2.0.0/chainlit/frontend/dist/assets/react-plotly-BpxUS-ab.js +1 -1
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/frontend/dist/index.html +2 -2
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/haystack/callbacks.py +5 -4
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/input_widget.py +6 -4
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/langchain/callbacks.py +56 -47
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/langflow/__init__.py +1 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/llama_index/callbacks.py +7 -7
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/message.py +8 -10
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/mistralai/__init__.py +3 -2
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/oauth_providers.py +70 -3
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/openai/__init__.py +3 -2
- chainlit-2.0.0/chainlit/py.typed +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/secret.py +1 -1
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/server.py +481 -182
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/session.py +7 -5
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/slack/__init__.py +3 -3
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/slack/app.py +3 -2
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/socket.py +89 -112
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/step.py +12 -12
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/sync.py +2 -1
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/teams/__init__.py +3 -3
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/teams/app.py +1 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/en-US.json +2 -1
- chainlit-2.0.0/chainlit/translations/nl-NL.json +229 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/types.py +24 -8
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/user.py +2 -1
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/utils.py +3 -2
- chainlit-2.0.0/chainlit/version.py +8 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/pyproject.toml +22 -13
- chainlit-1.3.1/chainlit/copilot/dist/index.js +0 -4234
- chainlit-1.3.1/chainlit/data/__init__.py +0 -25
- chainlit-1.3.1/chainlit/discord/__init__.py +0 -6
- chainlit-1.3.1/chainlit/frontend/dist/assets/Wistia-C891KrBP.js +0 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/index-CwmincdQ.css +0 -1
- chainlit-1.3.1/chainlit/frontend/dist/assets/index-DLRdQOIx.js +0 -723
- chainlit-1.3.1/chainlit/version.py +0 -7
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/__main__.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/_utils.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/copilot/dist/assets/logo_dark-IkGJ_IwC.svg +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/copilot/dist/assets/logo_light-Bb_IPh6r.svg +0 -0
- /chainlit-1.3.1/chainlit/py.typed → /chainlit-2.0.0/chainlit/data/storage_clients/__init__.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/data/utils.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/frontend/dist/assets/logo_dark-IkGJ_IwC.svg +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/frontend/dist/assets/logo_light-Bb_IPh6r.svg +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/frontend/dist/favicon.svg +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/haystack/__init__.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/hello.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/langchain/__init__.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/llama_index/__init__.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/logger.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/markdown.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/telemetry.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/bn.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/gu.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/he-IL.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/hi.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/kn.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/ml.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/mr.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/ta.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/te.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations/zh-CN.json +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/translations.py +0 -0
- {chainlit-1.3.1 → chainlit-2.0.0}/chainlit/user_session.py +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: chainlit
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: Build Conversational AI.
|
|
5
5
|
Home-page: https://chainlit.io/
|
|
6
|
-
License:
|
|
6
|
+
License: Apache-2.0
|
|
7
7
|
Keywords: LLM,Agents,gen ai,chat ui,chatbot ui,openai,copilot,langchain,conversational ai
|
|
8
8
|
Author: Willy Douhard
|
|
9
9
|
Requires-Python: >=3.9,<4.0.0
|
|
10
10
|
Classifier: Environment :: Web Environment
|
|
11
11
|
Classifier: Framework :: FastAPI
|
|
12
|
-
Classifier: License ::
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
13
|
Classifier: Programming Language :: JavaScript
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -24,7 +24,7 @@ Requires-Dist: aiofiles (>=23.1.0,<24.0.0)
|
|
|
24
24
|
Requires-Dist: asyncer (>=0.0.7,<0.0.8)
|
|
25
25
|
Requires-Dist: click (>=8.1.3,<9.0.0)
|
|
26
26
|
Requires-Dist: dataclasses_json (>=0.6.7,<0.7.0)
|
|
27
|
-
Requires-Dist: fastapi (>=0.
|
|
27
|
+
Requires-Dist: fastapi (>=0.115.3,<0.116)
|
|
28
28
|
Requires-Dist: filetype (>=1.2.0,<2.0.0)
|
|
29
29
|
Requires-Dist: httpx (>=0.23.0)
|
|
30
30
|
Requires-Dist: lazify (>=0.4.0,<0.5.0)
|
|
@@ -35,9 +35,9 @@ Requires-Dist: packaging (>=23.1,<24.0)
|
|
|
35
35
|
Requires-Dist: pydantic (>=1,<3)
|
|
36
36
|
Requires-Dist: pyjwt (>=2.8.0,<3.0.0)
|
|
37
37
|
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
|
38
|
-
Requires-Dist: python-multipart (>=0.0.
|
|
38
|
+
Requires-Dist: python-multipart (>=0.0.18,<0.0.19)
|
|
39
39
|
Requires-Dist: python-socketio (>=5.11.0,<6.0.0)
|
|
40
|
-
Requires-Dist: starlette (>=0.
|
|
40
|
+
Requires-Dist: starlette (>=0.41.2,<0.42.0)
|
|
41
41
|
Requires-Dist: syncer (>=2.0.3,<3.0.0)
|
|
42
42
|
Requires-Dist: tomli (>=2.0.1,<3.0.0)
|
|
43
43
|
Requires-Dist: uptrace (>=1.22.0,<2.0.0)
|
|
@@ -59,22 +59,10 @@ Description-Content-Type: text/markdown
|
|
|
59
59
|
|
|
60
60
|
Chainlit is an open-source async Python framework which allows developers to build scalable Conversational AI or agentic applications.
|
|
61
61
|
|
|
62
|
-
- ✅ ChatGPT-like application
|
|
63
|
-
- ✅ Embedded Chatbot & Software Copilot
|
|
64
|
-
- ✅ Slack & Discord
|
|
65
|
-
- ✅ Custom frontend (build your own agentic experience)
|
|
66
|
-
- ✅ API Endpoint
|
|
67
|
-
|
|
68
62
|
Full documentation is available [here](https://docs.chainlit.io). You can ask Chainlit related questions to [Chainlit Help](https://help.chainlit.io/), an app built using Chainlit!
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
> Check out [Literal AI](https://literalai.com), our product to monitor and evaluate LLM applications! It works with any Python or TypeScript applications and [seamlessly](https://docs.chainlit.io/data-persistence/overview) with Chainlit by adding a `LITERAL_API_KEY` in your project.
|
|
72
|
-
>
|
|
73
|
-
> Chainlit is developed and maintained by the Literal AI team, which is currently focused on expanding the capabilities of Literal AI. While we continue to support and maintain Chainlit, we are also committed to enabling the community to contribute, particularly in areas like integrations and data layers.
|
|
64
|
+
https://github.com/user-attachments/assets/b3738aba-55c0-42fa-ac00-6efd1ee0d148
|
|
74
65
|
|
|
75
|
-
<p align="center">
|
|
76
|
-
<img src="https://github.com/Chainlit/chainlit/assets/13104895/0c2cc7a9-766c-41d3-aae2-117a2d0eb8ed" alt="Chainlit user interface" width="80%"></img>
|
|
77
|
-
</p>
|
|
78
66
|
|
|
79
67
|
## Installation
|
|
80
68
|
|
|
@@ -87,6 +75,16 @@ chainlit hello
|
|
|
87
75
|
|
|
88
76
|
If this opens the `hello app` in your browser, you're all set!
|
|
89
77
|
|
|
78
|
+
### Development version
|
|
79
|
+
|
|
80
|
+
The latest in-development version can be installed straight from GitHub with:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
pip install git+https://github.com/Chainlit/chainlit.git#subdirectory=backend/
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
(Requires Node and pnpm installed on the system.)
|
|
87
|
+
|
|
90
88
|
## 🚀 Quickstart
|
|
91
89
|
|
|
92
90
|
### 🐍 Pure Python
|
|
@@ -132,24 +130,6 @@ chainlit run demo.py -w
|
|
|
132
130
|
|
|
133
131
|
<img src="/images/quick-start.png" alt="Quick Start"></img>
|
|
134
132
|
|
|
135
|
-
## 🎉 Key Features and Integrations
|
|
136
|
-
|
|
137
|
-
Full documentation is available [here](https://docs.chainlit.io). Key features:
|
|
138
|
-
|
|
139
|
-
- [💬 Multi Modal chats](https://docs.chainlit.io/advanced-features/multi-modal)
|
|
140
|
-
- [💭 Chain of Thought visualization](https://docs.chainlit.io/concepts/step)
|
|
141
|
-
- [💾 Data persistence + human feedback](https://docs.chainlit.io/data-persistence/overview)
|
|
142
|
-
- [🐛 Debug Mode](https://docs.chainlit.io/data-persistence/enterprise#debug-mode)
|
|
143
|
-
- [👤 Authentication](https://docs.chainlit.io/authentication/overview)
|
|
144
|
-
|
|
145
|
-
Chainlit is compatible with all Python programs and libraries. That being said, it comes with integrations for:
|
|
146
|
-
|
|
147
|
-
- [LangChain](https://docs.chainlit.io/integrations/langchain)
|
|
148
|
-
- [Llama Index](https://docs.chainlit.io/integrations/llama-index)
|
|
149
|
-
- [Autogen](https://github.com/Chainlit/cookbook/tree/main/pyautogen)
|
|
150
|
-
- [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
|
|
151
|
-
- [Haystack](https://docs.chainlit.io/integrations/haystack)
|
|
152
|
-
|
|
153
133
|
## 📚 More Examples - Cookbook
|
|
154
134
|
|
|
155
135
|
You can find various examples of Chainlit apps [here](https://github.com/Chainlit/cookbook) that leverage tools and services such as OpenAI, Anthropiс, LangChain, LlamaIndex, ChromaDB, Pinecone and more.
|
|
@@ -10,22 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
Chainlit is an open-source async Python framework which allows developers to build scalable Conversational AI or agentic applications.
|
|
12
12
|
|
|
13
|
-
- ✅ ChatGPT-like application
|
|
14
|
-
- ✅ Embedded Chatbot & Software Copilot
|
|
15
|
-
- ✅ Slack & Discord
|
|
16
|
-
- ✅ Custom frontend (build your own agentic experience)
|
|
17
|
-
- ✅ API Endpoint
|
|
18
|
-
|
|
19
13
|
Full documentation is available [here](https://docs.chainlit.io). You can ask Chainlit related questions to [Chainlit Help](https://help.chainlit.io/), an app built using Chainlit!
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
> Check out [Literal AI](https://literalai.com), our product to monitor and evaluate LLM applications! It works with any Python or TypeScript applications and [seamlessly](https://docs.chainlit.io/data-persistence/overview) with Chainlit by adding a `LITERAL_API_KEY` in your project.
|
|
23
|
-
>
|
|
24
|
-
> Chainlit is developed and maintained by the Literal AI team, which is currently focused on expanding the capabilities of Literal AI. While we continue to support and maintain Chainlit, we are also committed to enabling the community to contribute, particularly in areas like integrations and data layers.
|
|
15
|
+
https://github.com/user-attachments/assets/b3738aba-55c0-42fa-ac00-6efd1ee0d148
|
|
25
16
|
|
|
26
|
-
<p align="center">
|
|
27
|
-
<img src="https://github.com/Chainlit/chainlit/assets/13104895/0c2cc7a9-766c-41d3-aae2-117a2d0eb8ed" alt="Chainlit user interface" width="80%"></img>
|
|
28
|
-
</p>
|
|
29
17
|
|
|
30
18
|
## Installation
|
|
31
19
|
|
|
@@ -38,6 +26,16 @@ chainlit hello
|
|
|
38
26
|
|
|
39
27
|
If this opens the `hello app` in your browser, you're all set!
|
|
40
28
|
|
|
29
|
+
### Development version
|
|
30
|
+
|
|
31
|
+
The latest in-development version can be installed straight from GitHub with:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
pip install git+https://github.com/Chainlit/chainlit.git#subdirectory=backend/
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
(Requires Node and pnpm installed on the system.)
|
|
38
|
+
|
|
41
39
|
## 🚀 Quickstart
|
|
42
40
|
|
|
43
41
|
### 🐍 Pure Python
|
|
@@ -83,24 +81,6 @@ chainlit run demo.py -w
|
|
|
83
81
|
|
|
84
82
|
<img src="/images/quick-start.png" alt="Quick Start"></img>
|
|
85
83
|
|
|
86
|
-
## 🎉 Key Features and Integrations
|
|
87
|
-
|
|
88
|
-
Full documentation is available [here](https://docs.chainlit.io). Key features:
|
|
89
|
-
|
|
90
|
-
- [💬 Multi Modal chats](https://docs.chainlit.io/advanced-features/multi-modal)
|
|
91
|
-
- [💭 Chain of Thought visualization](https://docs.chainlit.io/concepts/step)
|
|
92
|
-
- [💾 Data persistence + human feedback](https://docs.chainlit.io/data-persistence/overview)
|
|
93
|
-
- [🐛 Debug Mode](https://docs.chainlit.io/data-persistence/enterprise#debug-mode)
|
|
94
|
-
- [👤 Authentication](https://docs.chainlit.io/authentication/overview)
|
|
95
|
-
|
|
96
|
-
Chainlit is compatible with all Python programs and libraries. That being said, it comes with integrations for:
|
|
97
|
-
|
|
98
|
-
- [LangChain](https://docs.chainlit.io/integrations/langchain)
|
|
99
|
-
- [Llama Index](https://docs.chainlit.io/integrations/llama-index)
|
|
100
|
-
- [Autogen](https://github.com/Chainlit/cookbook/tree/main/pyautogen)
|
|
101
|
-
- [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
|
|
102
|
-
- [Haystack](https://docs.chainlit.io/integrations/haystack)
|
|
103
|
-
|
|
104
84
|
## 📚 More Examples - Cookbook
|
|
105
85
|
|
|
106
86
|
You can find various examples of Chainlit apps [here](https://github.com/Chainlit/cookbook) that leverage tools and services such as OpenAI, Anthropiс, LangChain, LlamaIndex, ChromaDB, Pinecone and more.
|
|
@@ -14,6 +14,9 @@ if env_found:
|
|
|
14
14
|
import asyncio
|
|
15
15
|
from typing import TYPE_CHECKING, Any, Dict
|
|
16
16
|
|
|
17
|
+
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
18
|
+
from pydantic.dataclasses import dataclass
|
|
19
|
+
|
|
17
20
|
import chainlit.input_widget as input_widget
|
|
18
21
|
from chainlit.action import Action
|
|
19
22
|
from chainlit.cache import cache
|
|
@@ -22,7 +25,8 @@ from chainlit.chat_settings import ChatSettings
|
|
|
22
25
|
from chainlit.context import context
|
|
23
26
|
from chainlit.element import (
|
|
24
27
|
Audio,
|
|
25
|
-
|
|
28
|
+
CustomElement,
|
|
29
|
+
Dataframe,
|
|
26
30
|
File,
|
|
27
31
|
Image,
|
|
28
32
|
Pdf,
|
|
@@ -43,21 +47,21 @@ from chainlit.message import (
|
|
|
43
47
|
)
|
|
44
48
|
from chainlit.step import Step, step
|
|
45
49
|
from chainlit.sync import make_async, run_sync
|
|
46
|
-
from chainlit.types import
|
|
50
|
+
from chainlit.types import ChatProfile, InputAudioChunk, OutputAudioChunk, Starter
|
|
47
51
|
from chainlit.user import PersistedUser, User
|
|
48
52
|
from chainlit.user_session import user_session
|
|
49
53
|
from chainlit.utils import make_module_getattr
|
|
50
54
|
from chainlit.version import __version__
|
|
51
|
-
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
52
|
-
from pydantic.dataclasses import dataclass
|
|
53
55
|
|
|
54
56
|
from .callbacks import (
|
|
55
57
|
action_callback,
|
|
56
58
|
author_rename,
|
|
59
|
+
data_layer,
|
|
57
60
|
header_auth_callback,
|
|
58
61
|
oauth_callback,
|
|
59
62
|
on_audio_chunk,
|
|
60
63
|
on_audio_end,
|
|
64
|
+
on_audio_start,
|
|
61
65
|
on_chat_end,
|
|
62
66
|
on_chat_resume,
|
|
63
67
|
on_chat_start,
|
|
@@ -65,7 +69,9 @@ from .callbacks import (
|
|
|
65
69
|
on_message,
|
|
66
70
|
on_settings_update,
|
|
67
71
|
on_stop,
|
|
72
|
+
on_window_message,
|
|
68
73
|
password_auth_callback,
|
|
74
|
+
send_window_message,
|
|
69
75
|
set_chat_profiles,
|
|
70
76
|
set_starters,
|
|
71
77
|
)
|
|
@@ -111,77 +117,73 @@ __getattr__ = make_module_getattr(
|
|
|
111
117
|
)
|
|
112
118
|
|
|
113
119
|
__all__ = [
|
|
114
|
-
"__version__",
|
|
115
|
-
"ChatProfile",
|
|
116
|
-
"Starter",
|
|
117
|
-
"user_session",
|
|
118
|
-
"chat_context",
|
|
119
|
-
"CopilotFunction",
|
|
120
|
-
"AudioChunk",
|
|
121
120
|
"Action",
|
|
122
|
-
"
|
|
123
|
-
"
|
|
121
|
+
"AskActionMessage",
|
|
122
|
+
"AskFileMessage",
|
|
123
|
+
"AskUserMessage",
|
|
124
|
+
"AsyncLangchainCallbackHandler",
|
|
124
125
|
"Audio",
|
|
126
|
+
"ChatGeneration",
|
|
127
|
+
"ChatProfile",
|
|
128
|
+
"ChatSettings",
|
|
129
|
+
"CompletionGeneration",
|
|
130
|
+
"CopilotFunction",
|
|
131
|
+
"CustomElement",
|
|
132
|
+
"Dataframe",
|
|
133
|
+
"ErrorMessage",
|
|
134
|
+
"File",
|
|
135
|
+
"GenerationMessage",
|
|
136
|
+
"HaystackAgentCallbackHandler",
|
|
137
|
+
"Image",
|
|
138
|
+
"InputAudioChunk",
|
|
139
|
+
"LangchainCallbackHandler",
|
|
140
|
+
"LlamaIndexCallbackHandler",
|
|
141
|
+
"Message",
|
|
142
|
+
"OutputAudioChunk",
|
|
125
143
|
"Pdf",
|
|
144
|
+
"PersistedUser",
|
|
126
145
|
"Plotly",
|
|
127
|
-
"Image",
|
|
128
|
-
"Text",
|
|
129
|
-
"Component",
|
|
130
146
|
"Pyplot",
|
|
131
|
-
"
|
|
147
|
+
"Starter",
|
|
148
|
+
"Step",
|
|
132
149
|
"Task",
|
|
133
150
|
"TaskList",
|
|
134
151
|
"TaskStatus",
|
|
152
|
+
"Text",
|
|
153
|
+
"User",
|
|
135
154
|
"Video",
|
|
136
|
-
"
|
|
137
|
-
"input_widget",
|
|
138
|
-
"Message",
|
|
139
|
-
"ErrorMessage",
|
|
140
|
-
"AskUserMessage",
|
|
141
|
-
"AskActionMessage",
|
|
142
|
-
"AskFileMessage",
|
|
143
|
-
"Step",
|
|
144
|
-
"step",
|
|
145
|
-
"ChatGeneration",
|
|
146
|
-
"CompletionGeneration",
|
|
147
|
-
"GenerationMessage",
|
|
148
|
-
"on_logout",
|
|
149
|
-
"on_chat_start",
|
|
150
|
-
"on_chat_end",
|
|
151
|
-
"on_chat_resume",
|
|
152
|
-
"on_stop",
|
|
155
|
+
"__version__",
|
|
153
156
|
"action_callback",
|
|
154
157
|
"author_rename",
|
|
155
|
-
"on_settings_update",
|
|
156
|
-
"password_auth_callback",
|
|
157
|
-
"header_auth_callback",
|
|
158
|
-
"sleep",
|
|
159
|
-
"run_sync",
|
|
160
|
-
"make_async",
|
|
161
158
|
"cache",
|
|
159
|
+
"chat_context",
|
|
162
160
|
"context",
|
|
163
|
-
"
|
|
164
|
-
"AsyncLangchainCallbackHandler",
|
|
165
|
-
"LlamaIndexCallbackHandler",
|
|
166
|
-
"HaystackAgentCallbackHandler",
|
|
167
|
-
"instrument_openai",
|
|
168
|
-
"instrument_mistralai",
|
|
169
|
-
"password_auth_callback",
|
|
161
|
+
"data_layer",
|
|
170
162
|
"header_auth_callback",
|
|
163
|
+
"input_widget",
|
|
164
|
+
"instrument_mistralai",
|
|
165
|
+
"instrument_openai",
|
|
166
|
+
"make_async",
|
|
171
167
|
"oauth_callback",
|
|
168
|
+
"on_audio_chunk",
|
|
169
|
+
"on_audio_end",
|
|
170
|
+
"on_audio_start",
|
|
171
|
+
"on_chat_end",
|
|
172
|
+
"on_chat_resume",
|
|
173
|
+
"on_chat_start",
|
|
172
174
|
"on_logout",
|
|
173
175
|
"on_message",
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
+
"on_settings_update",
|
|
177
|
+
"on_stop",
|
|
178
|
+
"on_window_message",
|
|
179
|
+
"password_auth_callback",
|
|
180
|
+
"run_sync",
|
|
181
|
+
"send_window_message",
|
|
176
182
|
"set_chat_profiles",
|
|
177
183
|
"set_starters",
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
"author_rename",
|
|
182
|
-
"on_stop",
|
|
183
|
-
"action_callback",
|
|
184
|
-
"on_settings_update",
|
|
184
|
+
"sleep",
|
|
185
|
+
"step",
|
|
186
|
+
"user_session",
|
|
185
187
|
]
|
|
186
188
|
|
|
187
189
|
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import uuid
|
|
2
|
-
from typing import Optional
|
|
2
|
+
from typing import Dict, Optional
|
|
3
|
+
|
|
4
|
+
from dataclasses_json import DataClassJsonMixin
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from pydantic.dataclasses import dataclass
|
|
3
7
|
|
|
4
8
|
from chainlit.context import context
|
|
5
9
|
from chainlit.telemetry import trace_event
|
|
6
|
-
from dataclasses_json import DataClassJsonMixin
|
|
7
|
-
from pydantic.dataclasses import Field, dataclass
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
@dataclass
|
|
11
13
|
class Action(DataClassJsonMixin):
|
|
12
14
|
# Name of the action, this should be used in the action_callback
|
|
13
15
|
name: str
|
|
14
|
-
# The
|
|
15
|
-
|
|
16
|
-
# The label of the action. This is what the user will see.
|
|
16
|
+
# The parameters to call this action with.
|
|
17
|
+
payload: Dict
|
|
18
|
+
# The label of the action. This is what the user will see.
|
|
17
19
|
label: str = ""
|
|
18
|
-
# The
|
|
19
|
-
|
|
20
|
+
# The tooltip of the action button. This is what the user will see when they hover the action.
|
|
21
|
+
tooltip: str = ""
|
|
22
|
+
# The lucid icon name for this action.
|
|
23
|
+
icon: Optional[str] = None
|
|
20
24
|
# This should not be set manually, only used internally.
|
|
21
25
|
forId: Optional[str] = None
|
|
22
26
|
# The ID of the action
|
|
23
27
|
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
|
|
24
|
-
# Show the action in a drawer menu
|
|
25
|
-
collapsed: bool = False
|
|
26
28
|
|
|
27
29
|
def __post_init__(self) -> None:
|
|
28
30
|
trace_event(f"init {self.__class__.__name__}")
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from datetime import datetime, timedelta
|
|
3
|
-
from typing import Any, Dict
|
|
4
2
|
|
|
5
|
-
import
|
|
3
|
+
from fastapi import Depends, HTTPException
|
|
4
|
+
|
|
6
5
|
from chainlit.config import config
|
|
7
6
|
from chainlit.data import get_data_layer
|
|
7
|
+
from chainlit.logger import logger
|
|
8
8
|
from chainlit.oauth_providers import get_configured_oauth_providers
|
|
9
|
-
from chainlit.user import User
|
|
10
|
-
from fastapi import Depends, HTTPException
|
|
11
|
-
from fastapi.security import OAuth2PasswordBearer
|
|
12
|
-
|
|
13
|
-
reuseable_oauth = OAuth2PasswordBearer(tokenUrl="/login", auto_error=False)
|
|
14
9
|
|
|
10
|
+
from .cookie import OAuth2PasswordBearerWithCookie
|
|
11
|
+
from .jwt import create_jwt, decode_jwt, get_jwt_secret
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
return os.environ.get("CHAINLIT_AUTH_SECRET")
|
|
13
|
+
reuseable_oauth = OAuth2PasswordBearerWithCookie(tokenUrl="/login", auto_error=False)
|
|
18
14
|
|
|
19
15
|
|
|
20
16
|
def ensure_jwt_secret():
|
|
@@ -45,45 +41,36 @@ def get_configuration():
|
|
|
45
41
|
"oauthProviders": (
|
|
46
42
|
get_configured_oauth_providers() if is_oauth_enabled() else []
|
|
47
43
|
),
|
|
44
|
+
"default_theme": config.ui.default_theme,
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
|
|
51
|
-
def create_jwt(data: User) -> str:
|
|
52
|
-
to_encode: Dict[str, Any] = data.to_dict()
|
|
53
|
-
to_encode.update(
|
|
54
|
-
{
|
|
55
|
-
"exp": datetime.utcnow() + timedelta(minutes=60 * 24 * 15), # 15 days
|
|
56
|
-
}
|
|
57
|
-
)
|
|
58
|
-
encoded_jwt = jwt.encode(to_encode, get_jwt_secret(), algorithm="HS256")
|
|
59
|
-
return encoded_jwt
|
|
60
|
-
|
|
61
|
-
|
|
62
48
|
async def authenticate_user(token: str = Depends(reuseable_oauth)):
|
|
63
49
|
try:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
del dict["exp"]
|
|
71
|
-
user = User(**dict)
|
|
72
|
-
except Exception:
|
|
73
|
-
raise HTTPException(status_code=401, detail="Invalid authentication token")
|
|
50
|
+
user = decode_jwt(token)
|
|
51
|
+
except Exception as e:
|
|
52
|
+
raise HTTPException(
|
|
53
|
+
status_code=401, detail="Invalid authentication token"
|
|
54
|
+
) from e
|
|
55
|
+
|
|
74
56
|
if data_layer := get_data_layer():
|
|
57
|
+
# Get or create persistent user if we've a data layer available.
|
|
75
58
|
try:
|
|
76
59
|
persisted_user = await data_layer.get_user(user.identifier)
|
|
77
60
|
if persisted_user is None:
|
|
78
61
|
persisted_user = await data_layer.create_user(user)
|
|
79
|
-
|
|
62
|
+
assert persisted_user
|
|
63
|
+
except Exception as e:
|
|
64
|
+
logger.exception("Unable to get persisted_user from data layer: %s", e)
|
|
80
65
|
return user
|
|
81
66
|
|
|
82
67
|
if user and user.display_name:
|
|
68
|
+
# Copy ephemeral display_name from authenticated user to persistent user.
|
|
83
69
|
persisted_user.display_name = user.display_name
|
|
70
|
+
|
|
84
71
|
return persisted_user
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
|
|
73
|
+
return user
|
|
87
74
|
|
|
88
75
|
|
|
89
76
|
async def get_current_user(token: str = Depends(reuseable_oauth)):
|
|
@@ -91,3 +78,6 @@ async def get_current_user(token: str = Depends(reuseable_oauth)):
|
|
|
91
78
|
return None
|
|
92
79
|
|
|
93
80
|
return await authenticate_user(token)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
__all__ = ["create_jwt", "get_configuration", "get_current_user"]
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Literal, Optional, cast
|
|
3
|
+
|
|
4
|
+
from fastapi import Request, Response
|
|
5
|
+
from fastapi.exceptions import HTTPException
|
|
6
|
+
from fastapi.security.base import SecurityBase
|
|
7
|
+
from fastapi.security.utils import get_authorization_scheme_param
|
|
8
|
+
from starlette.status import HTTP_401_UNAUTHORIZED
|
|
9
|
+
|
|
10
|
+
""" Module level cookie settings. """
|
|
11
|
+
_cookie_samesite = cast(
|
|
12
|
+
Literal["lax", "strict", "none"],
|
|
13
|
+
os.environ.get("CHAINLIT_COOKIE_SAMESITE", "lax"),
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
assert (
|
|
17
|
+
_cookie_samesite
|
|
18
|
+
in [
|
|
19
|
+
"lax",
|
|
20
|
+
"strict",
|
|
21
|
+
"none",
|
|
22
|
+
]
|
|
23
|
+
), "Invalid value for CHAINLIT_COOKIE_SAMESITE. Must be one of 'lax', 'strict' or 'none'."
|
|
24
|
+
_cookie_secure = _cookie_samesite == "none"
|
|
25
|
+
|
|
26
|
+
_auth_cookie_lifetime = 60 * 60 # 1 hour
|
|
27
|
+
_state_cookie_lifetime = 3 * 60 # 3m
|
|
28
|
+
_auth_cookie_name = "access_token"
|
|
29
|
+
_state_cookie_name = "oauth_state"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class OAuth2PasswordBearerWithCookie(SecurityBase):
|
|
33
|
+
"""
|
|
34
|
+
OAuth2 password flow with cookie support with fallback to bearer token.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
tokenUrl: str,
|
|
40
|
+
scheme_name: Optional[str] = None,
|
|
41
|
+
auto_error: bool = True,
|
|
42
|
+
):
|
|
43
|
+
self.tokenUrl = tokenUrl
|
|
44
|
+
self.scheme_name = scheme_name or self.__class__.__name__
|
|
45
|
+
self.auto_error = auto_error
|
|
46
|
+
|
|
47
|
+
async def __call__(self, request: Request) -> Optional[str]:
|
|
48
|
+
# First try to get the token from the cookie
|
|
49
|
+
token = request.cookies.get(_auth_cookie_name)
|
|
50
|
+
|
|
51
|
+
# If no cookie, try the Authorization header as fallback
|
|
52
|
+
if not token:
|
|
53
|
+
# TODO: Only bother to check if cookie auth is explicitly disabled.
|
|
54
|
+
authorization = request.headers.get("Authorization")
|
|
55
|
+
if authorization:
|
|
56
|
+
scheme, token = get_authorization_scheme_param(authorization)
|
|
57
|
+
if scheme.lower() != "bearer":
|
|
58
|
+
if self.auto_error:
|
|
59
|
+
raise HTTPException(
|
|
60
|
+
status_code=HTTP_401_UNAUTHORIZED,
|
|
61
|
+
detail="Invalid authentication credentials",
|
|
62
|
+
headers={"WWW-Authenticate": "Bearer"},
|
|
63
|
+
)
|
|
64
|
+
else:
|
|
65
|
+
return None
|
|
66
|
+
else:
|
|
67
|
+
if self.auto_error:
|
|
68
|
+
raise HTTPException(
|
|
69
|
+
status_code=HTTP_401_UNAUTHORIZED,
|
|
70
|
+
detail="Not authenticated",
|
|
71
|
+
headers={"WWW-Authenticate": "Bearer"},
|
|
72
|
+
)
|
|
73
|
+
else:
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
return token
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def set_auth_cookie(response: Response, token: str):
|
|
80
|
+
"""
|
|
81
|
+
Helper function to set the authentication cookie with secure parameters
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
response.set_cookie(
|
|
85
|
+
key=_auth_cookie_name,
|
|
86
|
+
value=token,
|
|
87
|
+
httponly=True,
|
|
88
|
+
secure=_cookie_secure,
|
|
89
|
+
samesite=_cookie_samesite,
|
|
90
|
+
max_age=_auth_cookie_lifetime,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def clear_auth_cookie(response: Response):
|
|
95
|
+
"""
|
|
96
|
+
Helper function to clear the authentication cookie
|
|
97
|
+
"""
|
|
98
|
+
response.delete_cookie(key=_auth_cookie_name, path="/")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def set_oauth_state_cookie(response: Response, token: str):
|
|
102
|
+
response.set_cookie(
|
|
103
|
+
_state_cookie_name,
|
|
104
|
+
token,
|
|
105
|
+
httponly=True,
|
|
106
|
+
samesite=_cookie_samesite,
|
|
107
|
+
secure=_cookie_secure,
|
|
108
|
+
max_age=_state_cookie_lifetime,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def validate_oauth_state_cookie(request: Request, state: str):
|
|
113
|
+
"""Check the state from the oauth provider against the browser cookie."""
|
|
114
|
+
|
|
115
|
+
oauth_state = request.cookies.get(_state_cookie_name)
|
|
116
|
+
|
|
117
|
+
if oauth_state != state:
|
|
118
|
+
raise Exception("oauth state does not correspond")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def clear_oauth_state_cookie(response: Response):
|
|
122
|
+
"""Oauth complete, delete state token."""
|
|
123
|
+
response.delete_cookie(_state_cookie_name) # Do we set path here?
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
import os
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
import jwt as pyjwt
|
|
6
|
+
|
|
7
|
+
from chainlit.config import config
|
|
8
|
+
from chainlit.user import User
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_jwt_secret() -> Optional[str]:
|
|
12
|
+
return os.environ.get("CHAINLIT_AUTH_SECRET")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def create_jwt(data: User) -> str:
|
|
16
|
+
to_encode: Dict[str, Any] = data.to_dict()
|
|
17
|
+
to_encode.update(
|
|
18
|
+
{
|
|
19
|
+
"exp": datetime.datetime.utcnow()
|
|
20
|
+
+ datetime.timedelta(seconds=config.project.user_session_timeout),
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
secret = get_jwt_secret()
|
|
24
|
+
assert secret
|
|
25
|
+
encoded_jwt = pyjwt.encode(to_encode, secret, algorithm="HS256")
|
|
26
|
+
return encoded_jwt
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def decode_jwt(token: str) -> User:
|
|
30
|
+
dict = pyjwt.decode(
|
|
31
|
+
token,
|
|
32
|
+
get_jwt_secret(),
|
|
33
|
+
algorithms=["HS256"],
|
|
34
|
+
options={"verify_signature": True},
|
|
35
|
+
)
|
|
36
|
+
del dict["exp"]
|
|
37
|
+
return User(**dict)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import importlib.util
|
|
1
2
|
import os
|
|
2
3
|
import threading
|
|
4
|
+
from typing import Any
|
|
3
5
|
|
|
4
6
|
from chainlit.config import config
|
|
5
7
|
from chainlit.logger import logger
|
|
@@ -8,11 +10,7 @@ from chainlit.logger import logger
|
|
|
8
10
|
def init_lc_cache():
|
|
9
11
|
use_cache = config.project.cache is True and config.run.no_cache is False
|
|
10
12
|
|
|
11
|
-
if use_cache:
|
|
12
|
-
try:
|
|
13
|
-
import langchain
|
|
14
|
-
except ImportError:
|
|
15
|
-
return
|
|
13
|
+
if use_cache and importlib.util.find_spec("langchain") is not None:
|
|
16
14
|
from langchain.cache import SQLiteCache
|
|
17
15
|
from langchain.globals import set_llm_cache
|
|
18
16
|
|
|
@@ -25,7 +23,7 @@ def init_lc_cache():
|
|
|
25
23
|
)
|
|
26
24
|
|
|
27
25
|
|
|
28
|
-
_cache = {}
|
|
26
|
+
_cache: dict[tuple, Any] = {}
|
|
29
27
|
_cache_lock = threading.Lock()
|
|
30
28
|
|
|
31
29
|
|