chainlit 1.0.506__py3-none-any.whl → 1.1.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 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
@@ -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.types import ChatProfile, ThreadDict
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.multi_modal]
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
- # Allows user to use speech to text
82
- [features.speech_to_text]
83
- enabled = false
84
- # See all languages here https://github.com/JamesBrill/react-speech-recognition/blob/HEAD/docs/API.md#language-string
85
- # language = "en-US"
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.
@@ -189,26 +199,31 @@ class Theme(DataClassJsonMixin):
189
199
 
190
200
 
191
201
  @dataclass
192
- class SpeechToTextFeature:
193
- enabled: Optional[bool] = None
194
- language: Optional[str] = None
195
-
196
-
197
- @dataclass
198
- class MultiModalFeature:
202
+ class SpontaneousFileUploadFeature(DataClassJsonMixin):
199
203
  enabled: Optional[bool] = None
200
204
  accept: Optional[Union[List[str], Dict[str, List[str]]]] = None
201
205
  max_files: Optional[int] = None
202
206
  max_size_mb: Optional[int] = None
203
207
 
204
208
 
209
+ @dataclass
210
+ class AudioFeature(DataClassJsonMixin):
211
+ min_decibels: int = -45
212
+ initial_silence_timeout: int = 2000
213
+ silence_timeout: int = 1500
214
+ chunk_duration: int = 1000
215
+ max_duration: int = 15000
216
+ sample_rate: int = 44100
217
+ enabled: bool = False
218
+
219
+
205
220
  @dataclass()
206
221
  class FeaturesSettings(DataClassJsonMixin):
207
222
  prompt_playground: bool = True
208
- multi_modal: Optional[MultiModalFeature] = None
223
+ spontaneous_file_upload: Optional[SpontaneousFileUploadFeature] = None
224
+ audio: Optional[AudioFeature] = Field(default_factory=AudioFeature)
209
225
  latex: bool = False
210
226
  unsafe_allow_html: bool = False
211
- speech_to_text: Optional[SpeechToTextFeature] = None
212
227
  auto_tag_thread: bool = True
213
228
 
214
229
 
@@ -247,7 +262,10 @@ class CodeSettings:
247
262
  on_chat_start: Optional[Callable[[], Any]] = None
248
263
  on_chat_end: Optional[Callable[[], Any]] = None
249
264
  on_chat_resume: Optional[Callable[["ThreadDict"], Any]] = None
250
- on_message: Optional[Callable[[str], Any]] = None
265
+ on_message: Optional[Callable[["Message"], Any]] = None
266
+ on_audio_chunk: Optional[Callable[["AudioChunk"], Any]] = None
267
+ on_audio_end: Optional[Callable[[List["ElementBased"]], Any]] = None
268
+
251
269
  author_rename: Optional[Callable[[str], str]] = None
252
270
  on_settings_update: Optional[Callable[[Dict[str, Any]], Any]] = None
253
271
  set_chat_profiles: Optional[Callable[[Optional["User"]], List["ChatProfile"]]] = (
@@ -413,11 +431,13 @@ def load_settings():
413
431
 
414
432
  ui_settings = UISettings(**ui_settings)
415
433
 
434
+ code_settings = CodeSettings(action_callbacks={})
435
+
416
436
  return {
417
437
  "features": features_settings,
418
438
  "ui": ui_settings,
419
439
  "project": project_settings,
420
- "code": CodeSettings(action_callbacks={}),
440
+ "code": code_settings,
421
441
  }
422
442
 
423
443