chainlit 1.1.300rc4__py3-none-any.whl → 1.1.300rc5__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 (43) hide show
  1. chainlit/__init__.py +20 -1
  2. chainlit/cli/__init__.py +48 -6
  3. chainlit/config.py +5 -0
  4. chainlit/context.py +9 -0
  5. chainlit/copilot/dist/index.js +180 -180
  6. chainlit/data/__init__.py +6 -3
  7. chainlit/data/sql_alchemy.py +3 -3
  8. chainlit/element.py +33 -9
  9. chainlit/emitter.py +3 -3
  10. chainlit/frontend/dist/assets/{DailyMotion-1a2b7d60.js → DailyMotion-f9db5a1d.js} +1 -1
  11. chainlit/frontend/dist/assets/{Facebook-8422f48c.js → Facebook-f95b29c9.js} +1 -1
  12. chainlit/frontend/dist/assets/{FilePlayer-a0a41349.js → FilePlayer-ba3f562c.js} +1 -1
  13. chainlit/frontend/dist/assets/{Kaltura-aa7990f2.js → Kaltura-195ed801.js} +1 -1
  14. chainlit/frontend/dist/assets/{Mixcloud-1647b3e4.js → Mixcloud-f64c6d87.js} +1 -1
  15. chainlit/frontend/dist/assets/{Mux-7e57be81.js → Mux-206cbddc.js} +1 -1
  16. chainlit/frontend/dist/assets/{Preview-cb89b2c6.js → Preview-af249586.js} +1 -1
  17. chainlit/frontend/dist/assets/{SoundCloud-c0d86d55.js → SoundCloud-80a26cdf.js} +1 -1
  18. chainlit/frontend/dist/assets/{Streamable-57c43c18.js → Streamable-f80b255d.js} +1 -1
  19. chainlit/frontend/dist/assets/{Twitch-bed3f21d.js → Twitch-0e2f1d13.js} +1 -1
  20. chainlit/frontend/dist/assets/{Vidyard-4dd76e44.js → Vidyard-bd67bfc6.js} +1 -1
  21. chainlit/frontend/dist/assets/{Vimeo-93bb5ae2.js → Vimeo-f9496a5d.js} +1 -1
  22. chainlit/frontend/dist/assets/{Wistia-97199246.js → Wistia-a943e0aa.js} +1 -1
  23. chainlit/frontend/dist/assets/{YouTube-fe1a7afe.js → YouTube-cf572a1f.js} +1 -1
  24. chainlit/frontend/dist/assets/{index-919bea8f.js → index-5511e258.js} +131 -131
  25. chainlit/frontend/dist/assets/{react-plotly-b416b8f9.js → react-plotly-74b55763.js} +1 -1
  26. chainlit/frontend/dist/index.html +1 -2
  27. chainlit/message.py +13 -8
  28. chainlit/oauth_providers.py +63 -1
  29. chainlit/server.py +170 -48
  30. chainlit/socket.py +40 -20
  31. chainlit/step.py +12 -3
  32. chainlit/teams/__init__.py +6 -0
  33. chainlit/teams/app.py +332 -0
  34. chainlit/translations/en-US.json +1 -1
  35. chainlit/types.py +7 -17
  36. chainlit/user.py +9 -1
  37. chainlit/utils.py +42 -0
  38. {chainlit-1.1.300rc4.dist-info → chainlit-1.1.300rc5.dist-info}/METADATA +2 -2
  39. chainlit-1.1.300rc5.dist-info/RECORD +79 -0
  40. chainlit/cli/utils.py +0 -24
  41. chainlit-1.1.300rc4.dist-info/RECORD +0 -78
  42. {chainlit-1.1.300rc4.dist-info → chainlit-1.1.300rc5.dist-info}/WHEEL +0 -0
  43. {chainlit-1.1.300rc4.dist-info → chainlit-1.1.300rc5.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py CHANGED
@@ -28,6 +28,7 @@ from chainlit.config import config
28
28
  from chainlit.context import context
29
29
  from chainlit.element import (
30
30
  Audio,
31
+ Component,
31
32
  File,
32
33
  Image,
33
34
  Pdf,
@@ -114,7 +115,7 @@ def oauth_callback(
114
115
 
115
116
  Example:
116
117
  @cl.oauth_callback
117
- async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: User) -> Optional[User]:
118
+ 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]:
118
119
 
119
120
  Returns:
120
121
  Callable[[str, str, Dict[str, str], User], Optional[User]]: The decorated authentication callback.
@@ -189,6 +190,22 @@ def on_chat_resume(func: Callable[[ThreadDict], Any]) -> Callable:
189
190
  return func
190
191
 
191
192
 
193
+ @trace
194
+ def on_system_message(func: Callable) -> Callable:
195
+ """
196
+ Hook to react to a system message sent by the copilot.
197
+
198
+ Args:
199
+ func (Callable[], Any]): The hook to execute.
200
+
201
+ Returns:
202
+ Callable[], Any]: The decorated hook.
203
+ """
204
+
205
+ config.code.on_system_message = wrap_user_function(func)
206
+ return func
207
+
208
+
192
209
  @trace
193
210
  def set_chat_profiles(
194
211
  func: Callable[[Optional["User"]], List["ChatProfile"]]
@@ -376,6 +393,7 @@ __all__ = [
376
393
  "Plotly",
377
394
  "Image",
378
395
  "Text",
396
+ "Component",
379
397
  "Pyplot",
380
398
  "File",
381
399
  "Task",
@@ -398,6 +416,7 @@ __all__ = [
398
416
  "on_chat_start",
399
417
  "on_chat_end",
400
418
  "on_chat_resume",
419
+ "on_system_message",
401
420
  "on_stop",
402
421
  "action_callback",
403
422
  "author_rename",
chainlit/cli/__init__.py CHANGED
@@ -7,13 +7,12 @@ import uvicorn
7
7
 
8
8
  nest_asyncio.apply()
9
9
 
10
- from chainlit.auth import ensure_jwt_secret
11
10
  from chainlit.cache import init_lc_cache
12
- from chainlit.cli.utils import check_file
13
11
  from chainlit.config import (
14
12
  BACKEND_ROOT,
15
13
  DEFAULT_HOST,
16
14
  DEFAULT_PORT,
15
+ DEFAULT_ROOT_PATH,
17
16
  config,
18
17
  init_config,
19
18
  lint_translations,
@@ -22,8 +21,8 @@ from chainlit.config import (
22
21
  from chainlit.logger import logger
23
22
  from chainlit.markdown import init_markdown
24
23
  from chainlit.secret import random_secret
25
- from chainlit.server import app, register_wildcard_route_handler
26
24
  from chainlit.telemetry import trace_event
25
+ from chainlit.utils import check_file, ensure_jwt_secret
27
26
 
28
27
 
29
28
  # Create the main command group for Chainlit CLI
@@ -35,8 +34,14 @@ def cli():
35
34
 
36
35
  # Define the function to run Chainlit with provided options
37
36
  def run_chainlit(target: str):
37
+ from chainlit.server import combined_asgi_app as app
38
+
38
39
  host = os.environ.get("CHAINLIT_HOST", DEFAULT_HOST)
39
40
  port = int(os.environ.get("CHAINLIT_PORT", DEFAULT_PORT))
41
+ root_path = os.environ.get("CHAINLIT_ROOT_PATH", DEFAULT_ROOT_PATH)
42
+
43
+ ssl_certfile = os.environ.get("CHAINLIT_SSL_CERT", None)
44
+ ssl_keyfile = os.environ.get("CHAINLIT_SSL_KEY", None)
40
45
 
41
46
  ws_per_message_deflate_env = os.environ.get(
42
47
  "UVICORN_WS_PER_MESSAGE_DEFLATE", "true"
@@ -49,6 +54,7 @@ def run_chainlit(target: str):
49
54
 
50
55
  config.run.host = host
51
56
  config.run.port = port
57
+ config.run.root_path = root_path
52
58
 
53
59
  check_file(target)
54
60
  # Load the module provided by the user
@@ -57,8 +63,6 @@ def run_chainlit(target: str):
57
63
 
58
64
  ensure_jwt_secret()
59
65
 
60
- register_wildcard_route_handler()
61
-
62
66
  # Create the chainlit.md file if it doesn't exist
63
67
  init_markdown(config.root)
64
68
 
@@ -75,6 +79,8 @@ def run_chainlit(target: str):
75
79
  port=port,
76
80
  log_level=log_level,
77
81
  ws_per_message_deflate=ws_per_message_deflate,
82
+ ssl_keyfile=ssl_keyfile,
83
+ ssl_certfile=ssl_certfile,
78
84
  )
79
85
  server = uvicorn.Server(config)
80
86
  await server.serve()
@@ -126,13 +132,47 @@ def run_chainlit(target: str):
126
132
  envvar="NO_CACHE",
127
133
  help="Useful to disable third parties cache, such as langchain.",
128
134
  )
135
+ @click.option(
136
+ "--ssl-cert",
137
+ default=None,
138
+ envvar="CHAINLIT_SSL_CERT",
139
+ help="Specify the file path for the SSL certificate.",
140
+ )
141
+ @click.option(
142
+ "--ssl-key",
143
+ default=None,
144
+ envvar="CHAINLIT_SSL_KEY",
145
+ help="Specify the file path for the SSL key",
146
+ )
129
147
  @click.option("--host", help="Specify a different host to run the server on")
130
148
  @click.option("--port", help="Specify a different port to run the server on")
131
- def chainlit_run(target, watch, headless, debug, ci, no_cache, host, port):
149
+ @click.option("--root-path", help="Specify a different root path to run the server on")
150
+ def chainlit_run(
151
+ target,
152
+ watch,
153
+ headless,
154
+ debug,
155
+ ci,
156
+ no_cache,
157
+ ssl_cert,
158
+ ssl_key,
159
+ host,
160
+ port,
161
+ root_path,
162
+ ):
132
163
  if host:
133
164
  os.environ["CHAINLIT_HOST"] = host
134
165
  if port:
135
166
  os.environ["CHAINLIT_PORT"] = port
167
+ if bool(ssl_cert) != bool(ssl_key):
168
+ raise click.UsageError(
169
+ "Both --ssl-cert and --ssl-key must be provided together."
170
+ )
171
+ if ssl_cert:
172
+ os.environ["CHAINLIT_SSL_CERT"] = ssl_cert
173
+ os.environ["CHAINLIT_SSL_KEY"] = ssl_key
174
+ if root_path:
175
+ os.environ["CHAINLIT_ROOT_PATH"] = root_path
136
176
  if ci:
137
177
  logger.info("Running in CI mode")
138
178
 
@@ -150,6 +190,8 @@ def chainlit_run(target, watch, headless, debug, ci, no_cache, host, port):
150
190
  config.run.no_cache = no_cache
151
191
  config.run.ci = ci
152
192
  config.run.watch = watch
193
+ config.run.ssl_cert = ssl_cert
194
+ config.run.ssl_key = ssl_key
153
195
 
154
196
  run_chainlit(target)
155
197
 
chainlit/config.py CHANGED
@@ -163,6 +163,7 @@ generated_by = "{__version__}"
163
163
 
164
164
  DEFAULT_HOST = "0.0.0.0"
165
165
  DEFAULT_PORT = 8000
166
+ DEFAULT_ROOT_PATH = ""
166
167
 
167
168
 
168
169
  @dataclass()
@@ -171,6 +172,9 @@ class RunSettings:
171
172
  module_name: Optional[str] = None
172
173
  host: str = DEFAULT_HOST
173
174
  port: int = DEFAULT_PORT
175
+ ssl_cert: Optional[str] = None
176
+ ssl_key: Optional[str] = None
177
+ root_path: str = DEFAULT_ROOT_PATH
174
178
  headless: bool = False
175
179
  watch: bool = False
176
180
  no_cache: bool = False
@@ -275,6 +279,7 @@ class CodeSettings:
275
279
  on_message: Optional[Callable[["Message"], Any]] = None
276
280
  on_audio_chunk: Optional[Callable[["AudioChunk"], Any]] = None
277
281
  on_audio_end: Optional[Callable[[List["ElementBased"]], Any]] = None
282
+ on_system_message: Optional[Callable[["Message"], Any]] = None
278
283
 
279
284
  author_rename: Optional[Callable[[str], str]] = None
280
285
  on_settings_update: Optional[Callable[[Dict[str, Any]], Any]] = None
chainlit/context.py CHANGED
@@ -69,6 +69,8 @@ def init_http_context(
69
69
  user_env: Optional[Dict[str, str]] = None,
70
70
  client_type: ClientType = "webapp",
71
71
  ) -> ChainlitContext:
72
+ from chainlit.data import get_data_layer
73
+
72
74
  session_id = str(uuid.uuid4())
73
75
  thread_id = thread_id or str(uuid.uuid4())
74
76
  session = HTTPSession(
@@ -81,6 +83,13 @@ def init_http_context(
81
83
  )
82
84
  context = ChainlitContext(session)
83
85
  context_var.set(context)
86
+
87
+ if data_layer := get_data_layer():
88
+ if user_id := getattr(user, "id", None):
89
+ asyncio.create_task(
90
+ data_layer.update_thread(thread_id=thread_id, user_id=user_id)
91
+ )
92
+
84
93
  return context
85
94
 
86
95