chainlit 1.0.506__py3-none-any.whl → 1.1.0__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 +34 -1
- chainlit/config.py +43 -21
- chainlit/context.py +19 -7
- chainlit/copilot/dist/index.js +650 -528
- chainlit/data/__init__.py +4 -2
- chainlit/data/acl.py +4 -1
- chainlit/data/sql_alchemy.py +39 -31
- chainlit/discord/__init__.py +6 -0
- chainlit/discord/app.py +304 -0
- chainlit/element.py +9 -3
- chainlit/emitter.py +11 -2
- chainlit/frontend/dist/assets/{index-d4233b49.js → index-0a52365d.js} +189 -185
- chainlit/frontend/dist/assets/react-plotly-509d26a7.js +3602 -0
- chainlit/frontend/dist/index.html +1 -1
- chainlit/llama_index/callbacks.py +7 -6
- chainlit/message.py +3 -3
- chainlit/server.py +31 -4
- chainlit/session.py +83 -62
- chainlit/slack/__init__.py +6 -0
- chainlit/slack/app.py +368 -0
- chainlit/socket.py +91 -33
- chainlit/step.py +25 -1
- chainlit/types.py +21 -1
- chainlit/user_session.py +6 -2
- chainlit/utils.py +2 -1
- {chainlit-1.0.506.dist-info → chainlit-1.1.0.dist-info}/METADATA +4 -3
- {chainlit-1.0.506.dist-info → chainlit-1.1.0.dist-info}/RECORD +29 -25
- chainlit/frontend/dist/assets/react-plotly-2b7fa4f9.js +0 -3484
- {chainlit-1.0.506.dist-info → chainlit-1.1.0.dist-info}/WHEEL +0 -0
- {chainlit-1.0.506.dist-info → chainlit-1.1.0.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py
CHANGED
|
@@ -52,7 +52,7 @@ from chainlit.oauth_providers import get_configured_oauth_providers
|
|
|
52
52
|
from chainlit.step import Step, step
|
|
53
53
|
from chainlit.sync import make_async, run_sync
|
|
54
54
|
from chainlit.telemetry import trace
|
|
55
|
-
from chainlit.types import ChatProfile, ThreadDict
|
|
55
|
+
from chainlit.types import AudioChunk, ChatProfile, ThreadDict
|
|
56
56
|
from chainlit.user import PersistedUser, User
|
|
57
57
|
from chainlit.user_session import user_session
|
|
58
58
|
from chainlit.utils import make_module_getattr, wrap_user_function
|
|
@@ -224,6 +224,38 @@ def on_chat_end(func: Callable) -> Callable:
|
|
|
224
224
|
return func
|
|
225
225
|
|
|
226
226
|
|
|
227
|
+
@trace
|
|
228
|
+
def on_audio_chunk(func: Callable) -> Callable:
|
|
229
|
+
"""
|
|
230
|
+
Hook to react to the audio chunks being sent.
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
chunk (AudioChunk): The audio chunk being sent.
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
Callable[], Any]: The decorated hook.
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
config.code.on_audio_chunk = wrap_user_function(func, with_task=False)
|
|
240
|
+
return func
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@trace
|
|
244
|
+
def on_audio_end(func: Callable) -> Callable:
|
|
245
|
+
"""
|
|
246
|
+
Hook to react to the audio stream ending. This is called after the last audio chunk is sent.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
elements ([List[Element]): The files that were uploaded before starting the audio stream (if any).
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
Callable[], Any]: The decorated hook.
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
config.code.on_audio_end = wrap_user_function(func, with_task=True)
|
|
256
|
+
return func
|
|
257
|
+
|
|
258
|
+
|
|
227
259
|
@trace
|
|
228
260
|
def author_rename(func: Callable[[str], str]) -> Callable[[str], str]:
|
|
229
261
|
"""
|
|
@@ -318,6 +350,7 @@ __getattr__ = make_module_getattr(
|
|
|
318
350
|
__all__ = [
|
|
319
351
|
"user_session",
|
|
320
352
|
"CopilotFunction",
|
|
353
|
+
"AudioChunk",
|
|
321
354
|
"Action",
|
|
322
355
|
"User",
|
|
323
356
|
"PersistedUser",
|
chainlit/config.py
CHANGED
|
@@ -4,7 +4,7 @@ import site
|
|
|
4
4
|
import sys
|
|
5
5
|
from importlib import util
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
|
|
7
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union, Literal
|
|
8
8
|
|
|
9
9
|
import tomli
|
|
10
10
|
from chainlit.logger import logger
|
|
@@ -16,7 +16,9 @@ from starlette.datastructures import Headers
|
|
|
16
16
|
|
|
17
17
|
if TYPE_CHECKING:
|
|
18
18
|
from chainlit.action import Action
|
|
19
|
-
from chainlit.
|
|
19
|
+
from chainlit.element import ElementBased
|
|
20
|
+
from chainlit.message import Message
|
|
21
|
+
from chainlit.types import AudioChunk, ChatProfile, ThreadDict
|
|
20
22
|
from chainlit.user import User
|
|
21
23
|
from fastapi import Request, Response
|
|
22
24
|
|
|
@@ -71,18 +73,26 @@ latex = false
|
|
|
71
73
|
# Automatically tag threads with the current chat profile (if a chat profile is used)
|
|
72
74
|
auto_tag_thread = true
|
|
73
75
|
|
|
74
|
-
# Authorize users to upload files with messages
|
|
75
|
-
[features.
|
|
76
|
+
# Authorize users to spontaneously upload files with messages
|
|
77
|
+
[features.spontaneous_file_upload]
|
|
76
78
|
enabled = true
|
|
77
79
|
accept = ["*/*"]
|
|
78
80
|
max_files = 20
|
|
79
81
|
max_size_mb = 500
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
|
|
83
|
+
[features.audio]
|
|
84
|
+
# Threshold for audio recording
|
|
85
|
+
min_decibels = -45
|
|
86
|
+
# Delay for the user to start speaking in MS
|
|
87
|
+
initial_silence_timeout = 3000
|
|
88
|
+
# Delay for the user to continue speaking in MS. If the user stops speaking for this duration, the recording will stop.
|
|
89
|
+
silence_timeout = 1500
|
|
90
|
+
# Above this duration (MS), the recording will forcefully stop.
|
|
91
|
+
max_duration = 15000
|
|
92
|
+
# Duration of the audio chunks in MS
|
|
93
|
+
chunk_duration = 1000
|
|
94
|
+
# Sample rate of the audio
|
|
95
|
+
sample_rate = 44100
|
|
86
96
|
|
|
87
97
|
[UI]
|
|
88
98
|
# Name of the app and chatbot.
|
|
@@ -122,9 +132,10 @@ hide_cot = false
|
|
|
122
132
|
# Be careful: If this is a relative path, it should not start with a slash.
|
|
123
133
|
# custom_build = "./public/build"
|
|
124
134
|
|
|
125
|
-
# Override default MUI light theme. (Check theme.ts)
|
|
126
135
|
[UI.theme]
|
|
136
|
+
#layout = "wide"
|
|
127
137
|
#font_family = "Inter, sans-serif"
|
|
138
|
+
# Override default MUI light theme. (Check theme.ts)
|
|
128
139
|
[UI.theme.light]
|
|
129
140
|
#background = "#FAFAFA"
|
|
130
141
|
#paper = "#FFFFFF"
|
|
@@ -184,31 +195,37 @@ class Palette(DataClassJsonMixin):
|
|
|
184
195
|
@dataclass()
|
|
185
196
|
class Theme(DataClassJsonMixin):
|
|
186
197
|
font_family: Optional[str] = None
|
|
198
|
+
layout: Optional[Literal["default", "wide"]] = "default"
|
|
187
199
|
light: Optional[Palette] = None
|
|
188
200
|
dark: Optional[Palette] = None
|
|
189
201
|
|
|
190
202
|
|
|
191
203
|
@dataclass
|
|
192
|
-
class
|
|
193
|
-
enabled: Optional[bool] = None
|
|
194
|
-
language: Optional[str] = None
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
@dataclass
|
|
198
|
-
class MultiModalFeature:
|
|
204
|
+
class SpontaneousFileUploadFeature(DataClassJsonMixin):
|
|
199
205
|
enabled: Optional[bool] = None
|
|
200
206
|
accept: Optional[Union[List[str], Dict[str, List[str]]]] = None
|
|
201
207
|
max_files: Optional[int] = None
|
|
202
208
|
max_size_mb: Optional[int] = None
|
|
203
209
|
|
|
204
210
|
|
|
211
|
+
@dataclass
|
|
212
|
+
class AudioFeature(DataClassJsonMixin):
|
|
213
|
+
min_decibels: int = -45
|
|
214
|
+
initial_silence_timeout: int = 2000
|
|
215
|
+
silence_timeout: int = 1500
|
|
216
|
+
chunk_duration: int = 1000
|
|
217
|
+
max_duration: int = 15000
|
|
218
|
+
sample_rate: int = 44100
|
|
219
|
+
enabled: bool = False
|
|
220
|
+
|
|
221
|
+
|
|
205
222
|
@dataclass()
|
|
206
223
|
class FeaturesSettings(DataClassJsonMixin):
|
|
207
224
|
prompt_playground: bool = True
|
|
208
|
-
|
|
225
|
+
spontaneous_file_upload: Optional[SpontaneousFileUploadFeature] = None
|
|
226
|
+
audio: Optional[AudioFeature] = Field(default_factory=AudioFeature)
|
|
209
227
|
latex: bool = False
|
|
210
228
|
unsafe_allow_html: bool = False
|
|
211
|
-
speech_to_text: Optional[SpeechToTextFeature] = None
|
|
212
229
|
auto_tag_thread: bool = True
|
|
213
230
|
|
|
214
231
|
|
|
@@ -247,7 +264,10 @@ class CodeSettings:
|
|
|
247
264
|
on_chat_start: Optional[Callable[[], Any]] = None
|
|
248
265
|
on_chat_end: Optional[Callable[[], Any]] = None
|
|
249
266
|
on_chat_resume: Optional[Callable[["ThreadDict"], Any]] = None
|
|
250
|
-
on_message: Optional[Callable[[
|
|
267
|
+
on_message: Optional[Callable[["Message"], Any]] = None
|
|
268
|
+
on_audio_chunk: Optional[Callable[["AudioChunk"], Any]] = None
|
|
269
|
+
on_audio_end: Optional[Callable[[List["ElementBased"]], Any]] = None
|
|
270
|
+
|
|
251
271
|
author_rename: Optional[Callable[[str], str]] = None
|
|
252
272
|
on_settings_update: Optional[Callable[[Dict[str, Any]], Any]] = None
|
|
253
273
|
set_chat_profiles: Optional[Callable[[Optional["User"]], List["ChatProfile"]]] = (
|
|
@@ -413,11 +433,13 @@ def load_settings():
|
|
|
413
433
|
|
|
414
434
|
ui_settings = UISettings(**ui_settings)
|
|
415
435
|
|
|
436
|
+
code_settings = CodeSettings(action_callbacks={})
|
|
437
|
+
|
|
416
438
|
return {
|
|
417
439
|
"features": features_settings,
|
|
418
440
|
"ui": ui_settings,
|
|
419
441
|
"project": project_settings,
|
|
420
|
-
"code":
|
|
442
|
+
"code": code_settings,
|
|
421
443
|
}
|
|
422
444
|
|
|
423
445
|
|
chainlit/context.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import uuid
|
|
3
3
|
from contextvars import ContextVar
|
|
4
|
-
from typing import TYPE_CHECKING, Dict, Optional, Union
|
|
4
|
+
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
|
5
5
|
|
|
6
|
-
from chainlit.session import HTTPSession, WebsocketSession
|
|
6
|
+
from chainlit.session import ClientType, HTTPSession, WebsocketSession
|
|
7
7
|
from lazify import LazyProxy
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
10
10
|
from chainlit.emitter import BaseChainlitEmitter
|
|
11
|
-
from chainlit.user import PersistedUser, User
|
|
12
11
|
from chainlit.step import Step
|
|
12
|
+
from chainlit.user import PersistedUser, User
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class ChainlitContextException(Exception):
|
|
@@ -28,13 +28,20 @@ class ChainlitContext:
|
|
|
28
28
|
if self.active_steps:
|
|
29
29
|
return self.active_steps[-1]
|
|
30
30
|
|
|
31
|
-
def __init__(
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
session: Union["HTTPSession", "WebsocketSession"],
|
|
34
|
+
emitter: Optional["BaseChainlitEmitter"] = None,
|
|
35
|
+
):
|
|
32
36
|
from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter
|
|
33
37
|
|
|
34
38
|
self.loop = asyncio.get_running_loop()
|
|
35
39
|
self.session = session
|
|
36
40
|
self.active_steps = []
|
|
37
|
-
|
|
41
|
+
|
|
42
|
+
if emitter:
|
|
43
|
+
self.emitter = emitter
|
|
44
|
+
elif isinstance(self.session, HTTPSession):
|
|
38
45
|
self.emitter = BaseChainlitEmitter(self.session)
|
|
39
46
|
elif isinstance(self.session, WebsocketSession):
|
|
40
47
|
self.emitter = ChainlitEmitter(self.session)
|
|
@@ -56,15 +63,20 @@ def init_ws_context(session_or_sid: Union[WebsocketSession, str]) -> ChainlitCon
|
|
|
56
63
|
|
|
57
64
|
|
|
58
65
|
def init_http_context(
|
|
66
|
+
thread_id: Optional[str] = None,
|
|
59
67
|
user: Optional[Union["User", "PersistedUser"]] = None,
|
|
60
68
|
auth_token: Optional[str] = None,
|
|
61
69
|
user_env: Optional[Dict[str, str]] = None,
|
|
70
|
+
client_type: ClientType = "webapp",
|
|
62
71
|
) -> ChainlitContext:
|
|
72
|
+
session_id = str(uuid.uuid4())
|
|
73
|
+
thread_id = thread_id or str(uuid.uuid4())
|
|
63
74
|
session = HTTPSession(
|
|
64
|
-
id=
|
|
75
|
+
id=session_id,
|
|
76
|
+
thread_id=thread_id,
|
|
65
77
|
token=auth_token,
|
|
66
78
|
user=user,
|
|
67
|
-
client_type=
|
|
79
|
+
client_type=client_type,
|
|
68
80
|
user_env=user_env,
|
|
69
81
|
)
|
|
70
82
|
context = ChainlitContext(session)
|