chainlit 0.7.700__tar.gz → 1.0.0rc1__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 (65) hide show
  1. {chainlit-0.7.700 → chainlit-1.0.0rc1}/PKG-INFO +12 -31
  2. {chainlit-0.7.700 → chainlit-1.0.0rc1}/README.md +10 -30
  3. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/__init__.py +32 -23
  4. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/auth.py +9 -10
  5. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/cli/__init__.py +1 -2
  6. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/config.py +13 -12
  7. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/context.py +7 -3
  8. chainlit-1.0.0rc1/chainlit/data/__init__.py +379 -0
  9. chainlit-1.0.0rc1/chainlit/data/acl.py +15 -0
  10. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/element.py +86 -123
  11. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/emitter.py +117 -50
  12. chainlit-0.7.700/chainlit/frontend/dist/assets/index-71698725.js → chainlit-1.0.0rc1/chainlit/frontend/dist/assets/index-6aee009a.js +118 -292
  13. chainlit-0.7.700/chainlit/frontend/dist/assets/react-plotly-2c0acdf0.js → chainlit-1.0.0rc1/chainlit/frontend/dist/assets/react-plotly-2f07c02a.js +1 -1
  14. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/frontend/dist/index.html +1 -1
  15. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/haystack/callbacks.py +45 -43
  16. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/hello.py +1 -1
  17. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/langchain/callbacks.py +132 -120
  18. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/llama_index/callbacks.py +68 -48
  19. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/message.py +179 -207
  20. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/oauth_providers.py +39 -34
  21. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/provider.py +44 -30
  22. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/providers/anthropic.py +4 -4
  23. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/providers/huggingface.py +2 -2
  24. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/providers/langchain.py +8 -10
  25. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/providers/openai.py +19 -13
  26. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/server.py +155 -99
  27. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/session.py +109 -40
  28. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/socket.py +47 -36
  29. chainlit-1.0.0rc1/chainlit/step.py +393 -0
  30. chainlit-1.0.0rc1/chainlit/types.py +163 -0
  31. chainlit-1.0.0rc1/chainlit/user.py +32 -0
  32. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/user_session.py +1 -5
  33. {chainlit-0.7.700 → chainlit-1.0.0rc1}/pyproject.toml +4 -2
  34. chainlit-0.7.700/chainlit/client/base.py +0 -169
  35. chainlit-0.7.700/chainlit/client/cloud.py +0 -502
  36. chainlit-0.7.700/chainlit/data/__init__.py +0 -13
  37. chainlit-0.7.700/chainlit/data/acl.py +0 -14
  38. chainlit-0.7.700/chainlit/prompt.py +0 -40
  39. chainlit-0.7.700/chainlit/types.py +0 -106
  40. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/__main__.py +0 -0
  41. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/action.py +0 -0
  42. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/cache.py +0 -0
  43. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/chat_settings.py +0 -0
  44. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/cli/utils.py +0 -0
  45. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/frontend/dist/assets/index-8942cb2d.css +0 -0
  46. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/frontend/dist/assets/logo_dark-bc7401f6.svg +0 -0
  47. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/frontend/dist/assets/logo_light-f19fc2ea.svg +0 -0
  48. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/frontend/dist/favicon.svg +0 -0
  49. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/haystack/__init__.py +0 -0
  50. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/input_widget.py +0 -0
  51. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/langchain/__init__.py +0 -0
  52. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/langflow/__init__.py +0 -0
  53. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/llama_index/__init__.py +0 -0
  54. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/logger.py +0 -0
  55. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/markdown.py +0 -0
  56. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/__init__.py +0 -0
  57. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/config.py +0 -0
  58. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/providers/__init__.py +0 -0
  59. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/playground/providers/vertexai.py +0 -0
  60. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/py.typed +0 -0
  61. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/secret.py +0 -0
  62. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/sync.py +0 -0
  63. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/telemetry.py +0 -0
  64. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/utils.py +0 -0
  65. {chainlit-0.7.700 → chainlit-1.0.0rc1}/chainlit/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 0.7.700
3
+ Version: 1.0.0rc1
4
4
  Summary: A faster way to build chatbot UIs.
5
5
  Home-page: https://github.com/Chainlit/chainlit
6
6
  License: Apache-2.0 license
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Requires-Dist: aiofiles (>=23.1.0,<24.0.0)
16
16
  Requires-Dist: asyncer (>=0.0.2,<0.0.3)
17
+ Requires-Dist: chainlit_client (==0.1.0rc5)
17
18
  Requires-Dist: click (>=8.1.3,<9.0.0)
18
19
  Requires-Dist: dataclasses_json (>=0.5.7,<0.6.0)
19
20
  Requires-Dist: fastapi (>=0.100,<0.101)
@@ -46,13 +47,7 @@ Description-Content-Type: text/markdown
46
47
 
47
48
  Chainlit is an open-source async Python framework that makes it incredibly fast to build Chat GPT like applications with your **own business logic and data**.
48
49
 
49
- Key features:
50
-
51
- - [💬 Multi Modal chats](https://docs.chainlit.io/chat-experience/elements)
52
- - [💭 Chain of Thought visualisation](https://docs.chainlit.io/observability-iteration/chain-of-thought)
53
- - [💾 Data persistence + human feedback](https://docs.chainlit.io/chat-data/overview)
54
- - [🛝 In context Prompt Playground](https://docs.chainlit.io/observability-iteration/prompt-playground/overview)
55
- - [👤 Authentication](https://docs.chainlit.io/authentication/overview)
50
+ Contact us [here](https://forms.gle/BX3UNBLmTF75KgZVA) for **Enterprise Support** and to get early access to the **Analytics & Observability** product.
56
51
 
57
52
  https://github.com/Chainlit/chainlit/assets/13104895/8882af90-fdfa-4b24-8200-1ee96c6c7490
58
53
 
@@ -85,11 +80,16 @@ Create a new file `demo.py` with the following code:
85
80
  import chainlit as cl
86
81
 
87
82
 
83
+ @cl.step
84
+ def tool():
85
+ return "Response from the tool!"
86
+
87
+
88
88
  @cl.on_message # this function will be called every time a user inputs a message in the UI
89
89
  async def main(message: cl.Message):
90
90
  """
91
91
  This function is called every time a user inputs a message in the UI.
92
- It sends back an intermediate response from Tool 1, followed by the final answer.
92
+ It sends back an intermediate response from the tool, followed by the final answer.
93
93
 
94
94
  Args:
95
95
  message: The user's message.
@@ -98,15 +98,11 @@ async def main(message: cl.Message):
98
98
  None.
99
99
  """
100
100
 
101
- # Send an intermediate response from Tool 1.
102
- await cl.Message(
103
- author="Tool 1",
104
- content=f"Response from tool1",
105
- parent_id=message.id,
106
- ).send()
101
+ # Call the tool
102
+ tool()
107
103
 
108
104
  # Send the final answer.
109
- await cl.Message(content=f"This is the final answer").send()
105
+ await cl.Message(content="This is the final answer").send()
110
106
  ```
111
107
 
112
108
  Now run it!
@@ -126,7 +122,6 @@ Chainlit is compatible with all Python programs and libraries. That being said,
126
122
  - [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
127
123
  - [Llama Index](https://docs.chainlit.io/integrations/llama-index)
128
124
  - [Haystack](https://docs.chainlit.io/integrations/haystack)
129
- - [Langflow](https://docs.chainlit.io/integrations/langflow)
130
125
 
131
126
  ## 🎨 Custom Frontend
132
127
 
@@ -145,22 +140,8 @@ To build and connect your own frontend, check out our [Custom Frontend Cookbook]
145
140
 
146
141
  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.
147
142
 
148
- ## 🛣 Roadmap
149
-
150
- - [x] Selectable chat profiles (at the beginning of a chat)
151
- - [ ] One click chat sharing
152
- - New clients:
153
- - [x] Custom React app
154
- - [ ] Slack
155
- - [ ] Discord
156
- - [ ] Website embbed
157
-
158
143
  Tell us what you would like to see added in Chainlit using the Github issues or on [Discord](https://discord.gg/k73SQ3FyUh).
159
144
 
160
- ## 🏢 Enterprise support
161
-
162
- For entreprise grade features and self hosting, please visit this [page](https://docs.chainlit.io/cloud/persistence/enterprise) and fill the form.
163
-
164
145
  ## 💁 Contributing
165
146
 
166
147
  As an open-source initiative in a rapidly evolving domain, we welcome contributions, be it through the addition of new features or the improvement of documentation.
@@ -8,13 +8,7 @@
8
8
 
9
9
  Chainlit is an open-source async Python framework that makes it incredibly fast to build Chat GPT like applications with your **own business logic and data**.
10
10
 
11
- Key features:
12
-
13
- - [💬 Multi Modal chats](https://docs.chainlit.io/chat-experience/elements)
14
- - [💭 Chain of Thought visualisation](https://docs.chainlit.io/observability-iteration/chain-of-thought)
15
- - [💾 Data persistence + human feedback](https://docs.chainlit.io/chat-data/overview)
16
- - [🛝 In context Prompt Playground](https://docs.chainlit.io/observability-iteration/prompt-playground/overview)
17
- - [👤 Authentication](https://docs.chainlit.io/authentication/overview)
11
+ Contact us [here](https://forms.gle/BX3UNBLmTF75KgZVA) for **Enterprise Support** and to get early access to the **Analytics & Observability** product.
18
12
 
19
13
  https://github.com/Chainlit/chainlit/assets/13104895/8882af90-fdfa-4b24-8200-1ee96c6c7490
20
14
 
@@ -47,11 +41,16 @@ Create a new file `demo.py` with the following code:
47
41
  import chainlit as cl
48
42
 
49
43
 
44
+ @cl.step
45
+ def tool():
46
+ return "Response from the tool!"
47
+
48
+
50
49
  @cl.on_message # this function will be called every time a user inputs a message in the UI
51
50
  async def main(message: cl.Message):
52
51
  """
53
52
  This function is called every time a user inputs a message in the UI.
54
- It sends back an intermediate response from Tool 1, followed by the final answer.
53
+ It sends back an intermediate response from the tool, followed by the final answer.
55
54
 
56
55
  Args:
57
56
  message: The user's message.
@@ -60,15 +59,11 @@ async def main(message: cl.Message):
60
59
  None.
61
60
  """
62
61
 
63
- # Send an intermediate response from Tool 1.
64
- await cl.Message(
65
- author="Tool 1",
66
- content=f"Response from tool1",
67
- parent_id=message.id,
68
- ).send()
62
+ # Call the tool
63
+ tool()
69
64
 
70
65
  # Send the final answer.
71
- await cl.Message(content=f"This is the final answer").send()
66
+ await cl.Message(content="This is the final answer").send()
72
67
  ```
73
68
 
74
69
  Now run it!
@@ -88,7 +83,6 @@ Chainlit is compatible with all Python programs and libraries. That being said,
88
83
  - [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
89
84
  - [Llama Index](https://docs.chainlit.io/integrations/llama-index)
90
85
  - [Haystack](https://docs.chainlit.io/integrations/haystack)
91
- - [Langflow](https://docs.chainlit.io/integrations/langflow)
92
86
 
93
87
  ## 🎨 Custom Frontend
94
88
 
@@ -107,22 +101,8 @@ To build and connect your own frontend, check out our [Custom Frontend Cookbook]
107
101
 
108
102
  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.
109
103
 
110
- ## 🛣 Roadmap
111
-
112
- - [x] Selectable chat profiles (at the beginning of a chat)
113
- - [ ] One click chat sharing
114
- - New clients:
115
- - [x] Custom React app
116
- - [ ] Slack
117
- - [ ] Discord
118
- - [ ] Website embbed
119
-
120
104
  Tell us what you would like to see added in Chainlit using the Github issues or on [Discord](https://discord.gg/k73SQ3FyUh).
121
105
 
122
- ## 🏢 Enterprise support
123
-
124
- For entreprise grade features and self hosting, please visit this [page](https://docs.chainlit.io/cloud/persistence/enterprise) and fill the form.
125
-
126
106
  ## 💁 Contributing
127
107
 
128
108
  As an open-source initiative in a rapidly evolving domain, we welcome contributions, be it through the addition of new features or the improvement of documentation.
@@ -5,7 +5,7 @@ from dotenv import load_dotenv
5
5
  env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
6
6
 
7
7
  import asyncio
8
- from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
8
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
9
9
 
10
10
  from starlette.datastructures import Headers
11
11
 
@@ -21,8 +21,8 @@ import chainlit.input_widget as input_widget
21
21
  from chainlit.action import Action
22
22
  from chainlit.cache import cache
23
23
  from chainlit.chat_settings import ChatSettings
24
- from chainlit.client.base import AppUser, ConversationDict, PersistedAppUser
25
24
  from chainlit.config import config
25
+ from chainlit.context import context
26
26
  from chainlit.element import (
27
27
  Audio,
28
28
  Avatar,
@@ -46,31 +46,34 @@ from chainlit.message import (
46
46
  Message,
47
47
  )
48
48
  from chainlit.oauth_providers import get_configured_oauth_providers
49
+ from chainlit.step import Step, step
49
50
  from chainlit.sync import make_async, run_sync
50
51
  from chainlit.telemetry import trace
51
- from chainlit.types import ChatProfile, FileSpec
52
+ from chainlit.types import ChatProfile, ThreadDict
53
+ from chainlit.user import PersistedUser, User
52
54
  from chainlit.user_session import user_session
53
55
  from chainlit.utils import make_module_getattr, wrap_user_function
54
56
  from chainlit.version import __version__
57
+ from chainlit_client import ChatGeneration, CompletionGeneration, GenerationMessage
55
58
 
56
59
  if env_found:
57
60
  logger.info("Loaded .env file")
58
61
 
59
62
 
60
63
  @trace
61
- def password_auth_callback(func: Callable[[str, str], Optional[AppUser]]) -> Callable:
64
+ def password_auth_callback(func: Callable[[str, str], Optional[User]]) -> Callable:
62
65
  """
63
66
  Framework agnostic decorator to authenticate the user.
64
67
 
65
68
  Args:
66
- func (Callable[[str, str], Optional[AppUser]]): The authentication callback to execute. Takes the email and password as parameters.
69
+ func (Callable[[str, str], Optional[User]]): The authentication callback to execute. Takes the email and password as parameters.
67
70
 
68
71
  Example:
69
72
  @cl.password_auth_callback
70
- async def password_auth_callback(username: str, password: str) -> Optional[AppUser]:
73
+ async def password_auth_callback(username: str, password: str) -> Optional[User]:
71
74
 
72
75
  Returns:
73
- Callable[[str, str], Optional[AppUser]]: The decorated authentication callback.
76
+ Callable[[str, str], Optional[User]]: The decorated authentication callback.
74
77
  """
75
78
 
76
79
  config.code.password_auth_callback = wrap_user_function(func)
@@ -78,19 +81,19 @@ def password_auth_callback(func: Callable[[str, str], Optional[AppUser]]) -> Cal
78
81
 
79
82
 
80
83
  @trace
81
- def header_auth_callback(func: Callable[[Headers], Optional[AppUser]]) -> Callable:
84
+ def header_auth_callback(func: Callable[[Headers], Optional[User]]) -> Callable:
82
85
  """
83
86
  Framework agnostic decorator to authenticate the user via a header
84
87
 
85
88
  Args:
86
- func (Callable[[Headers], Optional[AppUser]]): The authentication callback to execute.
89
+ func (Callable[[Headers], Optional[User]]): The authentication callback to execute.
87
90
 
88
91
  Example:
89
92
  @cl.header_auth_callback
90
- async def header_auth_callback(headers: Headers) -> Optional[AppUser]:
93
+ async def header_auth_callback(headers: Headers) -> Optional[User]:
91
94
 
92
95
  Returns:
93
- Callable[[Headers], Optional[AppUser]]: The decorated authentication callback.
96
+ Callable[[Headers], Optional[User]]: The decorated authentication callback.
94
97
  """
95
98
 
96
99
  config.code.header_auth_callback = wrap_user_function(func)
@@ -99,20 +102,20 @@ def header_auth_callback(func: Callable[[Headers], Optional[AppUser]]) -> Callab
99
102
 
100
103
  @trace
101
104
  def oauth_callback(
102
- func: Callable[[str, str, Dict[str, str], AppUser], Optional[AppUser]]
105
+ func: Callable[[str, str, Dict[str, str], User], Optional[User]]
103
106
  ) -> Callable:
104
107
  """
105
108
  Framework agnostic decorator to authenticate the user via oauth
106
109
 
107
110
  Args:
108
- func (Callable[[str, str, Dict[str, str], AppUser], Optional[AppUser]]): The authentication callback to execute.
111
+ func (Callable[[str, str, Dict[str, str], User], Optional[User]]): The authentication callback to execute.
109
112
 
110
113
  Example:
111
114
  @cl.oauth_callback
112
- async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: AppUser) -> Optional[AppUser]:
115
+ async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: User) -> Optional[User]:
113
116
 
114
117
  Returns:
115
- Callable[[str, str, Dict[str, str], AppUser], Optional[AppUser]]: The decorated authentication callback.
118
+ Callable[[str, str, Dict[str, str], User], Optional[User]]: The decorated authentication callback.
116
119
  """
117
120
 
118
121
  if len(get_configured_oauth_providers()) == 0:
@@ -158,7 +161,7 @@ def on_chat_start(func: Callable) -> Callable:
158
161
 
159
162
 
160
163
  @trace
161
- def on_chat_resume(func: Callable[[ConversationDict], Any]) -> Callable:
164
+ def on_chat_resume(func: Callable[[ThreadDict], Any]) -> Callable:
162
165
  """
163
166
  Hook to react to resume websocket connection event.
164
167
 
@@ -175,16 +178,16 @@ def on_chat_resume(func: Callable[[ConversationDict], Any]) -> Callable:
175
178
 
176
179
  @trace
177
180
  def set_chat_profiles(
178
- func: Callable[[Optional["AppUser"]], List["ChatProfile"]]
181
+ func: Callable[[Optional["User"]], List["ChatProfile"]]
179
182
  ) -> Callable:
180
183
  """
181
- Programmatic declaration of the available chat profiles (can depend on the AppUser from the session if authentication is setup).
184
+ Programmatic declaration of the available chat profiles (can depend on the User from the session if authentication is setup).
182
185
 
183
186
  Args:
184
- func (Callable[[Optional["AppUser"]], List["ChatProfile"]]): The function declaring the chat profiles.
187
+ func (Callable[[Optional["User"]], List["ChatProfile"]]): The function declaring the chat profiles.
185
188
 
186
189
  Returns:
187
- Callable[[Optional["AppUser"]], List["ChatProfile"]]: The decorated function.
190
+ Callable[[Optional["User"]], List["ChatProfile"]]: The decorated function.
188
191
  """
189
192
 
190
193
  config.code.set_chat_profiles = wrap_user_function(func)
@@ -225,7 +228,7 @@ def author_rename(func: Callable[[str], str]) -> Callable[[str], str]:
225
228
  @trace
226
229
  def on_stop(func: Callable) -> Callable:
227
230
  """
228
- Hook to react to the user stopping a conversation.
231
+ Hook to react to the user stopping a thread.
229
232
 
230
233
  Args:
231
234
  func (Callable[[], Any]): The stop hook to execute.
@@ -291,8 +294,8 @@ __getattr__ = make_module_getattr(
291
294
  __all__ = [
292
295
  "user_session",
293
296
  "Action",
294
- "AppUser",
295
- "PersistedAppUser",
297
+ "User",
298
+ "PersistedUser",
296
299
  "Audio",
297
300
  "Pdf",
298
301
  "Plotly",
@@ -312,6 +315,11 @@ __all__ = [
312
315
  "AskUserMessage",
313
316
  "AskActionMessage",
314
317
  "AskFileMessage",
318
+ "Step",
319
+ "step",
320
+ "ChatGeneration",
321
+ "CompletionGeneration",
322
+ "GenerationMessage",
315
323
  "on_chat_start",
316
324
  "on_chat_end",
317
325
  "on_chat_resume",
@@ -325,6 +333,7 @@ __all__ = [
325
333
  "run_sync",
326
334
  "make_async",
327
335
  "cache",
336
+ "context",
328
337
  "LangchainCallbackHandler",
329
338
  "AsyncLangchainCallbackHandler",
330
339
  "LlamaIndexCallbackHandler",
@@ -3,10 +3,10 @@ from datetime import datetime, timedelta
3
3
  from typing import Any, Dict
4
4
 
5
5
  import jwt
6
- from chainlit.client.cloud import AppUser
7
6
  from chainlit.config import config
8
- from chainlit.data import chainlit_client
7
+ from chainlit.data import get_data_layer
9
8
  from chainlit.oauth_providers import get_configured_oauth_providers
9
+ from chainlit.user import User
10
10
  from fastapi import Depends, HTTPException
11
11
  from fastapi.security import OAuth2PasswordBearer
12
12
 
@@ -47,7 +47,7 @@ def get_configuration():
47
47
  }
48
48
 
49
49
 
50
- def create_jwt(data: AppUser) -> str:
50
+ def create_jwt(data: User) -> str:
51
51
  to_encode = data.to_dict() # type: Dict[str, Any]
52
52
  to_encode.update(
53
53
  {
@@ -67,21 +67,20 @@ async def authenticate_user(token: str = Depends(reuseable_oauth)):
67
67
  options={"verify_signature": True},
68
68
  )
69
69
  del dict["exp"]
70
- app_user = AppUser(**dict)
70
+ user = User(**dict)
71
71
  except Exception as e:
72
72
  raise HTTPException(status_code=401, detail="Invalid authentication token")
73
-
74
- if chainlit_client:
73
+ if data_layer := get_data_layer():
75
74
  try:
76
- persisted_app_user = await chainlit_client.get_app_user(app_user.username)
75
+ persisted_user = await data_layer.get_user(user.identifier)
77
76
  except Exception as e:
78
77
  raise HTTPException(status_code=500, detail=str(e))
79
- if persisted_app_user == None:
78
+ if persisted_user == None:
80
79
  raise HTTPException(status_code=401, detail="User does not exist")
81
80
 
82
- return persisted_app_user
81
+ return persisted_user
83
82
  else:
84
- return app_user
83
+ return user
85
84
 
86
85
 
87
86
  async def get_current_user(token: str = Depends(reuseable_oauth)):
@@ -21,7 +21,7 @@ from chainlit.config import (
21
21
  from chainlit.logger import logger
22
22
  from chainlit.markdown import init_markdown
23
23
  from chainlit.secret import random_secret
24
- from chainlit.server import app, max_message_size, register_wildcard_route_handler
24
+ from chainlit.server import app, register_wildcard_route_handler
25
25
  from chainlit.telemetry import trace_event
26
26
 
27
27
 
@@ -73,7 +73,6 @@ def run_chainlit(target: str):
73
73
  host=host,
74
74
  port=port,
75
75
  log_level=log_level,
76
- ws_max_size=max_message_size,
77
76
  ws_per_message_deflate=ws_per_message_deflate,
78
77
  )
79
78
  server = uvicorn.Server(config)
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import sys
3
3
  from importlib import util
4
+ from pathlib import Path
4
5
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
5
6
 
6
7
  import tomli
@@ -12,8 +13,8 @@ from starlette.datastructures import Headers
12
13
 
13
14
  if TYPE_CHECKING:
14
15
  from chainlit.action import Action
15
- from chainlit.client.base import AppUser, ConversationDict
16
- from chainlit.types import ChatProfile
16
+ from chainlit.types import ChatProfile, ThreadDict
17
+ from chainlit.user import User
17
18
 
18
19
 
19
20
  BACKEND_ROOT = os.path.dirname(__file__)
@@ -23,6 +24,10 @@ PACKAGE_ROOT = os.path.dirname(os.path.dirname(BACKEND_ROOT))
23
24
  # Get the directory the script is running from
24
25
  APP_ROOT = os.getcwd()
25
26
 
27
+ # Create the directory to store the uploaded files
28
+ FILES_DIRECTORY = Path(APP_ROOT) / ".files"
29
+ FILES_DIRECTORY.mkdir(exist_ok=True)
30
+
26
31
  config_dir = os.path.join(APP_ROOT, ".chainlit")
27
32
  config_file = os.path.join(config_dir, "config.toml")
28
33
 
@@ -66,7 +71,7 @@ multi_modal = true
66
71
  # Name of the app and chatbot.
67
72
  name = "Chatbot"
68
73
 
69
- # Show the readme while the conversation is empty.
74
+ # Show the readme while the thread is empty.
70
75
  show_readme_as_default = true
71
76
 
72
77
  # Description of the app and chatbot. This is used for HTML tags.
@@ -190,20 +195,20 @@ class CodeSettings:
190
195
  # Module object loaded from the module_name
191
196
  module: Any = None
192
197
  # Bunch of callbacks defined by the developer
193
- password_auth_callback: Optional[Callable[[str, str], Optional["AppUser"]]] = None
194
- header_auth_callback: Optional[Callable[[Headers], Optional["AppUser"]]] = None
198
+ password_auth_callback: Optional[Callable[[str, str], Optional["User"]]] = None
199
+ header_auth_callback: Optional[Callable[[Headers], Optional["User"]]] = None
195
200
  oauth_callback: Optional[
196
- Callable[[str, str, Dict[str, str], "AppUser"], Optional["AppUser"]]
201
+ Callable[[str, str, Dict[str, str], "User"], Optional["User"]]
197
202
  ] = None
198
203
  on_stop: Optional[Callable[[], Any]] = None
199
204
  on_chat_start: Optional[Callable[[], Any]] = None
200
205
  on_chat_end: Optional[Callable[[], Any]] = None
201
- on_chat_resume: Optional[Callable[["ConversationDict"], Any]] = None
206
+ on_chat_resume: Optional[Callable[["ThreadDict"], Any]] = None
202
207
  on_message: Optional[Callable[[str], Any]] = None
203
208
  author_rename: Optional[Callable[[str], str]] = None
204
209
  on_settings_update: Optional[Callable[[Dict[str, Any]], Any]] = None
205
210
  set_chat_profiles: Optional[
206
- Callable[[Optional["AppUser"]], List["ChatProfile"]]
211
+ Callable[[Optional["User"]], List["ChatProfile"]]
207
212
  ] = None
208
213
 
209
214
 
@@ -229,8 +234,6 @@ class ChainlitConfig:
229
234
  root = APP_ROOT
230
235
  # Chainlit server URL. Used only for cloud features
231
236
  chainlit_server: str
232
- # Whether or not a chainlit api key has been provided
233
- data_persistence: bool
234
237
  # The url of the deployed app. Only set if the app is deployed.
235
238
  chainlit_prod_url = chainlit_prod_url
236
239
 
@@ -341,11 +344,9 @@ def load_config():
341
344
  settings = load_settings()
342
345
 
343
346
  chainlit_server = os.environ.get("CHAINLIT_SERVER", "https://cloud.chainlit.io")
344
- data_persistence = "CHAINLIT_API_KEY" in os.environ
345
347
 
346
348
  config = ChainlitConfig(
347
349
  chainlit_server=chainlit_server,
348
- data_persistence=data_persistence,
349
350
  chainlit_prod_url=chainlit_prod_url,
350
351
  run=RunSettings(),
351
352
  **settings,
@@ -7,9 +7,8 @@ from chainlit.session import HTTPSession, WebsocketSession
7
7
  from lazify import LazyProxy
8
8
 
9
9
  if TYPE_CHECKING:
10
- from chainlit.client.cloud import AppUser, PersistedAppUser
11
10
  from chainlit.emitter import BaseChainlitEmitter
12
- from chainlit.message import Message
11
+ from chainlit.user import PersistedUser, User
13
12
 
14
13
 
15
14
  class ChainlitContextException(Exception):
@@ -22,6 +21,11 @@ class ChainlitContext:
22
21
  emitter: "BaseChainlitEmitter"
23
22
  session: Union["HTTPSession", "WebsocketSession"]
24
23
 
24
+ @property
25
+ def current_step(self):
26
+ if self.session.active_steps:
27
+ return self.session.active_steps[-1]
28
+
25
29
  def __init__(self, session: Union["HTTPSession", "WebsocketSession"]):
26
30
  from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter
27
31
 
@@ -47,7 +51,7 @@ def init_ws_context(session_or_sid: Union[WebsocketSession, str]) -> ChainlitCon
47
51
 
48
52
 
49
53
  def init_http_context(
50
- user: Optional[Union["AppUser", "PersistedAppUser"]] = None,
54
+ user: Optional[Union["User", "PersistedUser"]] = None,
51
55
  auth_token: Optional[str] = None,
52
56
  user_env: Optional[Dict[str, str]] = None,
53
57
  ) -> ChainlitContext: