chainlit 0.7.604rc2__py3-none-any.whl → 1.0.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 +32 -23
- chainlit/auth.py +9 -10
- chainlit/cache.py +3 -3
- chainlit/cli/__init__.py +12 -2
- chainlit/config.py +22 -13
- chainlit/context.py +7 -3
- chainlit/data/__init__.py +375 -9
- chainlit/data/acl.py +6 -5
- chainlit/element.py +86 -123
- chainlit/emitter.py +117 -50
- chainlit/frontend/dist/assets/index-6aee009a.js +697 -0
- chainlit/frontend/dist/assets/{react-plotly-16f7de12.js → react-plotly-2f07c02a.js} +1 -1
- chainlit/frontend/dist/index.html +1 -1
- chainlit/haystack/callbacks.py +45 -43
- chainlit/hello.py +1 -1
- chainlit/langchain/callbacks.py +135 -120
- chainlit/llama_index/callbacks.py +68 -48
- chainlit/message.py +179 -207
- chainlit/oauth_providers.py +39 -34
- chainlit/playground/provider.py +44 -30
- chainlit/playground/providers/anthropic.py +4 -4
- chainlit/playground/providers/huggingface.py +2 -2
- chainlit/playground/providers/langchain.py +8 -10
- chainlit/playground/providers/openai.py +19 -13
- chainlit/server.py +155 -99
- chainlit/session.py +109 -40
- chainlit/socket.py +54 -38
- chainlit/step.py +393 -0
- chainlit/types.py +78 -21
- chainlit/user.py +32 -0
- chainlit/user_session.py +1 -5
- {chainlit-0.7.604rc2.dist-info → chainlit-1.0.0rc0.dist-info}/METADATA +12 -31
- chainlit-1.0.0rc0.dist-info/RECORD +60 -0
- chainlit/client/base.py +0 -169
- chainlit/client/cloud.py +0 -500
- chainlit/frontend/dist/assets/index-c58dbd4b.js +0 -871
- chainlit/prompt.py +0 -40
- chainlit-0.7.604rc2.dist-info/RECORD +0 -61
- {chainlit-0.7.604rc2.dist-info → chainlit-1.0.0rc0.dist-info}/WHEEL +0 -0
- {chainlit-0.7.604rc2.dist-info → chainlit-1.0.0rc0.dist-info}/entry_points.txt +0 -0
chainlit/__init__.py
CHANGED
|
@@ -5,7 +5,7 @@ from dotenv import load_dotenv
|
|
|
5
5
|
env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
|
|
6
6
|
|
|
7
7
|
import asyncio
|
|
8
|
-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
|
9
9
|
|
|
10
10
|
from starlette.datastructures import Headers
|
|
11
11
|
|
|
@@ -21,8 +21,8 @@ import chainlit.input_widget as input_widget
|
|
|
21
21
|
from chainlit.action import Action
|
|
22
22
|
from chainlit.cache import cache
|
|
23
23
|
from chainlit.chat_settings import ChatSettings
|
|
24
|
-
from chainlit.client.base import AppUser, ConversationDict, PersistedAppUser
|
|
25
24
|
from chainlit.config import config
|
|
25
|
+
from chainlit.context import context
|
|
26
26
|
from chainlit.element import (
|
|
27
27
|
Audio,
|
|
28
28
|
Avatar,
|
|
@@ -46,31 +46,34 @@ from chainlit.message import (
|
|
|
46
46
|
Message,
|
|
47
47
|
)
|
|
48
48
|
from chainlit.oauth_providers import get_configured_oauth_providers
|
|
49
|
+
from chainlit.step import Step, step
|
|
49
50
|
from chainlit.sync import make_async, run_sync
|
|
50
51
|
from chainlit.telemetry import trace
|
|
51
|
-
from chainlit.types import ChatProfile,
|
|
52
|
+
from chainlit.types import ChatProfile, ThreadDict
|
|
53
|
+
from chainlit.user import PersistedUser, User
|
|
52
54
|
from chainlit.user_session import user_session
|
|
53
55
|
from chainlit.utils import make_module_getattr, wrap_user_function
|
|
54
56
|
from chainlit.version import __version__
|
|
57
|
+
from chainlit_client import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
55
58
|
|
|
56
59
|
if env_found:
|
|
57
60
|
logger.info("Loaded .env file")
|
|
58
61
|
|
|
59
62
|
|
|
60
63
|
@trace
|
|
61
|
-
def password_auth_callback(func: Callable[[str, str], Optional[
|
|
64
|
+
def password_auth_callback(func: Callable[[str, str], Optional[User]]) -> Callable:
|
|
62
65
|
"""
|
|
63
66
|
Framework agnostic decorator to authenticate the user.
|
|
64
67
|
|
|
65
68
|
Args:
|
|
66
|
-
func (Callable[[str, str], Optional[
|
|
69
|
+
func (Callable[[str, str], Optional[User]]): The authentication callback to execute. Takes the email and password as parameters.
|
|
67
70
|
|
|
68
71
|
Example:
|
|
69
72
|
@cl.password_auth_callback
|
|
70
|
-
async def password_auth_callback(username: str, password: str) -> Optional[
|
|
73
|
+
async def password_auth_callback(username: str, password: str) -> Optional[User]:
|
|
71
74
|
|
|
72
75
|
Returns:
|
|
73
|
-
Callable[[str, str], Optional[
|
|
76
|
+
Callable[[str, str], Optional[User]]: The decorated authentication callback.
|
|
74
77
|
"""
|
|
75
78
|
|
|
76
79
|
config.code.password_auth_callback = wrap_user_function(func)
|
|
@@ -78,19 +81,19 @@ def password_auth_callback(func: Callable[[str, str], Optional[AppUser]]) -> Cal
|
|
|
78
81
|
|
|
79
82
|
|
|
80
83
|
@trace
|
|
81
|
-
def header_auth_callback(func: Callable[[Headers], Optional[
|
|
84
|
+
def header_auth_callback(func: Callable[[Headers], Optional[User]]) -> Callable:
|
|
82
85
|
"""
|
|
83
86
|
Framework agnostic decorator to authenticate the user via a header
|
|
84
87
|
|
|
85
88
|
Args:
|
|
86
|
-
func (Callable[[Headers], Optional[
|
|
89
|
+
func (Callable[[Headers], Optional[User]]): The authentication callback to execute.
|
|
87
90
|
|
|
88
91
|
Example:
|
|
89
92
|
@cl.header_auth_callback
|
|
90
|
-
async def header_auth_callback(headers: Headers) -> Optional[
|
|
93
|
+
async def header_auth_callback(headers: Headers) -> Optional[User]:
|
|
91
94
|
|
|
92
95
|
Returns:
|
|
93
|
-
Callable[[Headers], Optional[
|
|
96
|
+
Callable[[Headers], Optional[User]]: The decorated authentication callback.
|
|
94
97
|
"""
|
|
95
98
|
|
|
96
99
|
config.code.header_auth_callback = wrap_user_function(func)
|
|
@@ -99,20 +102,20 @@ def header_auth_callback(func: Callable[[Headers], Optional[AppUser]]) -> Callab
|
|
|
99
102
|
|
|
100
103
|
@trace
|
|
101
104
|
def oauth_callback(
|
|
102
|
-
func: Callable[[str, str, Dict[str, str],
|
|
105
|
+
func: Callable[[str, str, Dict[str, str], User], Optional[User]]
|
|
103
106
|
) -> Callable:
|
|
104
107
|
"""
|
|
105
108
|
Framework agnostic decorator to authenticate the user via oauth
|
|
106
109
|
|
|
107
110
|
Args:
|
|
108
|
-
func (Callable[[str, str, Dict[str, str],
|
|
111
|
+
func (Callable[[str, str, Dict[str, str], User], Optional[User]]): The authentication callback to execute.
|
|
109
112
|
|
|
110
113
|
Example:
|
|
111
114
|
@cl.oauth_callback
|
|
112
|
-
async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user:
|
|
115
|
+
async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: User) -> Optional[User]:
|
|
113
116
|
|
|
114
117
|
Returns:
|
|
115
|
-
Callable[[str, str, Dict[str, str],
|
|
118
|
+
Callable[[str, str, Dict[str, str], User], Optional[User]]: The decorated authentication callback.
|
|
116
119
|
"""
|
|
117
120
|
|
|
118
121
|
if len(get_configured_oauth_providers()) == 0:
|
|
@@ -158,7 +161,7 @@ def on_chat_start(func: Callable) -> Callable:
|
|
|
158
161
|
|
|
159
162
|
|
|
160
163
|
@trace
|
|
161
|
-
def on_chat_resume(func: Callable[[
|
|
164
|
+
def on_chat_resume(func: Callable[[ThreadDict], Any]) -> Callable:
|
|
162
165
|
"""
|
|
163
166
|
Hook to react to resume websocket connection event.
|
|
164
167
|
|
|
@@ -175,16 +178,16 @@ def on_chat_resume(func: Callable[[ConversationDict], Any]) -> Callable:
|
|
|
175
178
|
|
|
176
179
|
@trace
|
|
177
180
|
def set_chat_profiles(
|
|
178
|
-
func: Callable[[Optional["
|
|
181
|
+
func: Callable[[Optional["User"]], List["ChatProfile"]]
|
|
179
182
|
) -> Callable:
|
|
180
183
|
"""
|
|
181
|
-
Programmatic declaration of the available chat profiles (can depend on the
|
|
184
|
+
Programmatic declaration of the available chat profiles (can depend on the User from the session if authentication is setup).
|
|
182
185
|
|
|
183
186
|
Args:
|
|
184
|
-
func (Callable[[Optional["
|
|
187
|
+
func (Callable[[Optional["User"]], List["ChatProfile"]]): The function declaring the chat profiles.
|
|
185
188
|
|
|
186
189
|
Returns:
|
|
187
|
-
Callable[[Optional["
|
|
190
|
+
Callable[[Optional["User"]], List["ChatProfile"]]: The decorated function.
|
|
188
191
|
"""
|
|
189
192
|
|
|
190
193
|
config.code.set_chat_profiles = wrap_user_function(func)
|
|
@@ -225,7 +228,7 @@ def author_rename(func: Callable[[str], str]) -> Callable[[str], str]:
|
|
|
225
228
|
@trace
|
|
226
229
|
def on_stop(func: Callable) -> Callable:
|
|
227
230
|
"""
|
|
228
|
-
Hook to react to the user stopping a
|
|
231
|
+
Hook to react to the user stopping a thread.
|
|
229
232
|
|
|
230
233
|
Args:
|
|
231
234
|
func (Callable[[], Any]): The stop hook to execute.
|
|
@@ -291,8 +294,8 @@ __getattr__ = make_module_getattr(
|
|
|
291
294
|
__all__ = [
|
|
292
295
|
"user_session",
|
|
293
296
|
"Action",
|
|
294
|
-
"
|
|
295
|
-
"
|
|
297
|
+
"User",
|
|
298
|
+
"PersistedUser",
|
|
296
299
|
"Audio",
|
|
297
300
|
"Pdf",
|
|
298
301
|
"Plotly",
|
|
@@ -312,6 +315,11 @@ __all__ = [
|
|
|
312
315
|
"AskUserMessage",
|
|
313
316
|
"AskActionMessage",
|
|
314
317
|
"AskFileMessage",
|
|
318
|
+
"Step",
|
|
319
|
+
"step",
|
|
320
|
+
"ChatGeneration",
|
|
321
|
+
"CompletionGeneration",
|
|
322
|
+
"GenerationMessage",
|
|
315
323
|
"on_chat_start",
|
|
316
324
|
"on_chat_end",
|
|
317
325
|
"on_chat_resume",
|
|
@@ -325,6 +333,7 @@ __all__ = [
|
|
|
325
333
|
"run_sync",
|
|
326
334
|
"make_async",
|
|
327
335
|
"cache",
|
|
336
|
+
"context",
|
|
328
337
|
"LangchainCallbackHandler",
|
|
329
338
|
"AsyncLangchainCallbackHandler",
|
|
330
339
|
"LlamaIndexCallbackHandler",
|
chainlit/auth.py
CHANGED
|
@@ -3,10 +3,10 @@ from datetime import datetime, timedelta
|
|
|
3
3
|
from typing import Any, Dict
|
|
4
4
|
|
|
5
5
|
import jwt
|
|
6
|
-
from chainlit.client.cloud import AppUser
|
|
7
6
|
from chainlit.config import config
|
|
8
|
-
from chainlit.data import
|
|
7
|
+
from chainlit.data import get_data_layer
|
|
9
8
|
from chainlit.oauth_providers import get_configured_oauth_providers
|
|
9
|
+
from chainlit.user import User
|
|
10
10
|
from fastapi import Depends, HTTPException
|
|
11
11
|
from fastapi.security import OAuth2PasswordBearer
|
|
12
12
|
|
|
@@ -47,7 +47,7 @@ def get_configuration():
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
def create_jwt(data:
|
|
50
|
+
def create_jwt(data: User) -> str:
|
|
51
51
|
to_encode = data.to_dict() # type: Dict[str, Any]
|
|
52
52
|
to_encode.update(
|
|
53
53
|
{
|
|
@@ -67,21 +67,20 @@ async def authenticate_user(token: str = Depends(reuseable_oauth)):
|
|
|
67
67
|
options={"verify_signature": True},
|
|
68
68
|
)
|
|
69
69
|
del dict["exp"]
|
|
70
|
-
|
|
70
|
+
user = User(**dict)
|
|
71
71
|
except Exception as e:
|
|
72
72
|
raise HTTPException(status_code=401, detail="Invalid authentication token")
|
|
73
|
-
|
|
74
|
-
if chainlit_client:
|
|
73
|
+
if data_layer := get_data_layer():
|
|
75
74
|
try:
|
|
76
|
-
|
|
75
|
+
persisted_user = await data_layer.get_user(user.identifier)
|
|
77
76
|
except Exception as e:
|
|
78
77
|
raise HTTPException(status_code=500, detail=str(e))
|
|
79
|
-
if
|
|
78
|
+
if persisted_user == None:
|
|
80
79
|
raise HTTPException(status_code=401, detail="User does not exist")
|
|
81
80
|
|
|
82
|
-
return
|
|
81
|
+
return persisted_user
|
|
83
82
|
else:
|
|
84
|
-
return
|
|
83
|
+
return user
|
|
85
84
|
|
|
86
85
|
|
|
87
86
|
async def get_current_user(token: str = Depends(reuseable_oauth)):
|
chainlit/cache.py
CHANGED
|
@@ -14,11 +14,11 @@ def init_lc_cache():
|
|
|
14
14
|
except ImportError:
|
|
15
15
|
return
|
|
16
16
|
from langchain.cache import SQLiteCache
|
|
17
|
+
from langchain.globals import set_llm_cache
|
|
17
18
|
|
|
18
19
|
if config.project.lc_cache_path is not None:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
20
|
+
set_llm_cache(SQLiteCache(database_path=config.project.lc_cache_path))
|
|
21
|
+
|
|
22
22
|
if not os.path.exists(config.project.lc_cache_path):
|
|
23
23
|
logger.info(
|
|
24
24
|
f"LangChain cache created at: {config.project.lc_cache_path}"
|
chainlit/cli/__init__.py
CHANGED
|
@@ -21,7 +21,7 @@ from chainlit.config import (
|
|
|
21
21
|
from chainlit.logger import logger
|
|
22
22
|
from chainlit.markdown import init_markdown
|
|
23
23
|
from chainlit.secret import random_secret
|
|
24
|
-
from chainlit.server import app,
|
|
24
|
+
from chainlit.server import app, register_wildcard_route_handler
|
|
25
25
|
from chainlit.telemetry import trace_event
|
|
26
26
|
|
|
27
27
|
|
|
@@ -36,6 +36,16 @@ def cli():
|
|
|
36
36
|
def run_chainlit(target: str):
|
|
37
37
|
host = os.environ.get("CHAINLIT_HOST", DEFAULT_HOST)
|
|
38
38
|
port = int(os.environ.get("CHAINLIT_PORT", DEFAULT_PORT))
|
|
39
|
+
|
|
40
|
+
ws_per_message_deflate_env = os.environ.get(
|
|
41
|
+
"UVICORN_WS_PER_MESSAGE_DEFLATE", "true"
|
|
42
|
+
)
|
|
43
|
+
ws_per_message_deflate = ws_per_message_deflate_env.lower() in [
|
|
44
|
+
"true",
|
|
45
|
+
"1",
|
|
46
|
+
"yes",
|
|
47
|
+
] # Convert to boolean
|
|
48
|
+
|
|
39
49
|
config.run.host = host
|
|
40
50
|
config.run.port = port
|
|
41
51
|
|
|
@@ -63,7 +73,7 @@ def run_chainlit(target: str):
|
|
|
63
73
|
host=host,
|
|
64
74
|
port=port,
|
|
65
75
|
log_level=log_level,
|
|
66
|
-
|
|
76
|
+
ws_per_message_deflate=ws_per_message_deflate,
|
|
67
77
|
)
|
|
68
78
|
server = uvicorn.Server(config)
|
|
69
79
|
await server.serve()
|
chainlit/config.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
3
|
from importlib import util
|
|
4
|
+
from pathlib import Path
|
|
4
5
|
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
|
5
6
|
|
|
6
7
|
import tomli
|
|
@@ -12,8 +13,8 @@ from starlette.datastructures import Headers
|
|
|
12
13
|
|
|
13
14
|
if TYPE_CHECKING:
|
|
14
15
|
from chainlit.action import Action
|
|
15
|
-
from chainlit.
|
|
16
|
-
from chainlit.
|
|
16
|
+
from chainlit.types import ChatProfile, ThreadDict
|
|
17
|
+
from chainlit.user import User
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
BACKEND_ROOT = os.path.dirname(__file__)
|
|
@@ -23,6 +24,10 @@ PACKAGE_ROOT = os.path.dirname(os.path.dirname(BACKEND_ROOT))
|
|
|
23
24
|
# Get the directory the script is running from
|
|
24
25
|
APP_ROOT = os.getcwd()
|
|
25
26
|
|
|
27
|
+
# Create the directory to store the uploaded files
|
|
28
|
+
FILES_DIRECTORY = Path(APP_ROOT) / ".files"
|
|
29
|
+
FILES_DIRECTORY.mkdir(exist_ok=True)
|
|
30
|
+
|
|
26
31
|
config_dir = os.path.join(APP_ROOT, ".chainlit")
|
|
27
32
|
config_file = os.path.join(config_dir, "config.toml")
|
|
28
33
|
|
|
@@ -47,6 +52,12 @@ cache = false
|
|
|
47
52
|
# Show the prompt playground
|
|
48
53
|
prompt_playground = true
|
|
49
54
|
|
|
55
|
+
# Process and display HTML in messages. This can be a security risk (see https://stackoverflow.com/questions/19603097/why-is-it-dangerous-to-render-user-generated-html-or-javascript)
|
|
56
|
+
unsafe_allow_html = false
|
|
57
|
+
|
|
58
|
+
# Process and display mathematical expressions. This can clash with "$" characters in messages.
|
|
59
|
+
latex = false
|
|
60
|
+
|
|
50
61
|
# Authorize users to upload files with messages
|
|
51
62
|
multi_modal = true
|
|
52
63
|
|
|
@@ -60,7 +71,7 @@ multi_modal = true
|
|
|
60
71
|
# Name of the app and chatbot.
|
|
61
72
|
name = "Chatbot"
|
|
62
73
|
|
|
63
|
-
# Show the readme while the
|
|
74
|
+
# Show the readme while the thread is empty.
|
|
64
75
|
show_readme_as_default = true
|
|
65
76
|
|
|
66
77
|
# Description of the app and chatbot. This is used for HTML tags.
|
|
@@ -157,6 +168,8 @@ class SpeechToTextFeature:
|
|
|
157
168
|
class FeaturesSettings(DataClassJsonMixin):
|
|
158
169
|
prompt_playground: bool = True
|
|
159
170
|
multi_modal: bool = True
|
|
171
|
+
latex: bool = False
|
|
172
|
+
unsafe_allow_html: bool = False
|
|
160
173
|
speech_to_text: Optional[SpeechToTextFeature] = None
|
|
161
174
|
|
|
162
175
|
|
|
@@ -182,20 +195,20 @@ class CodeSettings:
|
|
|
182
195
|
# Module object loaded from the module_name
|
|
183
196
|
module: Any = None
|
|
184
197
|
# Bunch of callbacks defined by the developer
|
|
185
|
-
password_auth_callback: Optional[Callable[[str, str], Optional["
|
|
186
|
-
header_auth_callback: Optional[Callable[[Headers], Optional["
|
|
198
|
+
password_auth_callback: Optional[Callable[[str, str], Optional["User"]]] = None
|
|
199
|
+
header_auth_callback: Optional[Callable[[Headers], Optional["User"]]] = None
|
|
187
200
|
oauth_callback: Optional[
|
|
188
|
-
Callable[[str, str, Dict[str, str], "
|
|
201
|
+
Callable[[str, str, Dict[str, str], "User"], Optional["User"]]
|
|
189
202
|
] = None
|
|
190
203
|
on_stop: Optional[Callable[[], Any]] = None
|
|
191
204
|
on_chat_start: Optional[Callable[[], Any]] = None
|
|
192
205
|
on_chat_end: Optional[Callable[[], Any]] = None
|
|
193
|
-
on_chat_resume: Optional[Callable[["
|
|
206
|
+
on_chat_resume: Optional[Callable[["ThreadDict"], Any]] = None
|
|
194
207
|
on_message: Optional[Callable[[str], Any]] = None
|
|
195
208
|
author_rename: Optional[Callable[[str], str]] = None
|
|
196
209
|
on_settings_update: Optional[Callable[[Dict[str, Any]], Any]] = None
|
|
197
210
|
set_chat_profiles: Optional[
|
|
198
|
-
Callable[[Optional["
|
|
211
|
+
Callable[[Optional["User"]], List["ChatProfile"]]
|
|
199
212
|
] = None
|
|
200
213
|
|
|
201
214
|
|
|
@@ -221,8 +234,6 @@ class ChainlitConfig:
|
|
|
221
234
|
root = APP_ROOT
|
|
222
235
|
# Chainlit server URL. Used only for cloud features
|
|
223
236
|
chainlit_server: str
|
|
224
|
-
# Whether or not a chainlit api key has been provided
|
|
225
|
-
data_persistence: bool
|
|
226
237
|
# The url of the deployed app. Only set if the app is deployed.
|
|
227
238
|
chainlit_prod_url = chainlit_prod_url
|
|
228
239
|
|
|
@@ -261,7 +272,7 @@ def load_module(target: str, force_refresh: bool = False):
|
|
|
261
272
|
and module.__file__
|
|
262
273
|
and module.__file__.startswith(target_dir)
|
|
263
274
|
):
|
|
264
|
-
|
|
275
|
+
sys.modules.pop(module_name, None)
|
|
265
276
|
|
|
266
277
|
spec = util.spec_from_file_location(target, target)
|
|
267
278
|
if not spec or not spec.loader:
|
|
@@ -333,11 +344,9 @@ def load_config():
|
|
|
333
344
|
settings = load_settings()
|
|
334
345
|
|
|
335
346
|
chainlit_server = os.environ.get("CHAINLIT_SERVER", "https://cloud.chainlit.io")
|
|
336
|
-
data_persistence = "CHAINLIT_API_KEY" in os.environ
|
|
337
347
|
|
|
338
348
|
config = ChainlitConfig(
|
|
339
349
|
chainlit_server=chainlit_server,
|
|
340
|
-
data_persistence=data_persistence,
|
|
341
350
|
chainlit_prod_url=chainlit_prod_url,
|
|
342
351
|
run=RunSettings(),
|
|
343
352
|
**settings,
|
chainlit/context.py
CHANGED
|
@@ -7,9 +7,8 @@ from chainlit.session import HTTPSession, WebsocketSession
|
|
|
7
7
|
from lazify import LazyProxy
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
10
|
-
from chainlit.client.cloud import AppUser, PersistedAppUser
|
|
11
10
|
from chainlit.emitter import BaseChainlitEmitter
|
|
12
|
-
from chainlit.
|
|
11
|
+
from chainlit.user import PersistedUser, User
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
class ChainlitContextException(Exception):
|
|
@@ -22,6 +21,11 @@ class ChainlitContext:
|
|
|
22
21
|
emitter: "BaseChainlitEmitter"
|
|
23
22
|
session: Union["HTTPSession", "WebsocketSession"]
|
|
24
23
|
|
|
24
|
+
@property
|
|
25
|
+
def current_step(self):
|
|
26
|
+
if self.session.active_steps:
|
|
27
|
+
return self.session.active_steps[-1]
|
|
28
|
+
|
|
25
29
|
def __init__(self, session: Union["HTTPSession", "WebsocketSession"]):
|
|
26
30
|
from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter
|
|
27
31
|
|
|
@@ -47,7 +51,7 @@ def init_ws_context(session_or_sid: Union[WebsocketSession, str]) -> ChainlitCon
|
|
|
47
51
|
|
|
48
52
|
|
|
49
53
|
def init_http_context(
|
|
50
|
-
user: Optional[Union["
|
|
54
|
+
user: Optional[Union["User", "PersistedUser"]] = None,
|
|
51
55
|
auth_token: Optional[str] = None,
|
|
52
56
|
user_env: Optional[Dict[str, str]] = None,
|
|
53
57
|
) -> ChainlitContext:
|