chainlit 2.0.0__py3-none-any.whl → 2.0.dev0__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.
- chainlit/__init__.py +57 -56
- chainlit/action.py +10 -12
- chainlit/{auth/__init__.py → auth.py} +34 -26
- chainlit/cache.py +6 -4
- chainlit/callbacks.py +7 -52
- chainlit/chat_context.py +2 -2
- chainlit/chat_settings.py +1 -3
- chainlit/cli/__init__.py +2 -15
- chainlit/config.py +70 -41
- chainlit/context.py +9 -8
- chainlit/copilot/dist/index.js +874 -8533
- chainlit/data/__init__.py +8 -96
- chainlit/data/acl.py +2 -3
- chainlit/data/base.py +15 -1
- chainlit/data/dynamodb.py +4 -7
- chainlit/data/literalai.py +6 -4
- chainlit/data/sql_alchemy.py +9 -10
- chainlit/data/{storage_clients/azure.py → storage_clients.py} +33 -2
- chainlit/discord/__init__.py +4 -4
- chainlit/discord/app.py +1 -2
- chainlit/element.py +9 -41
- chainlit/emitter.py +21 -17
- chainlit/frontend/dist/assets/DailyMotion-b4b7af47.js +1 -0
- chainlit/frontend/dist/assets/Facebook-572972a0.js +1 -0
- chainlit/frontend/dist/assets/FilePlayer-85c69ca8.js +1 -0
- chainlit/frontend/dist/assets/Kaltura-dfc24672.js +1 -0
- chainlit/frontend/dist/assets/Mixcloud-705011f4.js +1 -0
- chainlit/frontend/dist/assets/Mux-4201a9e6.js +1 -0
- chainlit/frontend/dist/assets/Preview-23ba40a6.js +1 -0
- chainlit/frontend/dist/assets/SoundCloud-1a582d51.js +1 -0
- chainlit/frontend/dist/assets/Streamable-5017c4ba.js +1 -0
- chainlit/frontend/dist/assets/Twitch-bb2de2fa.js +1 -0
- chainlit/frontend/dist/assets/Vidyard-54e269b1.js +1 -0
- chainlit/frontend/dist/assets/Vimeo-d92c37dd.js +1 -0
- chainlit/frontend/dist/assets/Wistia-25a1363b.js +1 -0
- chainlit/frontend/dist/assets/YouTube-616e8cb7.js +1 -0
- chainlit/frontend/dist/assets/index-aaf974a9.css +1 -0
- chainlit/frontend/dist/assets/index-f5df2072.js +1027 -0
- chainlit/frontend/dist/assets/{react-plotly-BpxUS-ab.js → react-plotly-f0315f86.js} +94 -94
- chainlit/frontend/dist/index.html +3 -2
- chainlit/haystack/callbacks.py +4 -5
- chainlit/input_widget.py +4 -6
- chainlit/langchain/callbacks.py +47 -56
- chainlit/langflow/__init__.py +0 -1
- chainlit/llama_index/callbacks.py +7 -7
- chainlit/message.py +10 -8
- chainlit/mistralai/__init__.py +2 -3
- chainlit/oauth_providers.py +12 -113
- chainlit/openai/__init__.py +7 -6
- chainlit/secret.py +1 -1
- chainlit/server.py +181 -491
- chainlit/session.py +5 -7
- chainlit/slack/__init__.py +3 -3
- chainlit/slack/app.py +2 -3
- chainlit/socket.py +103 -78
- chainlit/step.py +29 -21
- chainlit/sync.py +1 -2
- chainlit/teams/__init__.py +3 -3
- chainlit/teams/app.py +0 -1
- chainlit/types.py +4 -20
- chainlit/user.py +1 -2
- chainlit/utils.py +2 -3
- chainlit/version.py +2 -3
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/METADATA +39 -27
- chainlit-2.0.dev0.dist-info/RECORD +96 -0
- chainlit/auth/cookie.py +0 -123
- chainlit/auth/jwt.py +0 -37
- chainlit/data/chainlit_data_layer.py +0 -584
- chainlit/data/storage_clients/__init__.py +0 -0
- chainlit/data/storage_clients/azure_blob.py +0 -80
- chainlit/data/storage_clients/base.py +0 -22
- chainlit/data/storage_clients/gcs.py +0 -78
- chainlit/data/storage_clients/s3.py +0 -49
- chainlit/frontend/dist/assets/DailyMotion-DgRzV5GZ.js +0 -1
- chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +0 -22
- chainlit/frontend/dist/assets/Facebook-C0vx6HWv.js +0 -1
- chainlit/frontend/dist/assets/FilePlayer-CdhzeHPP.js +0 -1
- chainlit/frontend/dist/assets/Kaltura-5iVmeUct.js +0 -1
- chainlit/frontend/dist/assets/Mixcloud-C2zi77Ex.js +0 -1
- chainlit/frontend/dist/assets/Mux-Vkebogdf.js +0 -1
- chainlit/frontend/dist/assets/Preview-DwY_sEIl.js +0 -1
- chainlit/frontend/dist/assets/SoundCloud-CREBXAWo.js +0 -1
- chainlit/frontend/dist/assets/Streamable-B5Lu25uy.js +0 -1
- chainlit/frontend/dist/assets/Twitch-y9iKCcM1.js +0 -1
- chainlit/frontend/dist/assets/Vidyard-ClYvcuEu.js +0 -1
- chainlit/frontend/dist/assets/Vimeo-D6HvM2jt.js +0 -1
- chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +0 -1
- chainlit/frontend/dist/assets/YouTube-D10tR6CJ.js +0 -1
- chainlit/frontend/dist/assets/index-CI4qFOt5.js +0 -8665
- chainlit/frontend/dist/assets/index-CrrqM0nZ.css +0 -1
- chainlit/translations/nl-NL.json +0 -229
- chainlit-2.0.0.dist-info/RECORD +0 -106
- /chainlit/copilot/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
- /chainlit/copilot/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/WHEEL +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/entry_points.txt +0 -0
chainlit/config.py
CHANGED
|
@@ -17,30 +17,22 @@ from typing import (
|
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
import tomli
|
|
20
|
-
from dataclasses_json import DataClassJsonMixin
|
|
21
|
-
from pydantic import Field
|
|
22
|
-
from pydantic.dataclasses import dataclass
|
|
23
|
-
from starlette.datastructures import Headers
|
|
24
|
-
|
|
25
|
-
from chainlit.data.base import BaseDataLayer
|
|
26
20
|
from chainlit.logger import logger
|
|
27
21
|
from chainlit.translations import lint_translation_json
|
|
28
22
|
from chainlit.version import __version__
|
|
23
|
+
from dataclasses_json import DataClassJsonMixin
|
|
24
|
+
from pydantic.dataclasses import Field, dataclass
|
|
25
|
+
from starlette.datastructures import Headers
|
|
29
26
|
|
|
30
27
|
from ._utils import is_path_inside
|
|
31
28
|
|
|
32
29
|
if TYPE_CHECKING:
|
|
33
|
-
from fastapi import Request, Response
|
|
34
|
-
|
|
35
30
|
from chainlit.action import Action
|
|
36
31
|
from chainlit.message import Message
|
|
37
|
-
from chainlit.types import
|
|
32
|
+
from chainlit.types import InputAudioChunk, ChatProfile, Starter, ThreadDict
|
|
38
33
|
from chainlit.user import User
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# within `typing.Callable`, alias to `Any` as Pydantic does not perform validation
|
|
42
|
-
# of callable argument/return types anyway.
|
|
43
|
-
Request = Response = Action = Message = ChatProfile = InputAudioChunk = Starter = ThreadDict = User = Any # fmt: off
|
|
34
|
+
from fastapi import Request, Response
|
|
35
|
+
|
|
44
36
|
|
|
45
37
|
BACKEND_ROOT = os.path.dirname(__file__)
|
|
46
38
|
PACKAGE_ROOT = os.path.dirname(os.path.dirname(BACKEND_ROOT))
|
|
@@ -55,7 +47,6 @@ FILES_DIRECTORY = Path(APP_ROOT) / ".files"
|
|
|
55
47
|
FILES_DIRECTORY.mkdir(exist_ok=True)
|
|
56
48
|
|
|
57
49
|
config_dir = os.path.join(APP_ROOT, ".chainlit")
|
|
58
|
-
public_dir = os.path.join(APP_ROOT, "public")
|
|
59
50
|
config_file = os.path.join(config_dir, "config.toml")
|
|
60
51
|
config_translation_dir = os.path.join(config_dir, "translations")
|
|
61
52
|
|
|
@@ -71,15 +62,15 @@ user_env = []
|
|
|
71
62
|
# Duration (in seconds) during which the session is saved when the connection is lost
|
|
72
63
|
session_timeout = 3600
|
|
73
64
|
|
|
74
|
-
# Duration (in seconds) of the user session expiry
|
|
75
|
-
user_session_timeout = 1296000 # 15 days
|
|
76
|
-
|
|
77
65
|
# Enable third parties caching (e.g LangChain cache)
|
|
78
66
|
cache = false
|
|
79
67
|
|
|
80
68
|
# Authorized origins
|
|
81
69
|
allow_origins = ["*"]
|
|
82
70
|
|
|
71
|
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
|
72
|
+
# follow_symlink = false
|
|
73
|
+
|
|
83
74
|
[features]
|
|
84
75
|
# 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)
|
|
85
76
|
unsafe_allow_html = false
|
|
@@ -108,13 +99,12 @@ edit_message = true
|
|
|
108
99
|
# Name of the assistant.
|
|
109
100
|
name = "Assistant"
|
|
110
101
|
|
|
111
|
-
# default_theme = "dark"
|
|
112
|
-
|
|
113
|
-
# layout = "wide"
|
|
114
|
-
|
|
115
102
|
# Description of the assistant. This is used for HTML tags.
|
|
116
103
|
# description = ""
|
|
117
104
|
|
|
105
|
+
# Large size content are by default collapsed for a cleaner ui
|
|
106
|
+
default_collapse_content = true
|
|
107
|
+
|
|
118
108
|
# Chain of Thought (CoT) display mode. Can be "hidden", "tool_call" or "full".
|
|
119
109
|
cot = "full"
|
|
120
110
|
|
|
@@ -129,6 +119,9 @@ cot = "full"
|
|
|
129
119
|
# The Javascript file can be served from the public directory.
|
|
130
120
|
# custom_js = "/public/test.js"
|
|
131
121
|
|
|
122
|
+
# Specify a custom font url.
|
|
123
|
+
# custom_font = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
|
|
124
|
+
|
|
132
125
|
# Specify a custom meta image url.
|
|
133
126
|
# custom_meta_image_url = "https://chainlit-cloud.s3.eu-west-3.amazonaws.com/logo/chainlit_banner.png"
|
|
134
127
|
|
|
@@ -137,6 +130,36 @@ cot = "full"
|
|
|
137
130
|
# Be careful: If this is a relative path, it should not start with a slash.
|
|
138
131
|
# custom_build = "./public/build"
|
|
139
132
|
|
|
133
|
+
[UI.theme]
|
|
134
|
+
default = "dark"
|
|
135
|
+
#layout = "wide"
|
|
136
|
+
#font_family = "Inter, sans-serif"
|
|
137
|
+
# Override default MUI light theme. (Check theme.ts)
|
|
138
|
+
[UI.theme.light]
|
|
139
|
+
#background = "#FAFAFA"
|
|
140
|
+
#paper = "#FFFFFF"
|
|
141
|
+
|
|
142
|
+
[UI.theme.light.primary]
|
|
143
|
+
#main = "#F80061"
|
|
144
|
+
#dark = "#980039"
|
|
145
|
+
#light = "#FFE7EB"
|
|
146
|
+
[UI.theme.light.text]
|
|
147
|
+
#primary = "#212121"
|
|
148
|
+
#secondary = "#616161"
|
|
149
|
+
|
|
150
|
+
# Override default MUI dark theme. (Check theme.ts)
|
|
151
|
+
[UI.theme.dark]
|
|
152
|
+
#background = "#FAFAFA"
|
|
153
|
+
#paper = "#FFFFFF"
|
|
154
|
+
|
|
155
|
+
[UI.theme.dark.primary]
|
|
156
|
+
#main = "#F80061"
|
|
157
|
+
#dark = "#980039"
|
|
158
|
+
#light = "#FFE7EB"
|
|
159
|
+
[UI.theme.dark.text]
|
|
160
|
+
#primary = "#EEEEEE"
|
|
161
|
+
#secondary = "#BDBDBD"
|
|
162
|
+
|
|
140
163
|
[meta]
|
|
141
164
|
generated_by = "{__version__}"
|
|
142
165
|
"""
|
|
@@ -184,6 +207,15 @@ class Palette(DataClassJsonMixin):
|
|
|
184
207
|
text: Optional[TextOptions] = None
|
|
185
208
|
|
|
186
209
|
|
|
210
|
+
@dataclass()
|
|
211
|
+
class Theme(DataClassJsonMixin):
|
|
212
|
+
font_family: Optional[str] = None
|
|
213
|
+
default: Optional[Literal["light", "dark"]] = "dark"
|
|
214
|
+
layout: Optional[Literal["default", "wide"]] = "default"
|
|
215
|
+
light: Optional[Palette] = None
|
|
216
|
+
dark: Optional[Palette] = None
|
|
217
|
+
|
|
218
|
+
|
|
187
219
|
@dataclass
|
|
188
220
|
class SpontaneousFileUploadFeature(DataClassJsonMixin):
|
|
189
221
|
enabled: Optional[bool] = None
|
|
@@ -213,13 +245,14 @@ class UISettings(DataClassJsonMixin):
|
|
|
213
245
|
name: str
|
|
214
246
|
description: str = ""
|
|
215
247
|
cot: Literal["hidden", "tool_call", "full"] = "full"
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
layout: Optional[Literal["default", "wide"]] = "default"
|
|
248
|
+
# Large size content are by default collapsed for a cleaner ui
|
|
249
|
+
default_collapse_content: bool = True
|
|
219
250
|
github: Optional[str] = None
|
|
251
|
+
theme: Optional[Theme] = None
|
|
220
252
|
# Optional custom CSS file that allows you to customize the UI
|
|
221
253
|
custom_css: Optional[str] = None
|
|
222
254
|
custom_js: Optional[str] = None
|
|
255
|
+
custom_font: Optional[str] = None
|
|
223
256
|
# Optional custom meta tag for image preview
|
|
224
257
|
custom_meta_image_url: Optional[str] = None
|
|
225
258
|
# Optional custom build directory for the frontend
|
|
@@ -236,9 +269,9 @@ class CodeSettings:
|
|
|
236
269
|
password_auth_callback: Optional[
|
|
237
270
|
Callable[[str, str], Awaitable[Optional["User"]]]
|
|
238
271
|
] = None
|
|
239
|
-
header_auth_callback: Optional[
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
header_auth_callback: Optional[
|
|
273
|
+
Callable[[Headers], Awaitable[Optional["User"]]]
|
|
274
|
+
] = None
|
|
242
275
|
oauth_callback: Optional[
|
|
243
276
|
Callable[[str, str, Dict[str, str], "User"], Awaitable[Optional["User"]]]
|
|
244
277
|
] = None
|
|
@@ -248,7 +281,6 @@ class CodeSettings:
|
|
|
248
281
|
on_chat_end: Optional[Callable[[], Any]] = None
|
|
249
282
|
on_chat_resume: Optional[Callable[["ThreadDict"], Any]] = None
|
|
250
283
|
on_message: Optional[Callable[["Message"], Any]] = None
|
|
251
|
-
on_window_message: Optional[Callable[[str], Any]] = None
|
|
252
284
|
on_audio_start: Optional[Callable[[], Any]] = None
|
|
253
285
|
on_audio_chunk: Optional[Callable[["InputAudioChunk"], Any]] = None
|
|
254
286
|
on_audio_end: Optional[Callable[[], Any]] = None
|
|
@@ -258,17 +290,14 @@ class CodeSettings:
|
|
|
258
290
|
set_chat_profiles: Optional[
|
|
259
291
|
Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]
|
|
260
292
|
] = None
|
|
261
|
-
set_starters: Optional[
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
data_layer: Optional[Callable[[], BaseDataLayer]] = None
|
|
293
|
+
set_starters: Optional[
|
|
294
|
+
Callable[[Optional["User"]], Awaitable[List["Starter"]]]
|
|
295
|
+
] = None
|
|
265
296
|
|
|
266
297
|
|
|
267
298
|
@dataclass()
|
|
268
299
|
class ProjectSettings(DataClassJsonMixin):
|
|
269
300
|
allow_origins: List[str] = Field(default_factory=lambda: ["*"])
|
|
270
|
-
# Socket.io client transports option
|
|
271
|
-
transports: Optional[List[str]] = None
|
|
272
301
|
enable_telemetry: bool = True
|
|
273
302
|
# List of environment variables to be provided by each user to use the app. If empty, no environment variables will be asked to the user.
|
|
274
303
|
user_env: Optional[List[str]] = None
|
|
@@ -277,10 +306,10 @@ class ProjectSettings(DataClassJsonMixin):
|
|
|
277
306
|
# Path to the local chat db
|
|
278
307
|
# Duration (in seconds) during which the session is saved when the connection is lost
|
|
279
308
|
session_timeout: int = 3600
|
|
280
|
-
# Duration (in seconds) of the user session expiry
|
|
281
|
-
user_session_timeout: int = 1296000 # 15 days
|
|
282
309
|
# Enable third parties caching (e.g LangChain cache)
|
|
283
310
|
cache: bool = False
|
|
311
|
+
# Follow symlink for asset mount (see https://github.com/Chainlit/chainlit/issues/317)
|
|
312
|
+
follow_symlink: bool = False
|
|
284
313
|
|
|
285
314
|
|
|
286
315
|
@dataclass()
|
|
@@ -361,7 +390,7 @@ def init_config(log=False):
|
|
|
361
390
|
dst = os.path.join(config_translation_dir, file)
|
|
362
391
|
if not os.path.exists(dst):
|
|
363
392
|
src = os.path.join(TRANSLATIONS_DIR, file)
|
|
364
|
-
with open(src, encoding="utf-8") as f:
|
|
393
|
+
with open(src, "r", encoding="utf-8") as f:
|
|
365
394
|
translation = json.load(f)
|
|
366
395
|
with open(dst, "w", encoding="utf-8") as f:
|
|
367
396
|
json.dump(translation, f, indent=4)
|
|
@@ -418,7 +447,7 @@ def load_settings():
|
|
|
418
447
|
|
|
419
448
|
if not meta or meta.get("generated_by") <= "0.3.0":
|
|
420
449
|
raise ValueError(
|
|
421
|
-
|
|
450
|
+
"Your config file is outdated. Please delete it and restart the app to regenerate it."
|
|
422
451
|
)
|
|
423
452
|
|
|
424
453
|
lc_cache_path = os.path.join(config_dir, ".langchain.db")
|
|
@@ -476,7 +505,7 @@ def load_config():
|
|
|
476
505
|
def lint_translations():
|
|
477
506
|
# Load the ground truth (en-US.json file from chainlit source code)
|
|
478
507
|
src = os.path.join(TRANSLATIONS_DIR, "en-US.json")
|
|
479
|
-
with open(src, encoding="utf-8") as f:
|
|
508
|
+
with open(src, "r", encoding="utf-8") as f:
|
|
480
509
|
truth = json.load(f)
|
|
481
510
|
|
|
482
511
|
# Find the local app translations
|
|
@@ -484,7 +513,7 @@ def lint_translations():
|
|
|
484
513
|
if file.endswith(".json"):
|
|
485
514
|
# Load the translation file
|
|
486
515
|
to_lint = os.path.join(config_translation_dir, file)
|
|
487
|
-
with open(to_lint, encoding="utf-8") as f:
|
|
516
|
+
with open(to_lint, "r", encoding="utf-8") as f:
|
|
488
517
|
translation = json.load(f)
|
|
489
518
|
|
|
490
519
|
# Lint the translation file
|
chainlit/context.py
CHANGED
|
@@ -3,9 +3,8 @@ import uuid
|
|
|
3
3
|
from contextvars import ContextVar
|
|
4
4
|
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
|
5
5
|
|
|
6
|
-
from lazify import LazyProxy
|
|
7
|
-
|
|
8
6
|
from chainlit.session import ClientType, HTTPSession, WebsocketSession
|
|
7
|
+
from lazify import LazyProxy
|
|
9
8
|
|
|
10
9
|
if TYPE_CHECKING:
|
|
11
10
|
from chainlit.emitter import BaseChainlitEmitter
|
|
@@ -24,17 +23,18 @@ class ChainlitContext:
|
|
|
24
23
|
loop: asyncio.AbstractEventLoop
|
|
25
24
|
emitter: "BaseChainlitEmitter"
|
|
26
25
|
session: Union["HTTPSession", "WebsocketSession"]
|
|
26
|
+
active_steps: List["Step"]
|
|
27
27
|
|
|
28
28
|
@property
|
|
29
29
|
def current_step(self):
|
|
30
|
-
if
|
|
31
|
-
return
|
|
30
|
+
if self.active_steps:
|
|
31
|
+
return self.active_steps[-1]
|
|
32
32
|
|
|
33
33
|
@property
|
|
34
34
|
def current_run(self):
|
|
35
|
-
if
|
|
35
|
+
if self.active_steps:
|
|
36
36
|
return next(
|
|
37
|
-
(step for step in
|
|
37
|
+
(step for step in self.active_steps if step.name in CL_RUN_NAMES), None
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
def __init__(
|
|
@@ -46,6 +46,7 @@ class ChainlitContext:
|
|
|
46
46
|
|
|
47
47
|
self.loop = asyncio.get_running_loop()
|
|
48
48
|
self.session = session
|
|
49
|
+
self.active_steps = []
|
|
49
50
|
|
|
50
51
|
if emitter:
|
|
51
52
|
self.emitter = emitter
|
|
@@ -104,8 +105,8 @@ def init_http_context(
|
|
|
104
105
|
def get_context() -> ChainlitContext:
|
|
105
106
|
try:
|
|
106
107
|
return context_var.get()
|
|
107
|
-
except LookupError
|
|
108
|
-
raise ChainlitContextException
|
|
108
|
+
except LookupError:
|
|
109
|
+
raise ChainlitContextException()
|
|
109
110
|
|
|
110
111
|
|
|
111
112
|
context: ChainlitContext = LazyProxy(get_context, enable_cache=False)
|