chainlit 2.0.0__py3-none-any.whl → 2.0.dev1__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 +57 -55
- chainlit/action.py +10 -12
- chainlit/{auth/__init__.py → auth.py} +34 -20
- chainlit/cache.py +1 -2
- chainlit/callbacks.py +7 -52
- chainlit/chat_context.py +2 -2
- chainlit/chat_settings.py +1 -3
- chainlit/cli/__init__.py +1 -14
- chainlit/config.py +69 -35
- chainlit/context.py +2 -3
- chainlit/copilot/dist/index.js +935 -8533
- chainlit/data/__init__.py +8 -96
- chainlit/data/acl.py +2 -3
- chainlit/data/base.py +1 -1
- chainlit/data/dynamodb.py +3 -5
- chainlit/data/literalai.py +6 -4
- chainlit/data/sql_alchemy.py +7 -8
- chainlit/data/storage_clients/azure.py +0 -1
- chainlit/data/storage_clients/base.py +0 -6
- chainlit/data/storage_clients/s3.py +3 -16
- chainlit/discord/app.py +1 -2
- chainlit/element.py +9 -13
- chainlit/emitter.py +21 -17
- chainlit/frontend/dist/assets/{DailyMotion-DgRzV5GZ.js → DailyMotion-D1ipkdPJ.js} +1 -1
- chainlit/frontend/dist/assets/{Facebook-C0vx6HWv.js → Facebook-d4TLeTik.js} +1 -1
- chainlit/frontend/dist/assets/{FilePlayer-CdhzeHPP.js → FilePlayer-BcU7tttX.js} +1 -1
- chainlit/frontend/dist/assets/{Kaltura-5iVmeUct.js → Kaltura-DdaRjZrh.js} +1 -1
- chainlit/frontend/dist/assets/{Mixcloud-C2zi77Ex.js → Mixcloud-BaJoMsaU.js} +1 -1
- chainlit/frontend/dist/assets/{Mux-Vkebogdf.js → Mux-DxPCM5d3.js} +1 -1
- chainlit/frontend/dist/assets/{Preview-DwY_sEIl.js → Preview-tUK_Z9pZ.js} +1 -1
- chainlit/frontend/dist/assets/{SoundCloud-CREBXAWo.js → SoundCloud-K8-lFZC6.js} +1 -1
- chainlit/frontend/dist/assets/{Streamable-B5Lu25uy.js → Streamable-hB-AQ54w.js} +1 -1
- chainlit/frontend/dist/assets/{Twitch-y9iKCcM1.js → Twitch-pmuNY0J5.js} +1 -1
- chainlit/frontend/dist/assets/{Vidyard-ClYvcuEu.js → Vidyard-BSUm6trV.js} +1 -1
- chainlit/frontend/dist/assets/{Vimeo-D6HvM2jt.js → Vimeo-JIPn71zS.js} +1 -1
- chainlit/frontend/dist/assets/Wistia-D75KkqOG.js +1 -0
- chainlit/frontend/dist/assets/{YouTube-D10tR6CJ.js → YouTube-CPlwqNm_.js} +1 -1
- chainlit/frontend/dist/assets/index-CuSbXjG5.js +1091 -0
- chainlit/frontend/dist/assets/index-CwmincdQ.css +1 -0
- chainlit/frontend/dist/assets/{react-plotly-BpxUS-ab.js → react-plotly-DALmanjC.js} +1 -1
- chainlit/frontend/dist/index.html +2 -2
- chainlit/haystack/callbacks.py +4 -5
- chainlit/input_widget.py +4 -6
- chainlit/langchain/callbacks.py +47 -56
- chainlit/langflow/__init__.py +0 -1
- chainlit/llama_index/callbacks.py +7 -7
- chainlit/message.py +7 -6
- chainlit/mistralai/__init__.py +2 -3
- chainlit/oauth_providers.py +3 -70
- chainlit/openai/__init__.py +2 -3
- chainlit/secret.py +1 -1
- chainlit/server.py +174 -474
- chainlit/session.py +5 -7
- chainlit/slack/app.py +2 -3
- chainlit/socket.py +103 -78
- chainlit/step.py +11 -11
- chainlit/sync.py +1 -2
- chainlit/teams/app.py +0 -1
- chainlit/types.py +4 -20
- chainlit/user.py +1 -2
- chainlit/utils.py +2 -3
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev1.dist-info}/METADATA +38 -8
- chainlit-2.0.dev1.dist-info/RECORD +99 -0
- chainlit/auth/cookie.py +0 -123
- chainlit/auth/jwt.py +0 -37
- chainlit/data/chainlit_data_layer.py +0 -584
- chainlit/data/storage_clients/azure_blob.py +0 -80
- chainlit/data/storage_clients/gcs.py +0 -78
- chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +0 -22
- chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +0 -1
- chainlit/frontend/dist/assets/index-CI4qFOt5.js +0 -8665
- chainlit/frontend/dist/assets/index-CrrqM0nZ.css +0 -1
- chainlit/translations/nl-NL.json +0 -229
- chainlit-2.0.0.dist-info/RECORD +0 -106
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev1.dist-info}/WHEEL +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev1.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py
CHANGED
|
@@ -14,9 +14,6 @@ if env_found:
|
|
|
14
14
|
import asyncio
|
|
15
15
|
from typing import TYPE_CHECKING, Any, Dict
|
|
16
16
|
|
|
17
|
-
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
18
|
-
from pydantic.dataclasses import dataclass
|
|
19
|
-
|
|
20
17
|
import chainlit.input_widget as input_widget
|
|
21
18
|
from chainlit.action import Action
|
|
22
19
|
from chainlit.cache import cache
|
|
@@ -25,7 +22,7 @@ from chainlit.chat_settings import ChatSettings
|
|
|
25
22
|
from chainlit.context import context
|
|
26
23
|
from chainlit.element import (
|
|
27
24
|
Audio,
|
|
28
|
-
|
|
25
|
+
Component,
|
|
29
26
|
Dataframe,
|
|
30
27
|
File,
|
|
31
28
|
Image,
|
|
@@ -47,21 +44,22 @@ from chainlit.message import (
|
|
|
47
44
|
)
|
|
48
45
|
from chainlit.step import Step, step
|
|
49
46
|
from chainlit.sync import make_async, run_sync
|
|
50
|
-
from chainlit.types import
|
|
47
|
+
from chainlit.types import InputAudioChunk, OutputAudioChunk, ChatProfile, Starter
|
|
51
48
|
from chainlit.user import PersistedUser, User
|
|
52
49
|
from chainlit.user_session import user_session
|
|
53
50
|
from chainlit.utils import make_module_getattr
|
|
54
51
|
from chainlit.version import __version__
|
|
52
|
+
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
53
|
+
from pydantic.dataclasses import dataclass
|
|
55
54
|
|
|
56
55
|
from .callbacks import (
|
|
57
56
|
action_callback,
|
|
58
57
|
author_rename,
|
|
59
|
-
data_layer,
|
|
60
58
|
header_auth_callback,
|
|
61
59
|
oauth_callback,
|
|
60
|
+
on_audio_start,
|
|
62
61
|
on_audio_chunk,
|
|
63
62
|
on_audio_end,
|
|
64
|
-
on_audio_start,
|
|
65
63
|
on_chat_end,
|
|
66
64
|
on_chat_resume,
|
|
67
65
|
on_chat_start,
|
|
@@ -69,9 +67,7 @@ from .callbacks import (
|
|
|
69
67
|
on_message,
|
|
70
68
|
on_settings_update,
|
|
71
69
|
on_stop,
|
|
72
|
-
on_window_message,
|
|
73
70
|
password_auth_callback,
|
|
74
|
-
send_window_message,
|
|
75
71
|
set_chat_profiles,
|
|
76
72
|
set_starters,
|
|
77
73
|
)
|
|
@@ -117,73 +113,79 @@ __getattr__ = make_module_getattr(
|
|
|
117
113
|
)
|
|
118
114
|
|
|
119
115
|
__all__ = [
|
|
120
|
-
"
|
|
121
|
-
"AskActionMessage",
|
|
122
|
-
"AskFileMessage",
|
|
123
|
-
"AskUserMessage",
|
|
124
|
-
"AsyncLangchainCallbackHandler",
|
|
125
|
-
"Audio",
|
|
126
|
-
"ChatGeneration",
|
|
116
|
+
"__version__",
|
|
127
117
|
"ChatProfile",
|
|
128
|
-
"
|
|
129
|
-
"
|
|
118
|
+
"Starter",
|
|
119
|
+
"user_session",
|
|
120
|
+
"chat_context",
|
|
130
121
|
"CopilotFunction",
|
|
131
|
-
"CustomElement",
|
|
132
|
-
"Dataframe",
|
|
133
|
-
"ErrorMessage",
|
|
134
|
-
"File",
|
|
135
|
-
"GenerationMessage",
|
|
136
|
-
"HaystackAgentCallbackHandler",
|
|
137
|
-
"Image",
|
|
138
122
|
"InputAudioChunk",
|
|
139
|
-
"LangchainCallbackHandler",
|
|
140
|
-
"LlamaIndexCallbackHandler",
|
|
141
|
-
"Message",
|
|
142
123
|
"OutputAudioChunk",
|
|
143
|
-
"
|
|
124
|
+
"Action",
|
|
125
|
+
"User",
|
|
144
126
|
"PersistedUser",
|
|
127
|
+
"Audio",
|
|
128
|
+
"Pdf",
|
|
145
129
|
"Plotly",
|
|
130
|
+
"Image",
|
|
131
|
+
"Text",
|
|
132
|
+
"Component",
|
|
146
133
|
"Pyplot",
|
|
147
|
-
"
|
|
148
|
-
"Step",
|
|
134
|
+
"File",
|
|
149
135
|
"Task",
|
|
150
136
|
"TaskList",
|
|
151
137
|
"TaskStatus",
|
|
152
|
-
"Text",
|
|
153
|
-
"User",
|
|
154
138
|
"Video",
|
|
155
|
-
"
|
|
139
|
+
"ChatSettings",
|
|
140
|
+
"input_widget",
|
|
141
|
+
"Message",
|
|
142
|
+
"ErrorMessage",
|
|
143
|
+
"AskUserMessage",
|
|
144
|
+
"AskActionMessage",
|
|
145
|
+
"AskFileMessage",
|
|
146
|
+
"Step",
|
|
147
|
+
"step",
|
|
148
|
+
"ChatGeneration",
|
|
149
|
+
"CompletionGeneration",
|
|
150
|
+
"GenerationMessage",
|
|
151
|
+
"on_logout",
|
|
152
|
+
"on_chat_start",
|
|
153
|
+
"on_chat_end",
|
|
154
|
+
"on_chat_resume",
|
|
155
|
+
"on_stop",
|
|
156
156
|
"action_callback",
|
|
157
157
|
"author_rename",
|
|
158
|
+
"on_settings_update",
|
|
159
|
+
"password_auth_callback",
|
|
160
|
+
"header_auth_callback",
|
|
161
|
+
"sleep",
|
|
162
|
+
"run_sync",
|
|
163
|
+
"make_async",
|
|
158
164
|
"cache",
|
|
159
|
-
"chat_context",
|
|
160
165
|
"context",
|
|
161
|
-
"
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
166
|
+
"LangchainCallbackHandler",
|
|
167
|
+
"AsyncLangchainCallbackHandler",
|
|
168
|
+
"LlamaIndexCallbackHandler",
|
|
169
|
+
"HaystackAgentCallbackHandler",
|
|
165
170
|
"instrument_openai",
|
|
166
|
-
"
|
|
171
|
+
"instrument_mistralai",
|
|
172
|
+
"password_auth_callback",
|
|
173
|
+
"header_auth_callback",
|
|
167
174
|
"oauth_callback",
|
|
168
|
-
"on_audio_chunk",
|
|
169
|
-
"on_audio_end",
|
|
170
|
-
"on_audio_start",
|
|
171
|
-
"on_chat_end",
|
|
172
|
-
"on_chat_resume",
|
|
173
|
-
"on_chat_start",
|
|
174
175
|
"on_logout",
|
|
175
176
|
"on_message",
|
|
176
|
-
"
|
|
177
|
-
"
|
|
178
|
-
"on_window_message",
|
|
179
|
-
"password_auth_callback",
|
|
180
|
-
"run_sync",
|
|
181
|
-
"send_window_message",
|
|
177
|
+
"on_chat_start",
|
|
178
|
+
"on_chat_resume",
|
|
182
179
|
"set_chat_profiles",
|
|
183
180
|
"set_starters",
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
181
|
+
"on_chat_end",
|
|
182
|
+
"on_audio_start",
|
|
183
|
+
"on_audio_chunk",
|
|
184
|
+
"on_audio_end",
|
|
185
|
+
"author_rename",
|
|
186
|
+
"on_stop",
|
|
187
|
+
"action_callback",
|
|
188
|
+
"on_settings_update",
|
|
187
189
|
]
|
|
188
190
|
|
|
189
191
|
|
chainlit/action.py
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import uuid
|
|
2
|
-
from typing import
|
|
3
|
-
|
|
4
|
-
from dataclasses_json import DataClassJsonMixin
|
|
5
|
-
from pydantic import Field
|
|
6
|
-
from pydantic.dataclasses import dataclass
|
|
2
|
+
from typing import Optional
|
|
7
3
|
|
|
8
4
|
from chainlit.context import context
|
|
9
5
|
from chainlit.telemetry import trace_event
|
|
6
|
+
from dataclasses_json import DataClassJsonMixin
|
|
7
|
+
from pydantic.dataclasses import Field, dataclass
|
|
10
8
|
|
|
11
9
|
|
|
12
10
|
@dataclass
|
|
13
11
|
class Action(DataClassJsonMixin):
|
|
14
12
|
# Name of the action, this should be used in the action_callback
|
|
15
13
|
name: str
|
|
16
|
-
# The
|
|
17
|
-
|
|
18
|
-
# The label of the action. This is what the user will see.
|
|
14
|
+
# The value associated with the action. This is useful to differentiate between multiple actions with the same name.
|
|
15
|
+
value: str
|
|
16
|
+
# The label of the action. This is what the user will see. If not provided the name will be used.
|
|
19
17
|
label: str = ""
|
|
20
|
-
# The
|
|
21
|
-
|
|
22
|
-
# The lucid icon name for this action.
|
|
23
|
-
icon: Optional[str] = None
|
|
18
|
+
# The description of the action. This is what the user will see when they hover the action.
|
|
19
|
+
description: str = ""
|
|
24
20
|
# This should not be set manually, only used internally.
|
|
25
21
|
forId: Optional[str] = None
|
|
26
22
|
# The ID of the action
|
|
27
23
|
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
|
|
24
|
+
# Show the action in a drawer menu
|
|
25
|
+
collapsed: bool = False
|
|
28
26
|
|
|
29
27
|
def __post_init__(self) -> None:
|
|
30
28
|
trace_event(f"init {self.__class__.__name__}")
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import os
|
|
2
|
+
from datetime import datetime, timedelta
|
|
3
|
+
from typing import Any, Dict
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
import jwt
|
|
5
6
|
from chainlit.config import config
|
|
6
7
|
from chainlit.data import get_data_layer
|
|
7
|
-
from chainlit.logger import logger
|
|
8
8
|
from chainlit.oauth_providers import get_configured_oauth_providers
|
|
9
|
+
from chainlit.user import User
|
|
10
|
+
from fastapi import Depends, HTTPException
|
|
11
|
+
from fastapi.security import OAuth2PasswordBearer
|
|
12
|
+
|
|
13
|
+
reuseable_oauth = OAuth2PasswordBearer(tokenUrl="/login", auto_error=False)
|
|
9
14
|
|
|
10
|
-
from .cookie import OAuth2PasswordBearerWithCookie
|
|
11
|
-
from .jwt import create_jwt, decode_jwt, get_jwt_secret
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
def get_jwt_secret():
|
|
17
|
+
return os.environ.get("CHAINLIT_AUTH_SECRET")
|
|
14
18
|
|
|
15
19
|
|
|
16
20
|
def ensure_jwt_secret():
|
|
@@ -41,36 +45,49 @@ def get_configuration():
|
|
|
41
45
|
"oauthProviders": (
|
|
42
46
|
get_configured_oauth_providers() if is_oauth_enabled() else []
|
|
43
47
|
),
|
|
44
|
-
"default_theme": config.ui.default_theme,
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
|
|
51
|
+
def create_jwt(data: User) -> str:
|
|
52
|
+
to_encode: Dict[str, Any] = data.to_dict()
|
|
53
|
+
to_encode.update(
|
|
54
|
+
{
|
|
55
|
+
"exp": datetime.utcnow() + timedelta(
|
|
56
|
+
seconds=config.project.user_session_timeout
|
|
57
|
+
),
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
encoded_jwt = jwt.encode(to_encode, get_jwt_secret(), algorithm="HS256")
|
|
61
|
+
return encoded_jwt
|
|
62
|
+
|
|
63
|
+
|
|
48
64
|
async def authenticate_user(token: str = Depends(reuseable_oauth)):
|
|
49
65
|
try:
|
|
50
|
-
|
|
66
|
+
dict = jwt.decode(
|
|
67
|
+
token,
|
|
68
|
+
get_jwt_secret(),
|
|
69
|
+
algorithms=["HS256"],
|
|
70
|
+
options={"verify_signature": True},
|
|
71
|
+
)
|
|
72
|
+
del dict["exp"]
|
|
73
|
+
user = User(**dict)
|
|
51
74
|
except Exception as e:
|
|
52
75
|
raise HTTPException(
|
|
53
76
|
status_code=401, detail="Invalid authentication token"
|
|
54
77
|
) from e
|
|
55
|
-
|
|
56
78
|
if data_layer := get_data_layer():
|
|
57
|
-
# Get or create persistent user if we've a data layer available.
|
|
58
79
|
try:
|
|
59
80
|
persisted_user = await data_layer.get_user(user.identifier)
|
|
60
81
|
if persisted_user is None:
|
|
61
82
|
persisted_user = await data_layer.create_user(user)
|
|
62
|
-
|
|
63
|
-
except Exception as e:
|
|
64
|
-
logger.exception("Unable to get persisted_user from data layer: %s", e)
|
|
83
|
+
except Exception:
|
|
65
84
|
return user
|
|
66
85
|
|
|
67
86
|
if user and user.display_name:
|
|
68
|
-
# Copy ephemeral display_name from authenticated user to persistent user.
|
|
69
87
|
persisted_user.display_name = user.display_name
|
|
70
|
-
|
|
71
88
|
return persisted_user
|
|
72
|
-
|
|
73
|
-
|
|
89
|
+
else:
|
|
90
|
+
return user
|
|
74
91
|
|
|
75
92
|
|
|
76
93
|
async def get_current_user(token: str = Depends(reuseable_oauth)):
|
|
@@ -78,6 +95,3 @@ async def get_current_user(token: str = Depends(reuseable_oauth)):
|
|
|
78
95
|
return None
|
|
79
96
|
|
|
80
97
|
return await authenticate_user(token)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
__all__ = ["create_jwt", "get_configuration", "get_current_user"]
|
chainlit/cache.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import importlib.util
|
|
2
2
|
import os
|
|
3
3
|
import threading
|
|
4
|
-
from typing import Any
|
|
5
4
|
|
|
6
5
|
from chainlit.config import config
|
|
7
6
|
from chainlit.logger import logger
|
|
@@ -23,7 +22,7 @@ def init_lc_cache():
|
|
|
23
22
|
)
|
|
24
23
|
|
|
25
24
|
|
|
26
|
-
_cache
|
|
25
|
+
_cache = {}
|
|
27
26
|
_cache_lock = threading.Lock()
|
|
28
27
|
|
|
29
28
|
|
chainlit/callbacks.py
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
from typing import Any, Awaitable, Callable, Dict, List, Optional
|
|
3
3
|
|
|
4
|
-
from fastapi import Request, Response
|
|
5
|
-
from starlette.datastructures import Headers
|
|
6
|
-
|
|
7
4
|
from chainlit.action import Action
|
|
8
5
|
from chainlit.config import config
|
|
9
|
-
from chainlit.context import context
|
|
10
|
-
from chainlit.data.base import BaseDataLayer
|
|
11
6
|
from chainlit.message import Message
|
|
12
7
|
from chainlit.oauth_providers import get_configured_oauth_providers
|
|
13
8
|
from chainlit.step import Step, step
|
|
@@ -15,11 +10,13 @@ from chainlit.telemetry import trace
|
|
|
15
10
|
from chainlit.types import ChatProfile, Starter, ThreadDict
|
|
16
11
|
from chainlit.user import User
|
|
17
12
|
from chainlit.utils import wrap_user_function
|
|
13
|
+
from fastapi import Request, Response
|
|
14
|
+
from starlette.datastructures import Headers
|
|
18
15
|
|
|
19
16
|
|
|
20
17
|
@trace
|
|
21
18
|
def password_auth_callback(
|
|
22
|
-
func: Callable[[str, str], Awaitable[Optional[User]]]
|
|
19
|
+
func: Callable[[str, str], Awaitable[Optional[User]]]
|
|
23
20
|
) -> Callable:
|
|
24
21
|
"""
|
|
25
22
|
Framework agnostic decorator to authenticate the user.
|
|
@@ -41,7 +38,7 @@ def password_auth_callback(
|
|
|
41
38
|
|
|
42
39
|
@trace
|
|
43
40
|
def header_auth_callback(
|
|
44
|
-
func: Callable[[Headers], Awaitable[Optional[User]]]
|
|
41
|
+
func: Callable[[Headers], Awaitable[Optional[User]]]
|
|
45
42
|
) -> Callable:
|
|
46
43
|
"""
|
|
47
44
|
Framework agnostic decorator to authenticate the user via a header
|
|
@@ -126,33 +123,6 @@ def on_message(func: Callable) -> Callable:
|
|
|
126
123
|
return func
|
|
127
124
|
|
|
128
125
|
|
|
129
|
-
@trace
|
|
130
|
-
async def send_window_message(data: Any):
|
|
131
|
-
"""
|
|
132
|
-
Send custom data to the host window via a window.postMessage event.
|
|
133
|
-
|
|
134
|
-
Args:
|
|
135
|
-
data (Any): The data to send with the event.
|
|
136
|
-
"""
|
|
137
|
-
await context.emitter.send_window_message(data)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
@trace
|
|
141
|
-
def on_window_message(func: Callable[[str], Any]) -> Callable:
|
|
142
|
-
"""
|
|
143
|
-
Hook to react to javascript postMessage events coming from the UI.
|
|
144
|
-
|
|
145
|
-
Args:
|
|
146
|
-
func (Callable[[str], Any]): The function to be called when a window message is received.
|
|
147
|
-
Takes the message content as a string parameter.
|
|
148
|
-
|
|
149
|
-
Returns:
|
|
150
|
-
Callable[[str], Any]: The decorated on_window_message function.
|
|
151
|
-
"""
|
|
152
|
-
config.code.on_window_message = wrap_user_function(func)
|
|
153
|
-
return func
|
|
154
|
-
|
|
155
|
-
|
|
156
126
|
@trace
|
|
157
127
|
def on_chat_start(func: Callable) -> Callable:
|
|
158
128
|
"""
|
|
@@ -207,7 +177,7 @@ def set_chat_profiles(
|
|
|
207
177
|
|
|
208
178
|
@trace
|
|
209
179
|
def set_starters(
|
|
210
|
-
func: Callable[[Optional["User"]], Awaitable[List["Starter"]]]
|
|
180
|
+
func: Callable[[Optional["User"]], Awaitable[List["Starter"]]]
|
|
211
181
|
) -> Callable:
|
|
212
182
|
"""
|
|
213
183
|
Programmatic declaration of the available starter (can depend on the User from the session if authentication is setup).
|
|
@@ -251,7 +221,6 @@ def on_audio_start(func: Callable) -> Callable:
|
|
|
251
221
|
config.code.on_audio_start = wrap_user_function(func, with_task=False)
|
|
252
222
|
return func
|
|
253
223
|
|
|
254
|
-
|
|
255
224
|
@trace
|
|
256
225
|
def on_audio_chunk(func: Callable) -> Callable:
|
|
257
226
|
"""
|
|
@@ -285,7 +254,7 @@ def on_audio_end(func: Callable) -> Callable:
|
|
|
285
254
|
|
|
286
255
|
@trace
|
|
287
256
|
def author_rename(
|
|
288
|
-
func: Callable[[str], Awaitable[str]]
|
|
257
|
+
func: Callable[[str], Awaitable[str]]
|
|
289
258
|
) -> Callable[[str], Awaitable[str]]:
|
|
290
259
|
"""
|
|
291
260
|
Useful to rename the author of message to display more friendly author names in the UI.
|
|
@@ -325,7 +294,7 @@ def action_callback(name: str) -> Callable:
|
|
|
325
294
|
"""
|
|
326
295
|
|
|
327
296
|
def decorator(func: Callable[[Action], Any]):
|
|
328
|
-
config.code.action_callbacks[name] = wrap_user_function(func, with_task=
|
|
297
|
+
config.code.action_callbacks[name] = wrap_user_function(func, with_task=True)
|
|
329
298
|
return func
|
|
330
299
|
|
|
331
300
|
return decorator
|
|
@@ -346,17 +315,3 @@ def on_settings_update(
|
|
|
346
315
|
|
|
347
316
|
config.code.on_settings_update = wrap_user_function(func, with_task=True)
|
|
348
317
|
return func
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
def data_layer(
|
|
352
|
-
func: Callable[[], BaseDataLayer],
|
|
353
|
-
) -> Callable[[], BaseDataLayer]:
|
|
354
|
-
"""
|
|
355
|
-
Hook to configure custom data layer.
|
|
356
|
-
"""
|
|
357
|
-
|
|
358
|
-
# We don't use wrap_user_function here because:
|
|
359
|
-
# 1. We don't need to support async here and;
|
|
360
|
-
# 2. We don't want to change the API for get_data_layer() to be async, everywhere (at this point).
|
|
361
|
-
config.code.data_layer = func
|
|
362
|
-
return func
|
chainlit/chat_context.py
CHANGED
|
@@ -25,10 +25,10 @@ class ChatContext:
|
|
|
25
25
|
|
|
26
26
|
if context.session.id not in chat_contexts:
|
|
27
27
|
chat_contexts[context.session.id] = []
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
if message not in chat_contexts[context.session.id]:
|
|
30
30
|
chat_contexts[context.session.id].append(message)
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
return message
|
|
33
33
|
|
|
34
34
|
def remove(self, message: "Message") -> bool:
|
chainlit/chat_settings.py
CHANGED
chainlit/cli/__init__.py
CHANGED
|
@@ -9,7 +9,6 @@ import uvicorn
|
|
|
9
9
|
nest_asyncio.apply()
|
|
10
10
|
|
|
11
11
|
# ruff: noqa: E402
|
|
12
|
-
from chainlit.auth import ensure_jwt_secret
|
|
13
12
|
from chainlit.cache import init_lc_cache
|
|
14
13
|
from chainlit.config import (
|
|
15
14
|
BACKEND_ROOT,
|
|
@@ -25,18 +24,7 @@ from chainlit.logger import logger
|
|
|
25
24
|
from chainlit.markdown import init_markdown
|
|
26
25
|
from chainlit.secret import random_secret
|
|
27
26
|
from chainlit.telemetry import trace_event
|
|
28
|
-
from chainlit.utils import check_file
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def assert_app():
|
|
32
|
-
if (
|
|
33
|
-
not config.code.on_chat_start
|
|
34
|
-
and not config.code.on_message
|
|
35
|
-
and not config.code.on_audio_chunk
|
|
36
|
-
):
|
|
37
|
-
raise Exception(
|
|
38
|
-
"You need to configure at least one of on_chat_start, on_message or on_audio_chunk callback"
|
|
39
|
-
)
|
|
27
|
+
from chainlit.utils import check_file, ensure_jwt_secret
|
|
40
28
|
|
|
41
29
|
|
|
42
30
|
# Create the main command group for Chainlit CLI
|
|
@@ -78,7 +66,6 @@ def run_chainlit(target: str):
|
|
|
78
66
|
load_module(config.run.module_name)
|
|
79
67
|
|
|
80
68
|
ensure_jwt_secret()
|
|
81
|
-
assert_app()
|
|
82
69
|
|
|
83
70
|
# Create the chainlit.md file if it doesn't exist
|
|
84
71
|
init_markdown(config.root)
|