chainlit 2.7.0__py3-none-any.whl → 2.7.1__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 (85) hide show
  1. {chainlit-2.7.0.dist-info → chainlit-2.7.1.dist-info}/METADATA +1 -1
  2. chainlit-2.7.1.dist-info/RECORD +4 -0
  3. chainlit/__init__.py +0 -207
  4. chainlit/__main__.py +0 -4
  5. chainlit/_utils.py +0 -8
  6. chainlit/action.py +0 -33
  7. chainlit/auth/__init__.py +0 -95
  8. chainlit/auth/cookie.py +0 -197
  9. chainlit/auth/jwt.py +0 -42
  10. chainlit/cache.py +0 -45
  11. chainlit/callbacks.py +0 -433
  12. chainlit/chat_context.py +0 -64
  13. chainlit/chat_settings.py +0 -34
  14. chainlit/cli/__init__.py +0 -235
  15. chainlit/config.py +0 -621
  16. chainlit/context.py +0 -112
  17. chainlit/data/__init__.py +0 -111
  18. chainlit/data/acl.py +0 -19
  19. chainlit/data/base.py +0 -107
  20. chainlit/data/chainlit_data_layer.py +0 -687
  21. chainlit/data/dynamodb.py +0 -616
  22. chainlit/data/literalai.py +0 -501
  23. chainlit/data/sql_alchemy.py +0 -741
  24. chainlit/data/storage_clients/__init__.py +0 -0
  25. chainlit/data/storage_clients/azure.py +0 -84
  26. chainlit/data/storage_clients/azure_blob.py +0 -94
  27. chainlit/data/storage_clients/base.py +0 -28
  28. chainlit/data/storage_clients/gcs.py +0 -101
  29. chainlit/data/storage_clients/s3.py +0 -88
  30. chainlit/data/utils.py +0 -29
  31. chainlit/discord/__init__.py +0 -6
  32. chainlit/discord/app.py +0 -364
  33. chainlit/element.py +0 -454
  34. chainlit/emitter.py +0 -450
  35. chainlit/hello.py +0 -12
  36. chainlit/input_widget.py +0 -182
  37. chainlit/langchain/__init__.py +0 -6
  38. chainlit/langchain/callbacks.py +0 -682
  39. chainlit/langflow/__init__.py +0 -25
  40. chainlit/llama_index/__init__.py +0 -6
  41. chainlit/llama_index/callbacks.py +0 -206
  42. chainlit/logger.py +0 -16
  43. chainlit/markdown.py +0 -57
  44. chainlit/mcp.py +0 -99
  45. chainlit/message.py +0 -619
  46. chainlit/mistralai/__init__.py +0 -50
  47. chainlit/oauth_providers.py +0 -835
  48. chainlit/openai/__init__.py +0 -53
  49. chainlit/py.typed +0 -0
  50. chainlit/secret.py +0 -9
  51. chainlit/semantic_kernel/__init__.py +0 -111
  52. chainlit/server.py +0 -1616
  53. chainlit/session.py +0 -304
  54. chainlit/sidebar.py +0 -55
  55. chainlit/slack/__init__.py +0 -6
  56. chainlit/slack/app.py +0 -427
  57. chainlit/socket.py +0 -381
  58. chainlit/step.py +0 -490
  59. chainlit/sync.py +0 -43
  60. chainlit/teams/__init__.py +0 -6
  61. chainlit/teams/app.py +0 -348
  62. chainlit/translations/bn.json +0 -214
  63. chainlit/translations/el-GR.json +0 -214
  64. chainlit/translations/en-US.json +0 -214
  65. chainlit/translations/fr-FR.json +0 -214
  66. chainlit/translations/gu.json +0 -214
  67. chainlit/translations/he-IL.json +0 -214
  68. chainlit/translations/hi.json +0 -214
  69. chainlit/translations/ja.json +0 -214
  70. chainlit/translations/kn.json +0 -214
  71. chainlit/translations/ml.json +0 -214
  72. chainlit/translations/mr.json +0 -214
  73. chainlit/translations/nl.json +0 -214
  74. chainlit/translations/ta.json +0 -214
  75. chainlit/translations/te.json +0 -214
  76. chainlit/translations/zh-CN.json +0 -214
  77. chainlit/translations.py +0 -60
  78. chainlit/types.py +0 -334
  79. chainlit/user.py +0 -43
  80. chainlit/user_session.py +0 -153
  81. chainlit/utils.py +0 -173
  82. chainlit/version.py +0 -8
  83. chainlit-2.7.0.dist-info/RECORD +0 -84
  84. {chainlit-2.7.0.dist-info → chainlit-2.7.1.dist-info}/WHEEL +0 -0
  85. {chainlit-2.7.0.dist-info → chainlit-2.7.1.dist-info}/entry_points.txt +0 -0
chainlit/callbacks.py DELETED
@@ -1,433 +0,0 @@
1
- import inspect
2
- from typing import Any, Awaitable, Callable, Dict, List, Optional, Union
3
-
4
- from fastapi import Request, Response
5
- from mcp import ClientSession
6
- from starlette.datastructures import Headers
7
-
8
- from chainlit.action import Action
9
- from chainlit.config import config
10
- from chainlit.context import context
11
- from chainlit.data.base import BaseDataLayer
12
- from chainlit.mcp import McpConnection
13
- from chainlit.message import Message
14
- from chainlit.oauth_providers import get_configured_oauth_providers
15
- from chainlit.step import Step, step
16
- from chainlit.types import ChatProfile, Starter, ThreadDict
17
- from chainlit.user import User
18
- from chainlit.utils import wrap_user_function
19
-
20
-
21
- def on_app_startup(func: Callable[[], Union[None, Awaitable[None]]]) -> Callable:
22
- """
23
- Hook to run code when the Chainlit application starts.
24
- Useful for initializing resources, loading models, setting up database connections, etc.
25
- The function can be synchronous or asynchronous.
26
-
27
- Args:
28
- func (Callable[[], Union[None, Awaitable[None]]]): The startup hook to execute. Takes no arguments.
29
-
30
- Example:
31
- @cl.on_app_startup
32
- async def startup():
33
- print("Application is starting!")
34
- # Initialize resources here
35
-
36
- Returns:
37
- Callable[[], Union[None, Awaitable[None]]]: The decorated startup hook.
38
- """
39
- config.code.on_app_startup = wrap_user_function(func, with_task=False)
40
- return func
41
-
42
-
43
- def on_app_shutdown(func: Callable[[], Union[None, Awaitable[None]]]) -> Callable:
44
- """
45
- Hook to run code when the Chainlit application shuts down.
46
- Useful for cleaning up resources, closing connections, saving state, etc.
47
- The function can be synchronous or asynchronous.
48
-
49
- Args:
50
- func (Callable[[], Union[None, Awaitable[None]]]): The shutdown hook to execute. Takes no arguments.
51
-
52
- Example:
53
- @cl.on_app_shutdown
54
- async def shutdown():
55
- print("Application is shutting down!")
56
- # Clean up resources here
57
-
58
- Returns:
59
- Callable[[], Union[None, Awaitable[None]]]: The decorated shutdown hook.
60
- """
61
- config.code.on_app_shutdown = wrap_user_function(func, with_task=False)
62
- return func
63
-
64
-
65
- def password_auth_callback(
66
- func: Callable[[str, str], Awaitable[Optional[User]]],
67
- ) -> Callable:
68
- """
69
- Framework agnostic decorator to authenticate the user.
70
-
71
- Args:
72
- func (Callable[[str, str], Awaitable[Optional[User]]]): The authentication callback to execute. Takes the email and password as parameters.
73
-
74
- Example:
75
- @cl.password_auth_callback
76
- async def password_auth_callback(username: str, password: str) -> Optional[User]:
77
-
78
- Returns:
79
- Callable[[str, str], Awaitable[Optional[User]]]: The decorated authentication callback.
80
- """
81
-
82
- config.code.password_auth_callback = wrap_user_function(func)
83
- return func
84
-
85
-
86
- def header_auth_callback(
87
- func: Callable[[Headers], Awaitable[Optional[User]]],
88
- ) -> Callable:
89
- """
90
- Framework agnostic decorator to authenticate the user via a header
91
-
92
- Args:
93
- func (Callable[[Headers], Awaitable[Optional[User]]]): The authentication callback to execute.
94
-
95
- Example:
96
- @cl.header_auth_callback
97
- async def header_auth_callback(headers: Headers) -> Optional[User]:
98
-
99
- Returns:
100
- Callable[[Headers], Awaitable[Optional[User]]]: The decorated authentication callback.
101
- """
102
-
103
- config.code.header_auth_callback = wrap_user_function(func)
104
- return func
105
-
106
-
107
- def oauth_callback(
108
- func: Callable[
109
- [str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]
110
- ],
111
- ) -> Callable:
112
- """
113
- Framework agnostic decorator to authenticate the user via oauth
114
-
115
- Args:
116
- func (Callable[[str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]]): The authentication callback to execute.
117
-
118
- Example:
119
- @cl.oauth_callback
120
- 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]:
121
-
122
- Returns:
123
- Callable[[str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]]: The decorated authentication callback.
124
- """
125
-
126
- if len(get_configured_oauth_providers()) == 0:
127
- raise ValueError(
128
- "You must set the environment variable for at least one oauth provider to use oauth authentication."
129
- )
130
-
131
- config.code.oauth_callback = wrap_user_function(func)
132
- return func
133
-
134
-
135
- def on_logout(func: Callable[[Request, Response], Any]) -> Callable:
136
- """
137
- Function called when the user logs out.
138
- Takes the FastAPI request and response as parameters.
139
- """
140
-
141
- config.code.on_logout = wrap_user_function(func)
142
- return func
143
-
144
-
145
- def on_message(func: Callable) -> Callable:
146
- """
147
- Framework agnostic decorator to react to messages coming from the UI.
148
- The decorated function is called every time a new message is received.
149
-
150
- Args:
151
- func (Callable[[Message], Any]): The function to be called when a new message is received. Takes a cl.Message.
152
-
153
- Returns:
154
- Callable[[str], Any]: The decorated on_message function.
155
- """
156
-
157
- async def with_parent_id(message: Message):
158
- async with Step(name="on_message", type="run", parent_id=message.id) as s:
159
- s.input = message.content
160
- if len(inspect.signature(func).parameters) > 0:
161
- await func(message)
162
- else:
163
- await func()
164
-
165
- config.code.on_message = wrap_user_function(with_parent_id)
166
- return func
167
-
168
-
169
- async def send_window_message(data: Any):
170
- """
171
- Send custom data to the host window via a window.postMessage event.
172
-
173
- Args:
174
- data (Any): The data to send with the event.
175
- """
176
- await context.emitter.send_window_message(data)
177
-
178
-
179
- def on_window_message(func: Callable[[str], Any]) -> Callable:
180
- """
181
- Hook to react to javascript postMessage events coming from the UI.
182
-
183
- Args:
184
- func (Callable[[str], Any]): The function to be called when a window message is received.
185
- Takes the message content as a string parameter.
186
-
187
- Returns:
188
- Callable[[str], Any]: The decorated on_window_message function.
189
- """
190
- config.code.on_window_message = wrap_user_function(func)
191
- return func
192
-
193
-
194
- def on_chat_start(func: Callable) -> Callable:
195
- """
196
- Hook to react to the user websocket connection event.
197
-
198
- Args:
199
- func (Callable[], Any]): The connection hook to execute.
200
-
201
- Returns:
202
- Callable[], Any]: The decorated hook.
203
- """
204
-
205
- config.code.on_chat_start = wrap_user_function(
206
- step(func, name="on_chat_start", type="run"), with_task=True
207
- )
208
- return func
209
-
210
-
211
- def on_chat_resume(func: Callable[[ThreadDict], Any]) -> Callable:
212
- """
213
- Hook to react to resume websocket connection event.
214
-
215
- Args:
216
- func (Callable[], Any]): The connection hook to execute.
217
-
218
- Returns:
219
- Callable[], Any]: The decorated hook.
220
- """
221
-
222
- config.code.on_chat_resume = wrap_user_function(func, with_task=True)
223
- return func
224
-
225
-
226
- def set_chat_profiles(
227
- func: Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]],
228
- ) -> Callable:
229
- """
230
- Programmatic declaration of the available chat profiles (can depend on the User from the session if authentication is setup).
231
-
232
- Args:
233
- func (Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]): The function declaring the chat profiles.
234
-
235
- Returns:
236
- Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]: The decorated function.
237
- """
238
-
239
- config.code.set_chat_profiles = wrap_user_function(func)
240
- return func
241
-
242
-
243
- def set_starters(
244
- func: Callable[[Optional["User"]], Awaitable[List["Starter"]]],
245
- ) -> Callable:
246
- """
247
- Programmatic declaration of the available starter (can depend on the User from the session if authentication is setup).
248
-
249
- Args:
250
- func (Callable[[Optional["User"]], Awaitable[List["Starter"]]]): The function declaring the starters.
251
-
252
- Returns:
253
- Callable[[Optional["User"]], Awaitable[List["Starter"]]]: The decorated function.
254
- """
255
-
256
- config.code.set_starters = wrap_user_function(func)
257
- return func
258
-
259
-
260
- def on_chat_end(func: Callable) -> Callable:
261
- """
262
- Hook to react to the user websocket disconnect event.
263
-
264
- Args:
265
- func (Callable[], Any]): The disconnect hook to execute.
266
-
267
- Returns:
268
- Callable[], Any]: The decorated hook.
269
- """
270
-
271
- config.code.on_chat_end = wrap_user_function(func, with_task=True)
272
- return func
273
-
274
-
275
- def on_audio_start(func: Callable) -> Callable:
276
- """
277
- Hook to react to the user initiating audio.
278
-
279
- Returns:
280
- Callable[], Any]: The decorated hook.
281
- """
282
-
283
- config.code.on_audio_start = wrap_user_function(func, with_task=False)
284
- return func
285
-
286
-
287
- def on_audio_chunk(func: Callable) -> Callable:
288
- """
289
- Hook to react to the audio chunks being sent.
290
-
291
- Args:
292
- chunk (InputAudioChunk): The audio chunk being sent.
293
-
294
- Returns:
295
- Callable[], Any]: The decorated hook.
296
- """
297
-
298
- config.code.on_audio_chunk = wrap_user_function(func, with_task=False)
299
- return func
300
-
301
-
302
- def on_audio_end(func: Callable) -> Callable:
303
- """
304
- Hook to react to the audio stream ending. This is called after the last audio chunk is sent.
305
-
306
- Returns:
307
- Callable[], Any]: The decorated hook.
308
- """
309
-
310
- config.code.on_audio_end = wrap_user_function(
311
- step(func, name="on_audio_end", type="run"), with_task=True
312
- )
313
- return func
314
-
315
-
316
- def author_rename(
317
- func: Callable[[str], Awaitable[str]],
318
- ) -> Callable[[str], Awaitable[str]]:
319
- """
320
- Useful to rename the author of message to display more friendly author names in the UI.
321
- Args:
322
- func (Callable[[str], Awaitable[str]]): The function to be called to rename an author. Takes the original author name as parameter.
323
-
324
- Returns:
325
- Callable[[Any, str], Awaitable[Any]]: The decorated function.
326
- """
327
-
328
- config.code.author_rename = wrap_user_function(func)
329
- return func
330
-
331
-
332
- def on_mcp_connect(
333
- func: Callable[[McpConnection, ClientSession], Awaitable[None]],
334
- ) -> Callable[[McpConnection, ClientSession], Awaitable[None]]:
335
- """
336
- Called everytime an MCP is connected
337
- """
338
-
339
- config.code.on_mcp_connect = wrap_user_function(func)
340
- return func
341
-
342
-
343
- def on_mcp_disconnect(
344
- func: Callable[[str, ClientSession], Awaitable[None]],
345
- ) -> Callable[[str, ClientSession], Awaitable[None]]:
346
- """
347
- Called everytime an MCP is disconnected
348
- """
349
-
350
- config.code.on_mcp_disconnect = wrap_user_function(func)
351
- return func
352
-
353
-
354
- def on_stop(func: Callable) -> Callable:
355
- """
356
- Hook to react to the user stopping a thread.
357
-
358
- Args:
359
- func (Callable[[], Any]): The stop hook to execute.
360
-
361
- Returns:
362
- Callable[[], Any]: The decorated stop hook.
363
- """
364
-
365
- config.code.on_stop = wrap_user_function(func)
366
- return func
367
-
368
-
369
- def action_callback(name: str) -> Callable:
370
- """
371
- Callback to call when an action is clicked in the UI.
372
-
373
- Args:
374
- func (Callable[[Action], Any]): The action callback to execute. First parameter is the action.
375
- """
376
-
377
- def decorator(func: Callable[[Action], Any]):
378
- config.code.action_callbacks[name] = wrap_user_function(func, with_task=False)
379
- return func
380
-
381
- return decorator
382
-
383
-
384
- def on_settings_update(
385
- func: Callable[[Dict[str, Any]], Any],
386
- ) -> Callable[[Dict[str, Any]], Any]:
387
- """
388
- Hook to react to the user changing any settings.
389
-
390
- Args:
391
- func (Callable[], Any]): The hook to execute after settings were changed.
392
-
393
- Returns:
394
- Callable[], Any]: The decorated hook.
395
- """
396
-
397
- config.code.on_settings_update = wrap_user_function(func, with_task=True)
398
- return func
399
-
400
-
401
- def data_layer(
402
- func: Callable[[], BaseDataLayer],
403
- ) -> Callable[[], BaseDataLayer]:
404
- """
405
- Hook to configure custom data layer.
406
- """
407
-
408
- # We don't use wrap_user_function here because:
409
- # 1. We don't need to support async here and;
410
- # 2. We don't want to change the API for get_data_layer() to be async, everywhere (at this point).
411
- config.code.data_layer = func
412
- return func
413
-
414
-
415
- def on_feedback(func: Callable) -> Callable:
416
- """
417
- Hook to react to user feedback events from the UI.
418
- The decorated function is called every time feedback is received.
419
-
420
- Args:
421
- func (Callable[[Feedback], Any]): The function to be called when feedback is received. Takes a cl.Feedback object.
422
-
423
- Example:
424
- @cl.on_feedback
425
- async def on_feedback(feedback: Feedback):
426
- print(f"Received feedback: {feedback.value} for step {feedback.forId}")
427
- # Handle feedback here
428
-
429
- Returns:
430
- Callable[[Feedback], Any]: The decorated on_feedback function.
431
- """
432
- config.code.on_feedback = wrap_user_function(func)
433
- return func
chainlit/chat_context.py DELETED
@@ -1,64 +0,0 @@
1
- from typing import TYPE_CHECKING, Dict, List
2
-
3
- from chainlit.context import context
4
-
5
- if TYPE_CHECKING:
6
- from chainlit.message import Message
7
-
8
- chat_contexts: Dict[str, List["Message"]] = {}
9
-
10
-
11
- class ChatContext:
12
- def get(self) -> List["Message"]:
13
- if not context.session:
14
- return []
15
-
16
- if context.session.id not in chat_contexts:
17
- # Create a new chat context
18
- chat_contexts[context.session.id] = []
19
-
20
- return chat_contexts[context.session.id].copy()
21
-
22
- def add(self, message: "Message"):
23
- if not context.session:
24
- return
25
-
26
- if context.session.id not in chat_contexts:
27
- chat_contexts[context.session.id] = []
28
-
29
- if message not in chat_contexts[context.session.id]:
30
- chat_contexts[context.session.id].append(message)
31
-
32
- return message
33
-
34
- def remove(self, message: "Message") -> bool:
35
- if not context.session:
36
- return False
37
-
38
- if context.session.id not in chat_contexts:
39
- return False
40
-
41
- if message in chat_contexts[context.session.id]:
42
- chat_contexts[context.session.id].remove(message)
43
- return True
44
-
45
- return False
46
-
47
- def clear(self) -> None:
48
- if context.session and context.session.id in chat_contexts:
49
- chat_contexts[context.session.id] = []
50
-
51
- def to_openai(self):
52
- messages = []
53
- for message in self.get():
54
- if message.type == "assistant_message":
55
- messages.append({"role": "assistant", "content": message.content})
56
- elif message.type == "user_message":
57
- messages.append({"role": "user", "content": message.content})
58
- else:
59
- messages.append({"role": "system", "content": message.content})
60
-
61
- return messages
62
-
63
-
64
- chat_context = ChatContext()
chainlit/chat_settings.py DELETED
@@ -1,34 +0,0 @@
1
- from typing import List
2
-
3
- from pydantic import Field
4
- from pydantic.dataclasses import dataclass
5
-
6
- from chainlit.context import context
7
- from chainlit.input_widget import InputWidget
8
-
9
-
10
- @dataclass
11
- class ChatSettings:
12
- """Useful to create chat settings that the user can change."""
13
-
14
- inputs: List[InputWidget] = Field(default_factory=list, exclude=True)
15
-
16
- def __init__(
17
- self,
18
- inputs: List[InputWidget],
19
- ) -> None:
20
- self.inputs = inputs
21
-
22
- def settings(self):
23
- return dict(
24
- [(input_widget.id, input_widget.initial) for input_widget in self.inputs]
25
- )
26
-
27
- async def send(self):
28
- settings = self.settings()
29
- context.emitter.set_chat_settings(settings)
30
-
31
- inputs_content = [input_widget.to_dict() for input_widget in self.inputs]
32
- await context.emitter.emit("chat_settings", inputs_content)
33
-
34
- return settings