|
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 | 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 |
|
|
0 commit comments