chainlit 1.2.0__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.

Files changed (41) hide show
  1. chainlit/__init__.py +10 -0
  2. chainlit/assistant.py +16 -0
  3. chainlit/assistant_settings.py +35 -0
  4. chainlit/callbacks.py +32 -0
  5. chainlit/cli/__init__.py +1 -1
  6. chainlit/config.py +11 -7
  7. chainlit/copilot/dist/index.js +253 -253
  8. chainlit/data/dynamodb.py +3 -3
  9. chainlit/data/sql_alchemy.py +2 -1
  10. chainlit/element.py +1 -1
  11. chainlit/emitter.py +7 -0
  12. chainlit/frontend/dist/assets/{DailyMotion-05f4fe48.js → DailyMotion-aa368b7e.js} +1 -1
  13. chainlit/frontend/dist/assets/{Facebook-f25411d1.js → Facebook-0335db46.js} +1 -1
  14. chainlit/frontend/dist/assets/{FilePlayer-40ff3414.js → FilePlayer-8d04256c.js} +1 -1
  15. chainlit/frontend/dist/assets/{Kaltura-6cbf3897.js → Kaltura-67c9dd31.js} +1 -1
  16. chainlit/frontend/dist/assets/{Mixcloud-34e7c912.js → Mixcloud-6bbaccf5.js} +1 -1
  17. chainlit/frontend/dist/assets/{Mux-8aaff6ac.js → Mux-c2bcb757.js} +1 -1
  18. chainlit/frontend/dist/assets/{Preview-2d3bf558.js → Preview-210f3955.js} +1 -1
  19. chainlit/frontend/dist/assets/{SoundCloud-b835f90f.js → SoundCloud-a0276b84.js} +1 -1
  20. chainlit/frontend/dist/assets/{Streamable-1293e4f3.js → Streamable-a007323d.js} +1 -1
  21. chainlit/frontend/dist/assets/{Twitch-c69660cd.js → Twitch-e6a88aa3.js} +1 -1
  22. chainlit/frontend/dist/assets/{Vidyard-43bda599.js → Vidyard-dfb88a35.js} +1 -1
  23. chainlit/frontend/dist/assets/{Vimeo-54150039.js → Vimeo-3baa13d9.js} +1 -1
  24. chainlit/frontend/dist/assets/{Wistia-aa3c721b.js → Wistia-e52f7bef.js} +1 -1
  25. chainlit/frontend/dist/assets/{YouTube-dd0f3cc2.js → YouTube-1715f22b.js} +1 -1
  26. chainlit/frontend/dist/assets/index-bfdd8585.js +729 -0
  27. chainlit/frontend/dist/assets/{react-plotly-f52a41eb.js → react-plotly-55648373.js} +1 -1
  28. chainlit/frontend/dist/index.html +1 -1
  29. chainlit/input_widget.py +22 -0
  30. chainlit/server.py +23 -1
  31. chainlit/session.py +23 -3
  32. chainlit/socket.py +50 -1
  33. chainlit/translations/en-US.json +6 -0
  34. chainlit/translations/fr-FR.json +236 -0
  35. chainlit/types.py +1 -1
  36. chainlit/user_session.py +4 -0
  37. {chainlit-1.2.0.dist-info → chainlit-1.2.0rc0.dist-info}/METADATA +8 -8
  38. {chainlit-1.2.0.dist-info → chainlit-1.2.0rc0.dist-info}/RECORD +40 -37
  39. chainlit/frontend/dist/assets/index-cf48bedd.js +0 -729
  40. {chainlit-1.2.0.dist-info → chainlit-1.2.0rc0.dist-info}/WHEEL +0 -0
  41. {chainlit-1.2.0.dist-info → chainlit-1.2.0rc0.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py CHANGED
@@ -16,6 +16,8 @@ from typing import TYPE_CHECKING, Any, Dict
16
16
 
17
17
  import chainlit.input_widget as input_widget
18
18
  from chainlit.action import Action
19
+ from chainlit.assistant import Assistant
20
+ from chainlit.assistant_settings import AssistantSettings
19
21
  from chainlit.cache import cache
20
22
  from chainlit.chat_context import chat_context
21
23
  from chainlit.chat_settings import ChatSettings
@@ -61,6 +63,8 @@ from .callbacks import (
61
63
  on_chat_end,
62
64
  on_chat_resume,
63
65
  on_chat_start,
66
+ on_create_assistant,
67
+ on_list_assistants,
64
68
  on_logout,
65
69
  on_message,
66
70
  on_settings_update,
@@ -134,6 +138,10 @@ __all__ = [
134
138
  "TaskStatus",
135
139
  "Video",
136
140
  "ChatSettings",
141
+ # Experimental
142
+ "AssistantSettings",
143
+ # Experimental
144
+ "Assistant",
137
145
  "input_widget",
138
146
  "Message",
139
147
  "ErrorMessage",
@@ -153,6 +161,8 @@ __all__ = [
153
161
  "action_callback",
154
162
  "author_rename",
155
163
  "on_settings_update",
164
+ "on_create_assistant",
165
+ "on_list_assistants",
156
166
  "password_auth_callback",
157
167
  "header_auth_callback",
158
168
  "sleep",
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
chainlit/callbacks.py CHANGED
@@ -1,7 +1,10 @@
1
+ import functools
1
2
  import inspect
2
3
  from typing import Any, Awaitable, Callable, Dict, List, Optional
3
4
 
4
5
  from chainlit.action import Action
6
+ from chainlit.assistant import Assistant
7
+ from chainlit.assistant_settings import AssistantSettings
5
8
  from chainlit.config import config
6
9
  from chainlit.message import Message
7
10
  from chainlit.oauth_providers import get_configured_oauth_providers
@@ -14,6 +17,15 @@ from fastapi import Request, Response
14
17
  from starlette.datastructures import Headers
15
18
 
16
19
 
20
+ def experimental(func):
21
+ @functools.wraps(func)
22
+ def wrapper(*args, **kwargs):
23
+ print(f"\033[1;33mexperimental feature: {func.__name__}\033[0m")
24
+ return func(*args, **kwargs)
25
+
26
+ return wrapper
27
+
28
+
17
29
  @trace
18
30
  def password_auth_callback(
19
31
  func: Callable[[str, str], Awaitable[Optional[User]]]
@@ -306,3 +318,23 @@ def on_settings_update(
306
318
 
307
319
  config.code.on_settings_update = wrap_user_function(func, with_task=True)
308
320
  return func
321
+
322
+
323
+ # Experimental
324
+ @trace
325
+ @experimental
326
+ def on_create_assistant(
327
+ func: Callable[[Optional[User], AssistantSettings], Any]
328
+ ) -> Callable[[Optional[User], AssistantSettings], Any]:
329
+ config.code.on_create_assistant = wrap_user_function(func)
330
+ return func
331
+
332
+
333
+ # Experimental
334
+ @trace
335
+ @experimental
336
+ def on_list_assistants(
337
+ func: Callable[[Optional[User]], List[Assistant]]
338
+ ) -> Callable[[Optional[User]], List[Assistant]]:
339
+ config.code.on_list_assistants = wrap_user_function(func)
340
+ return func
chainlit/cli/__init__.py CHANGED
@@ -183,7 +183,7 @@ def chainlit_run(
183
183
  no_cache = True
184
184
  # This is required to have OpenAI LLM providers available for the CI run
185
185
  os.environ["OPENAI_API_KEY"] = "sk-FAKE-OPENAI-API-KEY"
186
- # This is required for authenticationt tests
186
+ # This is required for authentication tests
187
187
  os.environ["CHAINLIT_AUTH_SECRET"] = "SUPER_SECRET"
188
188
  else:
189
189
  trace_event("chainlit run")
chainlit/config.py CHANGED
@@ -28,13 +28,13 @@ from ._utils import is_path_inside
28
28
 
29
29
  if TYPE_CHECKING:
30
30
  from chainlit.action import Action
31
+ from chainlit.assistant import Assistant
31
32
  from chainlit.element import ElementBased
32
33
  from chainlit.message import Message
33
34
  from chainlit.types import AudioChunk, ChatProfile, Starter, ThreadDict
34
35
  from chainlit.user import User
35
36
  from fastapi import Request, Response
36
37
 
37
-
38
38
  BACKEND_ROOT = os.path.dirname(__file__)
39
39
  PACKAGE_ROOT = os.path.dirname(os.path.dirname(BACKEND_ROOT))
40
40
  TRANSLATIONS_DIR = os.path.join(BACKEND_ROOT, "translations")
@@ -285,9 +285,9 @@ class CodeSettings:
285
285
  password_auth_callback: Optional[
286
286
  Callable[[str, str], Awaitable[Optional["User"]]]
287
287
  ] = None
288
- header_auth_callback: Optional[
289
- Callable[[Headers], Awaitable[Optional["User"]]]
290
- ] = None
288
+ header_auth_callback: Optional[Callable[[Headers], Awaitable[Optional["User"]]]] = (
289
+ None
290
+ )
291
291
  oauth_callback: Optional[
292
292
  Callable[[str, str, Dict[str, str], "User"], Awaitable[Optional["User"]]]
293
293
  ] = None
@@ -305,9 +305,13 @@ class CodeSettings:
305
305
  set_chat_profiles: Optional[
306
306
  Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]
307
307
  ] = None
308
- set_starters: Optional[
309
- Callable[[Optional["User"]], Awaitable[List["Starter"]]]
310
- ] = None
308
+ set_starters: Optional[Callable[[Optional["User"]], Awaitable[List["Starter"]]]] = (
309
+ None
310
+ )
311
+
312
+ # assistant-related callback function
313
+ on_create_assistant: Optional[Callable[[Optional["User"], Any], Any]] = None
314
+ on_list_assistants: Optional[Callable[[Optional["User"]], List["Assistant"]]] = None
311
315
 
312
316
 
313
317
  @dataclass()