chainlit 1.0.401__tar.gz → 2.0.3__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.

Files changed (127) hide show
  1. {chainlit-1.0.401 → chainlit-2.0.3}/PKG-INFO +48 -50
  2. {chainlit-1.0.401 → chainlit-2.0.3}/README.md +26 -35
  3. chainlit-2.0.3/chainlit/__init__.py +191 -0
  4. chainlit-2.0.3/chainlit/_utils.py +8 -0
  5. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/action.py +12 -10
  6. chainlit-1.0.401/chainlit/auth.py → chainlit-2.0.3/chainlit/auth/__init__.py +28 -36
  7. chainlit-2.0.3/chainlit/auth/cookie.py +122 -0
  8. chainlit-2.0.3/chainlit/auth/jwt.py +39 -0
  9. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/cache.py +4 -6
  10. chainlit-2.0.3/chainlit/callbacks.py +362 -0
  11. chainlit-2.0.3/chainlit/chat_context.py +64 -0
  12. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/chat_settings.py +3 -1
  13. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/cli/__init__.py +77 -8
  14. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/config.py +181 -101
  15. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/context.py +42 -13
  16. chainlit-2.0.3/chainlit/copilot/dist/index.js +12200 -0
  17. chainlit-2.0.3/chainlit/data/__init__.py +113 -0
  18. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/data/acl.py +6 -2
  19. chainlit-2.0.3/chainlit/data/base.py +107 -0
  20. chainlit-2.0.3/chainlit/data/chainlit_data_layer.py +608 -0
  21. chainlit-2.0.3/chainlit/data/dynamodb.py +590 -0
  22. chainlit-2.0.3/chainlit/data/literalai.py +500 -0
  23. chainlit-2.0.3/chainlit/data/sql_alchemy.py +721 -0
  24. chainlit-2.0.3/chainlit/data/storage_clients/azure.py +81 -0
  25. chainlit-2.0.3/chainlit/data/storage_clients/azure_blob.py +89 -0
  26. chainlit-2.0.3/chainlit/data/storage_clients/base.py +26 -0
  27. chainlit-2.0.3/chainlit/data/storage_clients/gcs.py +88 -0
  28. chainlit-2.0.3/chainlit/data/storage_clients/s3.py +75 -0
  29. chainlit-2.0.3/chainlit/data/utils.py +29 -0
  30. chainlit-2.0.3/chainlit/discord/__init__.py +6 -0
  31. chainlit-2.0.3/chainlit/discord/app.py +354 -0
  32. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/element.py +91 -33
  33. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/emitter.py +80 -29
  34. chainlit-2.0.3/chainlit/frontend/dist/assets/DailyMotion-C_XC7xJI.js +1 -0
  35. chainlit-2.0.3/chainlit/frontend/dist/assets/Dataframe-Cs4l4hA1.js +22 -0
  36. chainlit-2.0.3/chainlit/frontend/dist/assets/Facebook-CUeCH7hk.js +1 -0
  37. chainlit-2.0.3/chainlit/frontend/dist/assets/FilePlayer-CB-fYkx8.js +1 -0
  38. chainlit-2.0.3/chainlit/frontend/dist/assets/Kaltura-YX6qaq72.js +1 -0
  39. chainlit-2.0.3/chainlit/frontend/dist/assets/Mixcloud-DGV0ldjP.js +1 -0
  40. chainlit-2.0.3/chainlit/frontend/dist/assets/Mux-CmRss5oc.js +1 -0
  41. chainlit-2.0.3/chainlit/frontend/dist/assets/Preview-DBVJn7-H.js +1 -0
  42. chainlit-2.0.3/chainlit/frontend/dist/assets/SoundCloud-qLUb18oY.js +1 -0
  43. chainlit-2.0.3/chainlit/frontend/dist/assets/Streamable-BvYP7bFp.js +1 -0
  44. chainlit-2.0.3/chainlit/frontend/dist/assets/Twitch-CTHt-sGZ.js +1 -0
  45. chainlit-2.0.3/chainlit/frontend/dist/assets/Vidyard-B-0mCJbm.js +1 -0
  46. chainlit-2.0.3/chainlit/frontend/dist/assets/Vimeo-Dnp7ri8q.js +1 -0
  47. chainlit-2.0.3/chainlit/frontend/dist/assets/Wistia-DW0x_UBn.js +1 -0
  48. chainlit-2.0.3/chainlit/frontend/dist/assets/YouTube--98FipvA.js +1 -0
  49. chainlit-2.0.3/chainlit/frontend/dist/assets/index-D71nZ46o.js +8665 -0
  50. chainlit-2.0.3/chainlit/frontend/dist/assets/index-g8LTJwwr.css +1 -0
  51. chainlit-2.0.3/chainlit/frontend/dist/assets/react-plotly-Cn_BQTQw.js +3484 -0
  52. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/frontend/dist/index.html +2 -4
  53. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/haystack/callbacks.py +4 -7
  54. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/input_widget.py +8 -4
  55. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/langchain/callbacks.py +103 -68
  56. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/langflow/__init__.py +1 -0
  57. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/llama_index/callbacks.py +65 -40
  58. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/markdown.py +22 -6
  59. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/message.py +54 -56
  60. chainlit-2.0.3/chainlit/mistralai/__init__.py +50 -0
  61. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/oauth_providers.py +266 -8
  62. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/openai/__init__.py +10 -18
  63. chainlit-2.0.3/chainlit/py.typed +0 -0
  64. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/secret.py +1 -1
  65. chainlit-2.0.3/chainlit/server.py +1311 -0
  66. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/session.py +108 -90
  67. chainlit-2.0.3/chainlit/slack/__init__.py +6 -0
  68. chainlit-2.0.3/chainlit/slack/app.py +397 -0
  69. chainlit-2.0.3/chainlit/socket.py +387 -0
  70. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/step.py +141 -89
  71. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/sync.py +2 -1
  72. chainlit-2.0.3/chainlit/teams/__init__.py +6 -0
  73. chainlit-2.0.3/chainlit/teams/app.py +338 -0
  74. chainlit-2.0.3/chainlit/translations/bn.json +235 -0
  75. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/translations/en-US.json +83 -4
  76. chainlit-2.0.3/chainlit/translations/gu.json +235 -0
  77. chainlit-2.0.3/chainlit/translations/he-IL.json +235 -0
  78. chainlit-2.0.3/chainlit/translations/hi.json +235 -0
  79. chainlit-2.0.3/chainlit/translations/kn.json +235 -0
  80. chainlit-2.0.3/chainlit/translations/ml.json +235 -0
  81. chainlit-2.0.3/chainlit/translations/mr.json +235 -0
  82. chainlit-2.0.3/chainlit/translations/nl-NL.json +233 -0
  83. chainlit-2.0.3/chainlit/translations/ta.json +235 -0
  84. chainlit-2.0.3/chainlit/translations/te.json +235 -0
  85. chainlit-2.0.3/chainlit/translations/zh-CN.json +233 -0
  86. chainlit-2.0.3/chainlit/translations.py +60 -0
  87. chainlit-2.0.3/chainlit/types.py +269 -0
  88. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/user.py +14 -3
  89. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/user_session.py +6 -3
  90. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/utils.py +52 -5
  91. chainlit-2.0.3/chainlit/version.py +8 -0
  92. chainlit-2.0.3/pyproject.toml +155 -0
  93. chainlit-1.0.401/chainlit/__init__.py +0 -372
  94. chainlit-1.0.401/chainlit/cli/utils.py +0 -24
  95. chainlit-1.0.401/chainlit/copilot/dist/index.js +0 -4353
  96. chainlit-1.0.401/chainlit/data/__init__.py +0 -428
  97. chainlit-1.0.401/chainlit/frontend/dist/assets/index-9711593e.js +0 -723
  98. chainlit-1.0.401/chainlit/frontend/dist/assets/index-d088547c.css +0 -1
  99. chainlit-1.0.401/chainlit/frontend/dist/assets/react-plotly-d8762cc2.js +0 -3602
  100. chainlit-1.0.401/chainlit/playground/__init__.py +0 -2
  101. chainlit-1.0.401/chainlit/playground/config.py +0 -40
  102. chainlit-1.0.401/chainlit/playground/provider.py +0 -108
  103. chainlit-1.0.401/chainlit/playground/providers/__init__.py +0 -13
  104. chainlit-1.0.401/chainlit/playground/providers/anthropic.py +0 -118
  105. chainlit-1.0.401/chainlit/playground/providers/huggingface.py +0 -75
  106. chainlit-1.0.401/chainlit/playground/providers/langchain.py +0 -89
  107. chainlit-1.0.401/chainlit/playground/providers/openai.py +0 -408
  108. chainlit-1.0.401/chainlit/playground/providers/vertexai.py +0 -171
  109. chainlit-1.0.401/chainlit/server.py +0 -750
  110. chainlit-1.0.401/chainlit/socket.py +0 -304
  111. chainlit-1.0.401/chainlit/translations/pt-BR.json +0 -155
  112. chainlit-1.0.401/chainlit/types.py +0 -164
  113. chainlit-1.0.401/chainlit/version.py +0 -7
  114. chainlit-1.0.401/pyproject.toml +0 -98
  115. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/__main__.py +0 -0
  116. /chainlit-1.0.401/chainlit/copilot/dist/assets/logo_dark-2a3cf740.svg → /chainlit-2.0.3/chainlit/copilot/dist/assets/logo_dark-IkGJ_IwC.svg +0 -0
  117. /chainlit-1.0.401/chainlit/copilot/dist/assets/logo_light-b078e7bc.svg → /chainlit-2.0.3/chainlit/copilot/dist/assets/logo_light-Bb_IPh6r.svg +0 -0
  118. /chainlit-1.0.401/chainlit/py.typed → /chainlit-2.0.3/chainlit/data/storage_clients/__init__.py +0 -0
  119. /chainlit-1.0.401/chainlit/frontend/dist/assets/logo_dark-2a3cf740.svg → /chainlit-2.0.3/chainlit/frontend/dist/assets/logo_dark-IkGJ_IwC.svg +0 -0
  120. /chainlit-1.0.401/chainlit/frontend/dist/assets/logo_light-b078e7bc.svg → /chainlit-2.0.3/chainlit/frontend/dist/assets/logo_light-Bb_IPh6r.svg +0 -0
  121. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/frontend/dist/favicon.svg +0 -0
  122. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/haystack/__init__.py +0 -0
  123. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/hello.py +0 -0
  124. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/langchain/__init__.py +0 -0
  125. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/llama_index/__init__.py +0 -0
  126. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/logger.py +0 -0
  127. {chainlit-1.0.401 → chainlit-2.0.3}/chainlit/telemetry.py +0 -0
@@ -1,41 +1,48 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 1.0.401
3
+ Version: 2.0.3
4
4
  Summary: Build Conversational AI.
5
- Home-page: https://github.com/Chainlit/chainlit
6
- License: Apache-2.0 license
5
+ Home-page: https://chainlit.io/
6
+ License: Apache-2.0
7
7
  Keywords: LLM,Agents,gen ai,chat ui,chatbot ui,openai,copilot,langchain,conversational ai
8
- Author: Chainlit
9
- Requires-Python: >=3.8.1,<4.0.0
10
- Classifier: License :: Other/Proprietary License
8
+ Author: Willy Douhard
9
+ Requires-Python: >=3.9,<4.0.0
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Framework :: FastAPI
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: JavaScript
11
14
  Classifier: Programming Language :: Python :: 3
12
15
  Classifier: Programming Language :: Python :: 3.9
13
16
  Classifier: Programming Language :: Python :: 3.10
14
17
  Classifier: Programming Language :: Python :: 3.11
15
18
  Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Communications :: Chat
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Software Development :: User Interfaces
16
23
  Requires-Dist: aiofiles (>=23.1.0,<24.0.0)
17
- Requires-Dist: asyncer (>=0.0.2,<0.0.3)
24
+ Requires-Dist: asyncer (>=0.0.7,<0.0.8)
18
25
  Requires-Dist: click (>=8.1.3,<9.0.0)
19
- Requires-Dist: dataclasses_json (>=0.5.7,<0.6.0)
20
- Requires-Dist: fastapi (>=0.100)
21
- Requires-Dist: fastapi-socketio (>=0.0.10,<0.0.11)
26
+ Requires-Dist: dataclasses_json (>=0.6.7,<0.7.0)
27
+ Requires-Dist: fastapi (>=0.115.3,<0.116)
22
28
  Requires-Dist: filetype (>=1.2.0,<2.0.0)
23
29
  Requires-Dist: httpx (>=0.23.0)
24
30
  Requires-Dist: lazify (>=0.4.0,<0.5.0)
25
- Requires-Dist: literalai (==0.0.300)
26
- Requires-Dist: nest-asyncio (>=1.5.6,<2.0.0)
31
+ Requires-Dist: literalai (==0.1.103)
32
+ Requires-Dist: nest-asyncio (>=1.6.0,<2.0.0)
27
33
  Requires-Dist: packaging (>=23.1,<24.0)
28
34
  Requires-Dist: pydantic (>=1,<3)
29
35
  Requires-Dist: pyjwt (>=2.8.0,<3.0.0)
30
36
  Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
31
- Requires-Dist: python-graphql-client (>=0.4.3,<0.5.0)
32
- Requires-Dist: python-multipart (>=0.0.9,<0.0.10)
33
- Requires-Dist: starlette (<0.33.0)
37
+ Requires-Dist: python-multipart (>=0.0.18,<0.0.19)
38
+ Requires-Dist: python-socketio (>=5.11.0,<6.0.0)
39
+ Requires-Dist: starlette (>=0.41.2,<0.42.0)
34
40
  Requires-Dist: syncer (>=2.0.3,<3.0.0)
35
41
  Requires-Dist: tomli (>=2.0.1,<3.0.0)
36
42
  Requires-Dist: uptrace (>=1.22.0,<2.0.0)
37
43
  Requires-Dist: uvicorn (>=0.25.0,<0.26.0)
38
44
  Requires-Dist: watchfiles (>=0.20.0,<0.21.0)
45
+ Project-URL: Documentation, https://docs.chainlit.io/
39
46
  Project-URL: Repository, https://github.com/Chainlit/chainlit
40
47
  Description-Content-Type: text/markdown
41
48
 
@@ -43,34 +50,40 @@ Description-Content-Type: text/markdown
43
50
 
44
51
  [![](https://dcbadge.vercel.app/api/server/ZThrUxbAYw?style=flat)](https://discord.gg/k73SQ3FyUh)
45
52
  [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/chainlit_io.svg?style=social&label=Follow%20%40chainlit_io)](https://twitter.com/chainlit_io)
53
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/chainlit)
54
+ [![GitHub Contributors](https://img.shields.io/github/contributors/chainlit/chainlit)](https://github.com/chainlit/chainlit/graphs/contributors)
46
55
  [![CI](https://github.com/Chainlit/chainlit/actions/workflows/ci.yaml/badge.svg)](https://github.com/Chainlit/chainlit/actions/workflows/ci.yaml)
47
56
 
48
57
  **Build production-ready Conversational AI applications in minutes, not weeks ⚡️**
49
58
 
50
59
  Chainlit is an open-source async Python framework which allows developers to build scalable Conversational AI or agentic applications.
51
60
 
52
- - ChatGPT-like application
53
- - ✅ Embedded Chatbot & Software Copilot
54
- - ✅ Custom frontend (build your own agentic experience)
55
- - ✅ API Endpoint
61
+ 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!
56
62
 
57
- Full documentation is available [here](https://docs.chainlit.io).
63
+ https://github.com/user-attachments/assets/b3738aba-55c0-42fa-ac00-6efd1ee0d148
58
64
 
59
- Contact us [here](https://forms.gle/BX3UNBLmTF75KgZVA) for **Enterprise Support** and to get early access to Literal AI, our product to evaluate and monitor LLM applications.
60
-
61
- https://github.com/Chainlit/chainlit/assets/13104895/8882af90-fdfa-4b24-8200-1ee96c6c7490
62
65
 
63
66
  ## Installation
64
67
 
65
68
  Open a terminal and run:
66
69
 
67
- ```bash
68
- $ pip install chainlit
69
- $ chainlit hello
70
+ ```sh
71
+ pip install chainlit
72
+ chainlit hello
70
73
  ```
71
74
 
72
75
  If this opens the `hello app` in your browser, you're all set!
73
76
 
77
+ ### Development version
78
+
79
+ The latest in-development version can be installed straight from GitHub with:
80
+
81
+ ```sh
82
+ pip install git+https://github.com/Chainlit/chainlit.git#subdirectory=backend/
83
+ ```
84
+
85
+ (Requires Node and pnpm installed on the system.)
86
+
74
87
  ## 🚀 Quickstart
75
88
 
76
89
  ### 🐍 Pure Python
@@ -81,8 +94,10 @@ Create a new file `demo.py` with the following code:
81
94
  import chainlit as cl
82
95
 
83
96
 
84
- @cl.step
85
- def tool():
97
+ @cl.step(type="tool")
98
+ async def tool():
99
+ # Fake tool
100
+ await cl.sleep(2)
86
101
  return "Response from the tool!"
87
102
 
88
103
 
@@ -99,37 +114,20 @@ async def main(message: cl.Message):
99
114
  None.
100
115
  """
101
116
 
117
+
102
118
  # Call the tool
103
- tool()
119
+ tool_res = await tool()
104
120
 
105
- # Send the final answer.
106
- await cl.Message(content="This is the final answer").send()
121
+ await cl.Message(content=tool_res).send()
107
122
  ```
108
123
 
109
124
  Now run it!
110
125
 
111
- ```
112
- $ chainlit run demo.py -w
126
+ ```sh
127
+ chainlit run demo.py -w
113
128
  ```
114
129
 
115
130
  <img src="/images/quick-start.png" alt="Quick Start"></img>
116
- ## 🎉 Key Features and Integrations
117
-
118
- Full documentation is available [here](https://docs.chainlit.io). Key features:
119
-
120
- - [💬 Multi Modal chats](https://docs.chainlit.io/advanced-features/multi-modal)
121
- - [💭 Chain of Thought visualisation](https://docs.chainlit.io/concepts/step)
122
- - [💾 Data persistence + human feedback](https://docs.chainlit.io/data-persistence/overview)
123
- - [🛝 In context Prompt Playground](https://docs.chainlit.io/advanced-features/prompt-playground/overview)
124
- - [👤 Authentication](https://docs.chainlit.io/authentication/overview)
125
-
126
- Chainlit is compatible with all Python programs and libraries. That being said, it comes with integrations for:
127
-
128
- - [LangChain](https://docs.chainlit.io/integrations/langchain)
129
- - [Llama Index](https://docs.chainlit.io/integrations/llama-index)
130
- - [Autogen](https://github.com/Chainlit/cookbook/tree/main/pyautogen)
131
- - [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
132
- - [Haystack](https://docs.chainlit.io/integrations/haystack)
133
131
 
134
132
  ## 📚 More Examples - Cookbook
135
133
 
@@ -2,34 +2,40 @@
2
2
 
3
3
  [![](https://dcbadge.vercel.app/api/server/ZThrUxbAYw?style=flat)](https://discord.gg/k73SQ3FyUh)
4
4
  [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/chainlit_io.svg?style=social&label=Follow%20%40chainlit_io)](https://twitter.com/chainlit_io)
5
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/chainlit)
6
+ [![GitHub Contributors](https://img.shields.io/github/contributors/chainlit/chainlit)](https://github.com/chainlit/chainlit/graphs/contributors)
5
7
  [![CI](https://github.com/Chainlit/chainlit/actions/workflows/ci.yaml/badge.svg)](https://github.com/Chainlit/chainlit/actions/workflows/ci.yaml)
6
8
 
7
9
  **Build production-ready Conversational AI applications in minutes, not weeks ⚡️**
8
10
 
9
11
  Chainlit is an open-source async Python framework which allows developers to build scalable Conversational AI or agentic applications.
10
12
 
11
- - ChatGPT-like application
12
- - ✅ Embedded Chatbot & Software Copilot
13
- - ✅ Custom frontend (build your own agentic experience)
14
- - ✅ API Endpoint
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!
15
14
 
16
- Full documentation is available [here](https://docs.chainlit.io).
15
+ https://github.com/user-attachments/assets/b3738aba-55c0-42fa-ac00-6efd1ee0d148
17
16
 
18
- Contact us [here](https://forms.gle/BX3UNBLmTF75KgZVA) for **Enterprise Support** and to get early access to Literal AI, our product to evaluate and monitor LLM applications.
19
-
20
- https://github.com/Chainlit/chainlit/assets/13104895/8882af90-fdfa-4b24-8200-1ee96c6c7490
21
17
 
22
18
  ## Installation
23
19
 
24
20
  Open a terminal and run:
25
21
 
26
- ```bash
27
- $ pip install chainlit
28
- $ chainlit hello
22
+ ```sh
23
+ pip install chainlit
24
+ chainlit hello
29
25
  ```
30
26
 
31
27
  If this opens the `hello app` in your browser, you're all set!
32
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
+
33
39
  ## 🚀 Quickstart
34
40
 
35
41
  ### 🐍 Pure Python
@@ -40,8 +46,10 @@ Create a new file `demo.py` with the following code:
40
46
  import chainlit as cl
41
47
 
42
48
 
43
- @cl.step
44
- def tool():
49
+ @cl.step(type="tool")
50
+ async def tool():
51
+ # Fake tool
52
+ await cl.sleep(2)
45
53
  return "Response from the tool!"
46
54
 
47
55
 
@@ -58,37 +66,20 @@ async def main(message: cl.Message):
58
66
  None.
59
67
  """
60
68
 
69
+
61
70
  # Call the tool
62
- tool()
71
+ tool_res = await tool()
63
72
 
64
- # Send the final answer.
65
- await cl.Message(content="This is the final answer").send()
73
+ await cl.Message(content=tool_res).send()
66
74
  ```
67
75
 
68
76
  Now run it!
69
77
 
70
- ```
71
- $ chainlit run demo.py -w
78
+ ```sh
79
+ chainlit run demo.py -w
72
80
  ```
73
81
 
74
82
  <img src="/images/quick-start.png" alt="Quick Start"></img>
75
- ## 🎉 Key Features and Integrations
76
-
77
- Full documentation is available [here](https://docs.chainlit.io). Key features:
78
-
79
- - [💬 Multi Modal chats](https://docs.chainlit.io/advanced-features/multi-modal)
80
- - [💭 Chain of Thought visualisation](https://docs.chainlit.io/concepts/step)
81
- - [💾 Data persistence + human feedback](https://docs.chainlit.io/data-persistence/overview)
82
- - [🛝 In context Prompt Playground](https://docs.chainlit.io/advanced-features/prompt-playground/overview)
83
- - [👤 Authentication](https://docs.chainlit.io/authentication/overview)
84
-
85
- Chainlit is compatible with all Python programs and libraries. That being said, it comes with integrations for:
86
-
87
- - [LangChain](https://docs.chainlit.io/integrations/langchain)
88
- - [Llama Index](https://docs.chainlit.io/integrations/llama-index)
89
- - [Autogen](https://github.com/Chainlit/cookbook/tree/main/pyautogen)
90
- - [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
91
- - [Haystack](https://docs.chainlit.io/integrations/haystack)
92
83
 
93
84
  ## 📚 More Examples - Cookbook
94
85
 
@@ -0,0 +1,191 @@
1
+ import os
2
+
3
+ from dotenv import load_dotenv
4
+
5
+ # ruff: noqa: E402
6
+ # Keep this here to ensure imports have environment available.
7
+ env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
8
+
9
+ from chainlit.logger import logger
10
+
11
+ if env_found:
12
+ logger.info("Loaded .env file")
13
+
14
+ import asyncio
15
+ from typing import TYPE_CHECKING, Any, Dict
16
+
17
+ from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
18
+ from pydantic.dataclasses import dataclass
19
+
20
+ import chainlit.input_widget as input_widget
21
+ from chainlit.action import Action
22
+ from chainlit.cache import cache
23
+ from chainlit.chat_context import chat_context
24
+ from chainlit.chat_settings import ChatSettings
25
+ from chainlit.context import context
26
+ from chainlit.element import (
27
+ Audio,
28
+ CustomElement,
29
+ Dataframe,
30
+ File,
31
+ Image,
32
+ Pdf,
33
+ Plotly,
34
+ Pyplot,
35
+ Task,
36
+ TaskList,
37
+ TaskStatus,
38
+ Text,
39
+ Video,
40
+ )
41
+ from chainlit.message import (
42
+ AskActionMessage,
43
+ AskFileMessage,
44
+ AskUserMessage,
45
+ ErrorMessage,
46
+ Message,
47
+ )
48
+ from chainlit.step import Step, step
49
+ from chainlit.sync import make_async, run_sync
50
+ from chainlit.types import ChatProfile, InputAudioChunk, OutputAudioChunk, Starter
51
+ from chainlit.user import PersistedUser, User
52
+ from chainlit.user_session import user_session
53
+ from chainlit.utils import make_module_getattr
54
+ from chainlit.version import __version__
55
+
56
+ from .callbacks import (
57
+ action_callback,
58
+ author_rename,
59
+ data_layer,
60
+ header_auth_callback,
61
+ oauth_callback,
62
+ on_audio_chunk,
63
+ on_audio_end,
64
+ on_audio_start,
65
+ on_chat_end,
66
+ on_chat_resume,
67
+ on_chat_start,
68
+ on_logout,
69
+ on_message,
70
+ on_settings_update,
71
+ on_stop,
72
+ on_window_message,
73
+ password_auth_callback,
74
+ send_window_message,
75
+ set_chat_profiles,
76
+ set_starters,
77
+ )
78
+
79
+ if TYPE_CHECKING:
80
+ from chainlit.haystack.callbacks import HaystackAgentCallbackHandler
81
+ from chainlit.langchain.callbacks import (
82
+ AsyncLangchainCallbackHandler,
83
+ LangchainCallbackHandler,
84
+ )
85
+ from chainlit.llama_index.callbacks import LlamaIndexCallbackHandler
86
+ from chainlit.mistralai import instrument_mistralai
87
+ from chainlit.openai import instrument_openai
88
+
89
+
90
+ def sleep(duration: int):
91
+ """
92
+ Sleep for a given duration.
93
+ Args:
94
+ duration (int): The duration in seconds.
95
+ """
96
+ return asyncio.sleep(duration)
97
+
98
+
99
+ @dataclass()
100
+ class CopilotFunction:
101
+ name: str
102
+ args: Dict[str, Any]
103
+
104
+ def acall(self):
105
+ return context.emitter.send_call_fn(self.name, self.args)
106
+
107
+
108
+ __getattr__ = make_module_getattr(
109
+ {
110
+ "LangchainCallbackHandler": "chainlit.langchain.callbacks",
111
+ "AsyncLangchainCallbackHandler": "chainlit.langchain.callbacks",
112
+ "LlamaIndexCallbackHandler": "chainlit.llama_index.callbacks",
113
+ "HaystackAgentCallbackHandler": "chainlit.haystack.callbacks",
114
+ "instrument_openai": "chainlit.openai",
115
+ "instrument_mistralai": "chainlit.mistralai",
116
+ }
117
+ )
118
+
119
+ __all__ = [
120
+ "Action",
121
+ "AskActionMessage",
122
+ "AskFileMessage",
123
+ "AskUserMessage",
124
+ "AsyncLangchainCallbackHandler",
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",
143
+ "Pdf",
144
+ "PersistedUser",
145
+ "Plotly",
146
+ "Pyplot",
147
+ "Starter",
148
+ "Step",
149
+ "Task",
150
+ "TaskList",
151
+ "TaskStatus",
152
+ "Text",
153
+ "User",
154
+ "Video",
155
+ "__version__",
156
+ "action_callback",
157
+ "author_rename",
158
+ "cache",
159
+ "chat_context",
160
+ "context",
161
+ "data_layer",
162
+ "header_auth_callback",
163
+ "input_widget",
164
+ "instrument_mistralai",
165
+ "instrument_openai",
166
+ "make_async",
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",
174
+ "on_logout",
175
+ "on_message",
176
+ "on_settings_update",
177
+ "on_stop",
178
+ "on_window_message",
179
+ "password_auth_callback",
180
+ "run_sync",
181
+ "send_window_message",
182
+ "set_chat_profiles",
183
+ "set_starters",
184
+ "sleep",
185
+ "step",
186
+ "user_session",
187
+ ]
188
+
189
+
190
+ def __dir__():
191
+ return __all__
@@ -0,0 +1,8 @@
1
+ """Util functions which are explicitly not part of the public API."""
2
+
3
+ from pathlib import Path
4
+
5
+
6
+ def is_path_inside(child_path: Path, parent_path: Path) -> bool:
7
+ """Check if the child path is inside the parent path."""
8
+ return parent_path.resolve() in child_path.resolve().parents
@@ -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 value associated with the action. This is useful to differentiate between multiple actions with the same name.
15
- value: str
16
- # The label of the action. This is what the user will see. If not provided the name will be used.
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 description of the action. This is what the user will see when they hover the action.
19
- description: str = ""
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 jwt
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
- def get_jwt_secret():
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():
@@ -42,46 +38,39 @@ def get_configuration():
42
38
  "requireLogin": require_login(),
43
39
  "passwordAuth": config.code.password_auth_callback is not None,
44
40
  "headerAuth": config.code.header_auth_callback is not None,
45
- "oauthProviders": get_configured_oauth_providers()
46
- if is_oauth_enabled()
47
- else [],
41
+ "oauthProviders": (
42
+ get_configured_oauth_providers() if is_oauth_enabled() else []
43
+ ),
44
+ "default_theme": config.ui.default_theme,
48
45
  }
49
46
 
50
47
 
51
- def create_jwt(data: User) -> str:
52
- to_encode = data.to_dict() # type: Dict[str, Any]
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
- dict = jwt.decode(
65
- token,
66
- get_jwt_secret(),
67
- algorithms=["HS256"],
68
- options={"verify_signature": True},
69
- )
70
- del dict["exp"]
71
- user = User(**dict)
50
+ user = decode_jwt(token)
72
51
  except Exception as e:
73
- raise HTTPException(status_code=401, detail="Invalid authentication token")
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
- if persisted_user == None:
60
+ if persisted_user is None:
78
61
  persisted_user = await data_layer.create_user(user)
62
+ assert persisted_user
79
63
  except Exception as e:
64
+ logger.exception("Unable to get persisted_user from data layer: %s", e)
80
65
  return user
81
66
 
67
+ if user and user.display_name:
68
+ # Copy ephemeral display_name from authenticated user to persistent user.
69
+ persisted_user.display_name = user.display_name
70
+
82
71
  return persisted_user
83
- else:
84
- return user
72
+
73
+ return user
85
74
 
86
75
 
87
76
  async def get_current_user(token: str = Depends(reuseable_oauth)):
@@ -89,3 +78,6 @@ async def get_current_user(token: str = Depends(reuseable_oauth)):
89
78
  return None
90
79
 
91
80
  return await authenticate_user(token)
81
+
82
+
83
+ __all__ = ["create_jwt", "get_configuration", "get_current_user"]