chainlit 2.0rc1__py3-none-any.whl → 2.0.2__py3-none-any.whl

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 (52) hide show
  1. chainlit/__init__.py +47 -57
  2. chainlit/action.py +8 -8
  3. chainlit/auth/__init__.py +1 -1
  4. chainlit/auth/cookie.py +7 -9
  5. chainlit/auth/jwt.py +5 -3
  6. chainlit/callbacks.py +1 -1
  7. chainlit/config.py +8 -59
  8. chainlit/copilot/dist/index.js +8319 -1019
  9. chainlit/data/__init__.py +71 -2
  10. chainlit/data/chainlit_data_layer.py +608 -0
  11. chainlit/data/literalai.py +1 -1
  12. chainlit/data/sql_alchemy.py +26 -2
  13. chainlit/data/storage_clients/azure_blob.py +89 -0
  14. chainlit/data/storage_clients/base.py +10 -0
  15. chainlit/data/storage_clients/gcs.py +88 -0
  16. chainlit/data/storage_clients/s3.py +42 -4
  17. chainlit/element.py +7 -4
  18. chainlit/emitter.py +9 -14
  19. chainlit/frontend/dist/assets/{DailyMotion-C-_sjrtO.js → DailyMotion-DFvM941y.js} +1 -1
  20. chainlit/frontend/dist/assets/Dataframe-CA6SlUSB.js +22 -0
  21. chainlit/frontend/dist/assets/{Facebook-bB34P03l.js → Facebook-BM4MwXR1.js} +1 -1
  22. chainlit/frontend/dist/assets/{FilePlayer-BWgqGrXv.js → FilePlayer-CfjB8iXr.js} +1 -1
  23. chainlit/frontend/dist/assets/{Kaltura-OY4P9Ofd.js → Kaltura-Bg-U6Xkz.js} +1 -1
  24. chainlit/frontend/dist/assets/{Mixcloud-9CtT8w5Y.js → Mixcloud-xJrfoMTv.js} +1 -1
  25. chainlit/frontend/dist/assets/{Mux-BH9A0qEi.js → Mux-CKnKDBmk.js} +1 -1
  26. chainlit/frontend/dist/assets/{Preview-Og00EJ05.js → Preview-DwHPdmIg.js} +1 -1
  27. chainlit/frontend/dist/assets/{SoundCloud-D7resGfn.js → SoundCloud-Crd5dwXV.js} +1 -1
  28. chainlit/frontend/dist/assets/{Streamable-6f_6bYz1.js → Streamable-Dq0c8lyx.js} +1 -1
  29. chainlit/frontend/dist/assets/{Twitch-BZJl3peM.js → Twitch-DIDvP936.js} +1 -1
  30. chainlit/frontend/dist/assets/{Vidyard-B7tv4b8_.js → Vidyard-B1dz9WN4.js} +1 -1
  31. chainlit/frontend/dist/assets/{Vimeo-F-eA4zQI.js → Vimeo-22Su6q2w.js} +1 -1
  32. chainlit/frontend/dist/assets/Wistia-C7adXRjN.js +1 -0
  33. chainlit/frontend/dist/assets/{YouTube-aFdJGjI1.js → YouTube-Dt4UMtQI.js} +1 -1
  34. chainlit/frontend/dist/assets/index-DbdLVHtZ.js +8665 -0
  35. chainlit/frontend/dist/assets/index-g8LTJwwr.css +1 -0
  36. chainlit/frontend/dist/assets/{react-plotly-DoUJXMgz.js → react-plotly-DvpXYYRJ.js} +1 -1
  37. chainlit/frontend/dist/index.html +2 -2
  38. chainlit/message.py +1 -3
  39. chainlit/server.py +297 -78
  40. chainlit/session.py +9 -0
  41. chainlit/socket.py +5 -53
  42. chainlit/step.py +0 -1
  43. chainlit/translations/en-US.json +1 -1
  44. chainlit/types.py +17 -3
  45. chainlit/user_session.py +1 -0
  46. {chainlit-2.0rc1.dist-info → chainlit-2.0.2.dist-info}/METADATA +4 -35
  47. {chainlit-2.0rc1.dist-info → chainlit-2.0.2.dist-info}/RECORD +49 -45
  48. chainlit/frontend/dist/assets/Wistia-Dhxhn3IB.js +0 -1
  49. chainlit/frontend/dist/assets/index-Ba33_hdJ.js +0 -1091
  50. chainlit/frontend/dist/assets/index-CwmincdQ.css +0 -1
  51. {chainlit-2.0rc1.dist-info → chainlit-2.0.2.dist-info}/WHEEL +0 -0
  52. {chainlit-2.0rc1.dist-info → chainlit-2.0.2.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py CHANGED
@@ -25,7 +25,7 @@ from chainlit.chat_settings import ChatSettings
25
25
  from chainlit.context import context
26
26
  from chainlit.element import (
27
27
  Audio,
28
- Component,
28
+ CustomElement,
29
29
  Dataframe,
30
30
  File,
31
31
  Image,
@@ -117,83 +117,73 @@ __getattr__ = make_module_getattr(
117
117
  )
118
118
 
119
119
  __all__ = [
120
- "__version__",
120
+ "Action",
121
+ "AskActionMessage",
122
+ "AskFileMessage",
123
+ "AskUserMessage",
124
+ "AsyncLangchainCallbackHandler",
125
+ "Audio",
126
+ "ChatGeneration",
121
127
  "ChatProfile",
122
- "Starter",
123
- "user_session",
124
- "chat_context",
128
+ "ChatSettings",
129
+ "CompletionGeneration",
125
130
  "CopilotFunction",
131
+ "CustomElement",
132
+ "Dataframe",
133
+ "ErrorMessage",
134
+ "File",
135
+ "GenerationMessage",
136
+ "HaystackAgentCallbackHandler",
137
+ "Image",
126
138
  "InputAudioChunk",
139
+ "LangchainCallbackHandler",
140
+ "LlamaIndexCallbackHandler",
141
+ "Message",
127
142
  "OutputAudioChunk",
128
- "Action",
129
- "User",
130
- "PersistedUser",
131
- "Audio",
132
143
  "Pdf",
144
+ "PersistedUser",
133
145
  "Plotly",
134
- "Image",
135
- "Text",
136
- "Component",
137
- "Dataframe",
138
146
  "Pyplot",
139
- "File",
147
+ "Starter",
148
+ "Step",
140
149
  "Task",
141
150
  "TaskList",
142
151
  "TaskStatus",
152
+ "Text",
153
+ "User",
143
154
  "Video",
144
- "ChatSettings",
145
- "input_widget",
146
- "Message",
147
- "ErrorMessage",
148
- "AskUserMessage",
149
- "AskActionMessage",
150
- "AskFileMessage",
151
- "Step",
152
- "step",
153
- "ChatGeneration",
154
- "CompletionGeneration",
155
- "GenerationMessage",
156
- "on_logout",
157
- "on_window_message",
158
- "send_window_message",
159
- "on_chat_start",
160
- "on_chat_end",
161
- "on_chat_resume",
162
- "on_stop",
155
+ "__version__",
163
156
  "action_callback",
164
157
  "author_rename",
165
- "on_settings_update",
166
- "password_auth_callback",
167
- "header_auth_callback",
168
- "sleep",
169
- "run_sync",
170
- "make_async",
171
158
  "cache",
159
+ "chat_context",
172
160
  "context",
173
- "LangchainCallbackHandler",
174
- "AsyncLangchainCallbackHandler",
175
- "LlamaIndexCallbackHandler",
176
- "HaystackAgentCallbackHandler",
177
- "instrument_openai",
178
- "instrument_mistralai",
179
- "password_auth_callback",
161
+ "data_layer",
180
162
  "header_auth_callback",
163
+ "input_widget",
164
+ "instrument_mistralai",
165
+ "instrument_openai",
166
+ "make_async",
181
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",
182
174
  "on_logout",
183
175
  "on_message",
184
- "on_chat_start",
185
- "on_chat_resume",
176
+ "on_settings_update",
177
+ "on_stop",
178
+ "on_window_message",
179
+ "password_auth_callback",
180
+ "run_sync",
181
+ "send_window_message",
186
182
  "set_chat_profiles",
187
183
  "set_starters",
188
- "on_chat_end",
189
- "on_audio_start",
190
- "on_audio_chunk",
191
- "on_audio_end",
192
- "author_rename",
193
- "on_stop",
194
- "action_callback",
195
- "on_settings_update",
196
- "data_layer",
184
+ "sleep",
185
+ "step",
186
+ "user_session",
197
187
  ]
198
188
 
199
189
 
chainlit/action.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import uuid
2
- from typing import Optional
2
+ from typing import Dict, Optional
3
3
 
4
4
  from dataclasses_json import DataClassJsonMixin
5
5
  from pydantic import Field
@@ -13,18 +13,18 @@ from chainlit.telemetry import trace_event
13
13
  class Action(DataClassJsonMixin):
14
14
  # Name of the action, this should be used in the action_callback
15
15
  name: str
16
- # The value associated with the action. This is useful to differentiate between multiple actions with the same name.
17
- value: str
18
- # 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.
19
19
  label: str = ""
20
- # The description of the action. This is what the user will see when they hover the action.
21
- 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
22
24
  # This should not be set manually, only used internally.
23
25
  forId: Optional[str] = None
24
26
  # The ID of the action
25
27
  id: str = Field(default_factory=lambda: str(uuid.uuid4()))
26
- # Show the action in a drawer menu
27
- collapsed: bool = False
28
28
 
29
29
  def __post_init__(self) -> None:
30
30
  trace_event(f"init {self.__class__.__name__}")
chainlit/auth/__init__.py CHANGED
@@ -38,10 +38,10 @@ def get_configuration():
38
38
  "requireLogin": require_login(),
39
39
  "passwordAuth": config.code.password_auth_callback is not None,
40
40
  "headerAuth": config.code.header_auth_callback is not None,
41
- "cookieAuth": config.project.cookie_auth,
42
41
  "oauthProviders": (
43
42
  get_configured_oauth_providers() if is_oauth_enabled() else []
44
43
  ),
44
+ "default_theme": config.ui.default_theme,
45
45
  }
46
46
 
47
47
 
chainlit/auth/cookie.py CHANGED
@@ -13,14 +13,13 @@ _cookie_samesite = cast(
13
13
  os.environ.get("CHAINLIT_COOKIE_SAMESITE", "lax"),
14
14
  )
15
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'."
16
+ assert _cookie_samesite in [
17
+ "lax",
18
+ "strict",
19
+ "none",
20
+ ], (
21
+ "Invalid value for CHAINLIT_COOKIE_SAMESITE. Must be one of 'lax', 'strict' or 'none'."
22
+ )
24
23
  _cookie_secure = _cookie_samesite == "none"
25
24
 
26
25
  _auth_cookie_lifetime = 60 * 60 # 1 hour
@@ -88,7 +87,6 @@ def set_auth_cookie(response: Response, token: str):
88
87
  secure=_cookie_secure,
89
88
  samesite=_cookie_samesite,
90
89
  max_age=_auth_cookie_lifetime,
91
- path="/", # Why is path set here and not below?
92
90
  )
93
91
 
94
92
 
chainlit/auth/jwt.py CHANGED
@@ -1,5 +1,5 @@
1
- import datetime
2
1
  import os
2
+ from datetime import datetime, timedelta, timezone
3
3
  from typing import Any, Dict, Optional
4
4
 
5
5
  import jwt as pyjwt
@@ -16,10 +16,12 @@ def create_jwt(data: User) -> str:
16
16
  to_encode: Dict[str, Any] = data.to_dict()
17
17
  to_encode.update(
18
18
  {
19
- "exp": datetime.datetime.utcnow()
20
- + datetime.timedelta(seconds=config.project.user_session_timeout),
19
+ "exp": datetime.now(timezone.utc)
20
+ + timedelta(seconds=config.project.user_session_timeout),
21
+ "iat": datetime.now(timezone.utc), # Add issued at time
21
22
  }
22
23
  )
24
+
23
25
  secret = get_jwt_secret()
24
26
  assert secret
25
27
  encoded_jwt = pyjwt.encode(to_encode, secret, algorithm="HS256")
chainlit/callbacks.py CHANGED
@@ -325,7 +325,7 @@ def action_callback(name: str) -> Callable:
325
325
  """
326
326
 
327
327
  def decorator(func: Callable[[Action], Any]):
328
- config.code.action_callbacks[name] = wrap_user_function(func, with_task=True)
328
+ config.code.action_callbacks[name] = wrap_user_function(func, with_task=False)
329
329
  return func
330
330
 
331
331
  return decorator
chainlit/config.py CHANGED
@@ -55,6 +55,7 @@ FILES_DIRECTORY = Path(APP_ROOT) / ".files"
55
55
  FILES_DIRECTORY.mkdir(exist_ok=True)
56
56
 
57
57
  config_dir = os.path.join(APP_ROOT, ".chainlit")
58
+ public_dir = os.path.join(APP_ROOT, "public")
58
59
  config_file = os.path.join(config_dir, "config.toml")
59
60
  config_translation_dir = os.path.join(config_dir, "translations")
60
61
 
@@ -79,9 +80,6 @@ cache = false
79
80
  # Authorized origins
80
81
  allow_origins = ["*"]
81
82
 
82
- # Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
83
- # follow_symlink = false
84
-
85
83
  [features]
86
84
  # Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
87
85
  unsafe_allow_html = false
@@ -95,9 +93,6 @@ auto_tag_thread = true
95
93
  # Allow users to edit their own messages
96
94
  edit_message = true
97
95
 
98
- # Use httponly cookie for client->server authentication, required to be able to use file upload and elements.
99
- cookie_auth = true
100
-
101
96
  # Authorize users to spontaneously upload files with messages
102
97
  [features.spontaneous_file_upload]
103
98
  enabled = true
@@ -113,12 +108,13 @@ cookie_auth = true
113
108
  # Name of the assistant.
114
109
  name = "Assistant"
115
110
 
111
+ # default_theme = "dark"
112
+
113
+ # layout = "wide"
114
+
116
115
  # Description of the assistant. This is used for HTML tags.
117
116
  # description = ""
118
117
 
119
- # Large size content are by default collapsed for a cleaner ui
120
- default_collapse_content = true
121
-
122
118
  # Chain of Thought (CoT) display mode. Can be "hidden", "tool_call" or "full".
123
119
  cot = "full"
124
120
 
@@ -133,9 +129,6 @@ cot = "full"
133
129
  # The Javascript file can be served from the public directory.
134
130
  # custom_js = "/public/test.js"
135
131
 
136
- # Specify a custom font url.
137
- # custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
138
-
139
132
  # Specify a custom meta image url.
140
133
  # custom_meta_image_url = "https://chainlit-cloud.s3.eu-west-3.amazonaws.com/logo/chainlit_banner.png"
141
134
 
@@ -144,36 +137,6 @@ cot = "full"
144
137
  # Be careful: If this is a relative path, it should not start with a slash.
145
138
  # custom_build = "./public/build"
146
139
 
147
- [UI.theme]
148
- default = "dark"
149
- #layout = "wide"
150
- #font_family = "Inter, sans-serif"
151
- # Override default MUI light theme. (Check theme.ts)
152
- [UI.theme.light]
153
- #background = "#FAFAFA"
154
- #paper = "#FFFFFF"
155
-
156
- [UI.theme.light.primary]
157
- #main = "#F80061"
158
- #dark = "#980039"
159
- #light = "#FFE7EB"
160
- [UI.theme.light.text]
161
- #primary = "#212121"
162
- #secondary = "#616161"
163
-
164
- # Override default MUI dark theme. (Check theme.ts)
165
- [UI.theme.dark]
166
- #background = "#FAFAFA"
167
- #paper = "#FFFFFF"
168
-
169
- [UI.theme.dark.primary]
170
- #main = "#F80061"
171
- #dark = "#980039"
172
- #light = "#FFE7EB"
173
- [UI.theme.dark.text]
174
- #primary = "#EEEEEE"
175
- #secondary = "#BDBDBD"
176
-
177
140
  [meta]
178
141
  generated_by = "{__version__}"
179
142
  """
@@ -221,15 +184,6 @@ class Palette(DataClassJsonMixin):
221
184
  text: Optional[TextOptions] = None
222
185
 
223
186
 
224
- @dataclass()
225
- class Theme(DataClassJsonMixin):
226
- font_family: Optional[str] = None
227
- default: Optional[Literal["light", "dark"]] = "dark"
228
- layout: Optional[Literal["default", "wide"]] = "default"
229
- light: Optional[Palette] = None
230
- dark: Optional[Palette] = None
231
-
232
-
233
187
  @dataclass
234
188
  class SpontaneousFileUploadFeature(DataClassJsonMixin):
235
189
  enabled: Optional[bool] = None
@@ -259,14 +213,13 @@ class UISettings(DataClassJsonMixin):
259
213
  name: str
260
214
  description: str = ""
261
215
  cot: Literal["hidden", "tool_call", "full"] = "full"
262
- # Large size content are by default collapsed for a cleaner ui
263
- default_collapse_content: bool = True
216
+ font_family: Optional[str] = None
217
+ default_theme: Optional[Literal["light", "dark"]] = "dark"
218
+ layout: Optional[Literal["default", "wide"]] = "default"
264
219
  github: Optional[str] = None
265
- theme: Optional[Theme] = None
266
220
  # Optional custom CSS file that allows you to customize the UI
267
221
  custom_css: Optional[str] = None
268
222
  custom_js: Optional[str] = None
269
- custom_font: Optional[str] = None
270
223
  # Optional custom meta tag for image preview
271
224
  custom_meta_image_url: Optional[str] = None
272
225
  # Optional custom build directory for the frontend
@@ -328,10 +281,6 @@ class ProjectSettings(DataClassJsonMixin):
328
281
  user_session_timeout: int = 1296000 # 15 days
329
282
  # Enable third parties caching (e.g LangChain cache)
330
283
  cache: bool = False
331
- # Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
332
- follow_symlink: bool = False
333
- # Use httponly cookie for client->server authentication, required to be able to use file upload and elements.
334
- cookie_auth: bool = True
335
284
 
336
285
 
337
286
  @dataclass()