chainlit 1.1.404__py3-none-any.whl → 1.2.0rc0__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 +63 -305
- chainlit/_utils.py +8 -0
- chainlit/assistant.py +16 -0
- chainlit/assistant_settings.py +35 -0
- chainlit/callbacks.py +340 -0
- chainlit/cli/__init__.py +1 -1
- chainlit/config.py +58 -28
- chainlit/copilot/dist/index.js +512 -631
- chainlit/data/__init__.py +6 -521
- chainlit/data/base.py +121 -0
- chainlit/data/dynamodb.py +5 -8
- chainlit/data/literalai.py +395 -0
- chainlit/data/sql_alchemy.py +11 -9
- chainlit/data/storage_clients.py +69 -15
- chainlit/data/utils.py +29 -0
- chainlit/element.py +1 -1
- chainlit/emitter.py +7 -0
- chainlit/frontend/dist/assets/{DailyMotion-e665b444.js → DailyMotion-aa368b7e.js} +1 -1
- chainlit/frontend/dist/assets/{Facebook-5207db92.js → Facebook-0335db46.js} +1 -1
- chainlit/frontend/dist/assets/{FilePlayer-86937d6e.js → FilePlayer-8d04256c.js} +1 -1
- chainlit/frontend/dist/assets/{Kaltura-c96622c1.js → Kaltura-67c9dd31.js} +1 -1
- chainlit/frontend/dist/assets/{Mixcloud-57ae3e32.js → Mixcloud-6bbaccf5.js} +1 -1
- chainlit/frontend/dist/assets/{Mux-20373920.js → Mux-c2bcb757.js} +1 -1
- chainlit/frontend/dist/assets/{Preview-c68c0613.js → Preview-210f3955.js} +1 -1
- chainlit/frontend/dist/assets/{SoundCloud-8a9e3eae.js → SoundCloud-a0276b84.js} +1 -1
- chainlit/frontend/dist/assets/{Streamable-1ed099af.js → Streamable-a007323d.js} +1 -1
- chainlit/frontend/dist/assets/{Twitch-6820039f.js → Twitch-e6a88aa3.js} +1 -1
- chainlit/frontend/dist/assets/{Vidyard-d39ab91d.js → Vidyard-dfb88a35.js} +1 -1
- chainlit/frontend/dist/assets/{Vimeo-017cd9a7.js → Vimeo-3baa13d9.js} +1 -1
- chainlit/frontend/dist/assets/{Wistia-a509d9f2.js → Wistia-e52f7bef.js} +1 -1
- chainlit/frontend/dist/assets/{YouTube-42dfd82f.js → YouTube-1715f22b.js} +1 -1
- chainlit/frontend/dist/assets/index-bfdd8585.js +729 -0
- chainlit/frontend/dist/assets/react-plotly-55648373.js +3484 -0
- chainlit/frontend/dist/index.html +1 -1
- chainlit/input_widget.py +22 -0
- chainlit/langchain/callbacks.py +6 -1
- chainlit/llama_index/callbacks.py +20 -4
- chainlit/markdown.py +15 -9
- chainlit/message.py +0 -1
- chainlit/server.py +113 -37
- chainlit/session.py +27 -4
- chainlit/socket.py +50 -1
- chainlit/translations/bn.json +231 -0
- chainlit/translations/en-US.json +6 -0
- chainlit/translations/fr-FR.json +236 -0
- chainlit/translations/gu.json +231 -0
- chainlit/translations/he-IL.json +231 -0
- chainlit/translations/hi.json +231 -0
- chainlit/translations/kn.json +231 -0
- chainlit/translations/ml.json +231 -0
- chainlit/translations/mr.json +231 -0
- chainlit/translations/ta.json +231 -0
- chainlit/translations/te.json +231 -0
- chainlit/types.py +1 -1
- chainlit/user_session.py +4 -0
- chainlit/utils.py +1 -1
- {chainlit-1.1.404.dist-info → chainlit-1.2.0rc0.dist-info}/METADATA +10 -10
- chainlit-1.2.0rc0.dist-info/RECORD +99 -0
- chainlit/frontend/dist/assets/index-30df9b2b.js +0 -730
- chainlit/frontend/dist/assets/react-plotly-5bb34118.js +0 -3602
- chainlit-1.1.404.dist-info/RECORD +0 -82
- {chainlit-1.1.404.dist-info → chainlit-1.2.0rc0.dist-info}/WHEEL +0 -0
- {chainlit-1.1.404.dist-info → chainlit-1.2.0rc0.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
import inspect
|
|
2
1
|
import os
|
|
3
2
|
|
|
4
3
|
from dotenv import load_dotenv
|
|
5
4
|
|
|
5
|
+
# ruff: noqa: E402
|
|
6
|
+
# Keep this here to ensure imports have environment available.
|
|
6
7
|
env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
|
|
7
8
|
|
|
8
|
-
import
|
|
9
|
-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
|
9
|
+
from chainlit.logger import logger
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
from starlette.datastructures import Headers
|
|
11
|
+
if env_found:
|
|
12
|
+
logger.info("Loaded .env file")
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
from chainlit.langchain.callbacks import (
|
|
18
|
-
LangchainCallbackHandler,
|
|
19
|
-
AsyncLangchainCallbackHandler,
|
|
20
|
-
)
|
|
21
|
-
from chainlit.llama_index.callbacks import LlamaIndexCallbackHandler
|
|
22
|
-
from chainlit.openai import instrument_openai
|
|
23
|
-
from chainlit.mistralai import instrument_mistralai
|
|
14
|
+
import asyncio
|
|
15
|
+
from typing import TYPE_CHECKING, Any, Dict
|
|
24
16
|
|
|
25
17
|
import chainlit.input_widget as input_widget
|
|
26
18
|
from chainlit.action import Action
|
|
19
|
+
from chainlit.assistant import Assistant
|
|
20
|
+
from chainlit.assistant_settings import AssistantSettings
|
|
27
21
|
from chainlit.cache import cache
|
|
28
22
|
from chainlit.chat_context import chat_context
|
|
29
23
|
from chainlit.chat_settings import ChatSettings
|
|
30
|
-
from chainlit.config import config
|
|
31
24
|
from chainlit.context import context
|
|
32
25
|
from chainlit.element import (
|
|
33
26
|
Audio,
|
|
@@ -43,7 +36,6 @@ from chainlit.element import (
|
|
|
43
36
|
Text,
|
|
44
37
|
Video,
|
|
45
38
|
)
|
|
46
|
-
from chainlit.logger import logger
|
|
47
39
|
from chainlit.message import (
|
|
48
40
|
AskActionMessage,
|
|
49
41
|
AskFileMessage,
|
|
@@ -51,303 +43,46 @@ from chainlit.message import (
|
|
|
51
43
|
ErrorMessage,
|
|
52
44
|
Message,
|
|
53
45
|
)
|
|
54
|
-
from chainlit.oauth_providers import get_configured_oauth_providers
|
|
55
46
|
from chainlit.step import Step, step
|
|
56
47
|
from chainlit.sync import make_async, run_sync
|
|
57
|
-
from chainlit.
|
|
58
|
-
from chainlit.types import AudioChunk, ChatProfile, Starter, ThreadDict
|
|
48
|
+
from chainlit.types import AudioChunk, ChatProfile, Starter
|
|
59
49
|
from chainlit.user import PersistedUser, User
|
|
60
50
|
from chainlit.user_session import user_session
|
|
61
|
-
from chainlit.utils import make_module_getattr
|
|
51
|
+
from chainlit.utils import make_module_getattr
|
|
62
52
|
from chainlit.version import __version__
|
|
63
53
|
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
54
|
+
from pydantic.dataclasses import dataclass
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
config.code.password_auth_callback = wrap_user_function(func)
|
|
86
|
-
return func
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
@trace
|
|
90
|
-
def header_auth_callback(func: Callable[[Headers], Optional[User]]) -> Callable:
|
|
91
|
-
"""
|
|
92
|
-
Framework agnostic decorator to authenticate the user via a header
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
func (Callable[[Headers], Optional[User]]): The authentication callback to execute.
|
|
96
|
-
|
|
97
|
-
Example:
|
|
98
|
-
@cl.header_auth_callback
|
|
99
|
-
async def header_auth_callback(headers: Headers) -> Optional[User]:
|
|
100
|
-
|
|
101
|
-
Returns:
|
|
102
|
-
Callable[[Headers], Optional[User]]: The decorated authentication callback.
|
|
103
|
-
"""
|
|
104
|
-
|
|
105
|
-
config.code.header_auth_callback = wrap_user_function(func)
|
|
106
|
-
return func
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@trace
|
|
110
|
-
def oauth_callback(
|
|
111
|
-
func: Callable[[str, str, Dict[str, str], User], Optional[User]]
|
|
112
|
-
) -> Callable:
|
|
113
|
-
"""
|
|
114
|
-
Framework agnostic decorator to authenticate the user via oauth
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
func (Callable[[str, str, Dict[str, str], User], Optional[User]]): The authentication callback to execute.
|
|
118
|
-
|
|
119
|
-
Example:
|
|
120
|
-
@cl.oauth_callback
|
|
121
|
-
async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: User, id_token: Optional[str]) -> Optional[User]:
|
|
122
|
-
|
|
123
|
-
Returns:
|
|
124
|
-
Callable[[str, str, Dict[str, str], User], Optional[User]]: The decorated authentication callback.
|
|
125
|
-
"""
|
|
126
|
-
|
|
127
|
-
if len(get_configured_oauth_providers()) == 0:
|
|
128
|
-
raise ValueError(
|
|
129
|
-
"You must set the environment variable for at least one oauth provider to use oauth authentication."
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
config.code.oauth_callback = wrap_user_function(func)
|
|
133
|
-
return func
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
@trace
|
|
137
|
-
def on_logout(func: Callable[[Request, Response], Any]) -> Callable:
|
|
138
|
-
"""
|
|
139
|
-
Function called when the user logs out.
|
|
140
|
-
Takes the FastAPI request and response as parameters.
|
|
141
|
-
"""
|
|
142
|
-
|
|
143
|
-
config.code.on_logout = wrap_user_function(func)
|
|
144
|
-
return func
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
@trace
|
|
148
|
-
def on_message(func: Callable) -> Callable:
|
|
149
|
-
"""
|
|
150
|
-
Framework agnostic decorator to react to messages coming from the UI.
|
|
151
|
-
The decorated function is called every time a new message is received.
|
|
152
|
-
|
|
153
|
-
Args:
|
|
154
|
-
func (Callable[[Message], Any]): The function to be called when a new message is received. Takes a cl.Message.
|
|
155
|
-
|
|
156
|
-
Returns:
|
|
157
|
-
Callable[[str], Any]: The decorated on_message function.
|
|
158
|
-
"""
|
|
159
|
-
|
|
160
|
-
async def with_parent_id(message: Message):
|
|
161
|
-
async with Step(name="on_message", type="run", parent_id=message.id) as s:
|
|
162
|
-
s.input = message.content
|
|
163
|
-
if len(inspect.signature(func).parameters) > 0:
|
|
164
|
-
await func(message)
|
|
165
|
-
else:
|
|
166
|
-
await func()
|
|
167
|
-
|
|
168
|
-
config.code.on_message = wrap_user_function(with_parent_id)
|
|
169
|
-
return func
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
@trace
|
|
173
|
-
def on_chat_start(func: Callable) -> Callable:
|
|
174
|
-
"""
|
|
175
|
-
Hook to react to the user websocket connection event.
|
|
176
|
-
|
|
177
|
-
Args:
|
|
178
|
-
func (Callable[], Any]): The connection hook to execute.
|
|
179
|
-
|
|
180
|
-
Returns:
|
|
181
|
-
Callable[], Any]: The decorated hook.
|
|
182
|
-
"""
|
|
183
|
-
|
|
184
|
-
config.code.on_chat_start = wrap_user_function(
|
|
185
|
-
step(func, name="on_chat_start", type="run"), with_task=True
|
|
186
|
-
)
|
|
187
|
-
return func
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
@trace
|
|
191
|
-
def on_chat_resume(func: Callable[[ThreadDict], Any]) -> Callable:
|
|
192
|
-
"""
|
|
193
|
-
Hook to react to resume websocket connection event.
|
|
194
|
-
|
|
195
|
-
Args:
|
|
196
|
-
func (Callable[], Any]): The connection hook to execute.
|
|
197
|
-
|
|
198
|
-
Returns:
|
|
199
|
-
Callable[], Any]: The decorated hook.
|
|
200
|
-
"""
|
|
201
|
-
|
|
202
|
-
config.code.on_chat_resume = wrap_user_function(func, with_task=True)
|
|
203
|
-
return func
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
@trace
|
|
207
|
-
def set_chat_profiles(
|
|
208
|
-
func: Callable[[Optional["User"]], List["ChatProfile"]]
|
|
209
|
-
) -> Callable:
|
|
210
|
-
"""
|
|
211
|
-
Programmatic declaration of the available chat profiles (can depend on the User from the session if authentication is setup).
|
|
212
|
-
|
|
213
|
-
Args:
|
|
214
|
-
func (Callable[[Optional["User"]], List["ChatProfile"]]): The function declaring the chat profiles.
|
|
215
|
-
|
|
216
|
-
Returns:
|
|
217
|
-
Callable[[Optional["User"]], List["ChatProfile"]]: The decorated function.
|
|
218
|
-
"""
|
|
219
|
-
|
|
220
|
-
config.code.set_chat_profiles = wrap_user_function(func)
|
|
221
|
-
return func
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
@trace
|
|
225
|
-
def set_starters(func: Callable[[Optional["User"]], List["Starter"]]) -> Callable:
|
|
226
|
-
"""
|
|
227
|
-
Programmatic declaration of the available starter (can depend on the User from the session if authentication is setup).
|
|
228
|
-
|
|
229
|
-
Args:
|
|
230
|
-
func (Callable[[Optional["User"]], List["Starter"]]): The function declaring the starters.
|
|
231
|
-
|
|
232
|
-
Returns:
|
|
233
|
-
Callable[[Optional["User"]], List["Starter"]]: The decorated function.
|
|
234
|
-
"""
|
|
235
|
-
|
|
236
|
-
config.code.set_starters = wrap_user_function(func)
|
|
237
|
-
return func
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
@trace
|
|
241
|
-
def on_chat_end(func: Callable) -> Callable:
|
|
242
|
-
"""
|
|
243
|
-
Hook to react to the user websocket disconnect event.
|
|
244
|
-
|
|
245
|
-
Args:
|
|
246
|
-
func (Callable[], Any]): The disconnect hook to execute.
|
|
247
|
-
|
|
248
|
-
Returns:
|
|
249
|
-
Callable[], Any]: The decorated hook.
|
|
250
|
-
"""
|
|
251
|
-
|
|
252
|
-
config.code.on_chat_end = wrap_user_function(func, with_task=True)
|
|
253
|
-
return func
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
@trace
|
|
257
|
-
def on_audio_chunk(func: Callable) -> Callable:
|
|
258
|
-
"""
|
|
259
|
-
Hook to react to the audio chunks being sent.
|
|
260
|
-
|
|
261
|
-
Args:
|
|
262
|
-
chunk (AudioChunk): The audio chunk being sent.
|
|
263
|
-
|
|
264
|
-
Returns:
|
|
265
|
-
Callable[], Any]: The decorated hook.
|
|
266
|
-
"""
|
|
267
|
-
|
|
268
|
-
config.code.on_audio_chunk = wrap_user_function(func, with_task=False)
|
|
269
|
-
return func
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
@trace
|
|
273
|
-
def on_audio_end(func: Callable) -> Callable:
|
|
274
|
-
"""
|
|
275
|
-
Hook to react to the audio stream ending. This is called after the last audio chunk is sent.
|
|
276
|
-
|
|
277
|
-
Args:
|
|
278
|
-
elements ([List[Element]): The files that were uploaded before starting the audio stream (if any).
|
|
279
|
-
|
|
280
|
-
Returns:
|
|
281
|
-
Callable[], Any]: The decorated hook.
|
|
282
|
-
"""
|
|
56
|
+
from .callbacks import (
|
|
57
|
+
action_callback,
|
|
58
|
+
author_rename,
|
|
59
|
+
header_auth_callback,
|
|
60
|
+
oauth_callback,
|
|
61
|
+
on_audio_chunk,
|
|
62
|
+
on_audio_end,
|
|
63
|
+
on_chat_end,
|
|
64
|
+
on_chat_resume,
|
|
65
|
+
on_chat_start,
|
|
66
|
+
on_create_assistant,
|
|
67
|
+
on_list_assistants,
|
|
68
|
+
on_logout,
|
|
69
|
+
on_message,
|
|
70
|
+
on_settings_update,
|
|
71
|
+
on_stop,
|
|
72
|
+
password_auth_callback,
|
|
73
|
+
set_chat_profiles,
|
|
74
|
+
set_starters,
|
|
75
|
+
)
|
|
283
76
|
|
|
284
|
-
|
|
285
|
-
|
|
77
|
+
if TYPE_CHECKING:
|
|
78
|
+
from chainlit.haystack.callbacks import HaystackAgentCallbackHandler
|
|
79
|
+
from chainlit.langchain.callbacks import (
|
|
80
|
+
AsyncLangchainCallbackHandler,
|
|
81
|
+
LangchainCallbackHandler,
|
|
286
82
|
)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
@trace
|
|
291
|
-
def author_rename(func: Callable[[str], str]) -> Callable[[str], str]:
|
|
292
|
-
"""
|
|
293
|
-
Useful to rename the author of message to display more friendly author names in the UI.
|
|
294
|
-
Args:
|
|
295
|
-
func (Callable[[str], str]): The function to be called to rename an author. Takes the original author name as parameter.
|
|
296
|
-
|
|
297
|
-
Returns:
|
|
298
|
-
Callable[[Any, str], Any]: The decorated function.
|
|
299
|
-
"""
|
|
300
|
-
|
|
301
|
-
config.code.author_rename = wrap_user_function(func)
|
|
302
|
-
return func
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
@trace
|
|
306
|
-
def on_stop(func: Callable) -> Callable:
|
|
307
|
-
"""
|
|
308
|
-
Hook to react to the user stopping a thread.
|
|
309
|
-
|
|
310
|
-
Args:
|
|
311
|
-
func (Callable[[], Any]): The stop hook to execute.
|
|
312
|
-
|
|
313
|
-
Returns:
|
|
314
|
-
Callable[[], Any]: The decorated stop hook.
|
|
315
|
-
"""
|
|
316
|
-
|
|
317
|
-
config.code.on_stop = wrap_user_function(func)
|
|
318
|
-
return func
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
def action_callback(name: str) -> Callable:
|
|
322
|
-
"""
|
|
323
|
-
Callback to call when an action is clicked in the UI.
|
|
324
|
-
|
|
325
|
-
Args:
|
|
326
|
-
func (Callable[[Action], Any]): The action callback to execute. First parameter is the action.
|
|
327
|
-
"""
|
|
328
|
-
|
|
329
|
-
def decorator(func: Callable[[Action], Any]):
|
|
330
|
-
config.code.action_callbacks[name] = wrap_user_function(func, with_task=True)
|
|
331
|
-
return func
|
|
332
|
-
|
|
333
|
-
return decorator
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
def on_settings_update(
|
|
337
|
-
func: Callable[[Dict[str, Any]], Any]
|
|
338
|
-
) -> Callable[[Dict[str, Any]], Any]:
|
|
339
|
-
"""
|
|
340
|
-
Hook to react to the user changing any settings.
|
|
341
|
-
|
|
342
|
-
Args:
|
|
343
|
-
func (Callable[], Any]): The hook to execute after settings were changed.
|
|
344
|
-
|
|
345
|
-
Returns:
|
|
346
|
-
Callable[], Any]: The decorated hook.
|
|
347
|
-
"""
|
|
348
|
-
|
|
349
|
-
config.code.on_settings_update = wrap_user_function(func, with_task=True)
|
|
350
|
-
return func
|
|
83
|
+
from chainlit.llama_index.callbacks import LlamaIndexCallbackHandler
|
|
84
|
+
from chainlit.mistralai import instrument_mistralai
|
|
85
|
+
from chainlit.openai import instrument_openai
|
|
351
86
|
|
|
352
87
|
|
|
353
88
|
def sleep(duration: int):
|
|
@@ -380,6 +115,7 @@ __getattr__ = make_module_getattr(
|
|
|
380
115
|
)
|
|
381
116
|
|
|
382
117
|
__all__ = [
|
|
118
|
+
"__version__",
|
|
383
119
|
"ChatProfile",
|
|
384
120
|
"Starter",
|
|
385
121
|
"user_session",
|
|
@@ -402,6 +138,10 @@ __all__ = [
|
|
|
402
138
|
"TaskStatus",
|
|
403
139
|
"Video",
|
|
404
140
|
"ChatSettings",
|
|
141
|
+
# Experimental
|
|
142
|
+
"AssistantSettings",
|
|
143
|
+
# Experimental
|
|
144
|
+
"Assistant",
|
|
405
145
|
"input_widget",
|
|
406
146
|
"Message",
|
|
407
147
|
"ErrorMessage",
|
|
@@ -421,6 +161,8 @@ __all__ = [
|
|
|
421
161
|
"action_callback",
|
|
422
162
|
"author_rename",
|
|
423
163
|
"on_settings_update",
|
|
164
|
+
"on_create_assistant",
|
|
165
|
+
"on_list_assistants",
|
|
424
166
|
"password_auth_callback",
|
|
425
167
|
"header_auth_callback",
|
|
426
168
|
"sleep",
|
|
@@ -434,6 +176,22 @@ __all__ = [
|
|
|
434
176
|
"HaystackAgentCallbackHandler",
|
|
435
177
|
"instrument_openai",
|
|
436
178
|
"instrument_mistralai",
|
|
179
|
+
"password_auth_callback",
|
|
180
|
+
"header_auth_callback",
|
|
181
|
+
"oauth_callback",
|
|
182
|
+
"on_logout",
|
|
183
|
+
"on_message",
|
|
184
|
+
"on_chat_start",
|
|
185
|
+
"on_chat_resume",
|
|
186
|
+
"set_chat_profiles",
|
|
187
|
+
"set_starters",
|
|
188
|
+
"on_chat_end",
|
|
189
|
+
"on_audio_chunk",
|
|
190
|
+
"on_audio_end",
|
|
191
|
+
"author_rename",
|
|
192
|
+
"on_stop",
|
|
193
|
+
"action_callback",
|
|
194
|
+
"on_settings_update",
|
|
437
195
|
]
|
|
438
196
|
|
|
439
197
|
|
chainlit/_utils.py
ADDED
|
@@ -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
|
chainlit/assistant.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import List, Dict
|
|
2
|
+
from chainlit.input_widget import InputWidget
|
|
3
|
+
|
|
4
|
+
class Assistant:
|
|
5
|
+
input_widgets: List[InputWidget] = []
|
|
6
|
+
settings_values: Dict = {}
|
|
7
|
+
|
|
8
|
+
def __init__(self, input_widgets: List[InputWidget], settings_values: Dict):
|
|
9
|
+
self.input_widgets = input_widgets
|
|
10
|
+
self.settings_values = settings_values
|
|
11
|
+
|
|
12
|
+
def to_dict(self):
|
|
13
|
+
return {
|
|
14
|
+
"input_widgets": [widget.__repr__() for widget in self.input_widgets],
|
|
15
|
+
"settings_values": self.settings_values
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from chainlit.context import context
|
|
5
|
+
from chainlit.input_widget import InputWidget
|
|
6
|
+
from pydantic.dataclasses import Field, dataclass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class AssistantSettings:
|
|
11
|
+
"""Useful to create chat settings that the user can change."""
|
|
12
|
+
|
|
13
|
+
inputs: List[InputWidget] = Field(default_factory=list, exclude=True)
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
inputs: List[InputWidget],
|
|
18
|
+
) -> None:
|
|
19
|
+
self.inputs = inputs
|
|
20
|
+
|
|
21
|
+
def settings(self):
|
|
22
|
+
return dict(
|
|
23
|
+
[(input_widget.id, input_widget.initial) for input_widget in self.inputs]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
async def send(self):
|
|
27
|
+
settings = self.settings()
|
|
28
|
+
context.emitter.set_assistant_settings(settings)
|
|
29
|
+
|
|
30
|
+
inputs_content = [input_widget.to_dict() for input_widget in self.inputs]
|
|
31
|
+
# logging.info(f"Sending assistant settings: {inputs_content}")
|
|
32
|
+
await context.emitter.emit("assistant_settings", inputs_content)
|
|
33
|
+
|
|
34
|
+
# logging.info(f"Assistant settings sent: {settings}")
|
|
35
|
+
return settings
|