chainlit 1.0.400__py3-none-any.whl → 2.0.3__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 +98 -279
- chainlit/_utils.py +8 -0
- chainlit/action.py +12 -10
- chainlit/{auth.py → auth/__init__.py} +28 -36
- chainlit/auth/cookie.py +122 -0
- chainlit/auth/jwt.py +39 -0
- chainlit/cache.py +4 -6
- chainlit/callbacks.py +362 -0
- chainlit/chat_context.py +64 -0
- chainlit/chat_settings.py +3 -1
- chainlit/cli/__init__.py +77 -8
- chainlit/config.py +181 -101
- chainlit/context.py +42 -13
- chainlit/copilot/dist/index.js +8750 -903
- chainlit/data/__init__.py +101 -416
- chainlit/data/acl.py +6 -2
- chainlit/data/base.py +107 -0
- chainlit/data/chainlit_data_layer.py +608 -0
- chainlit/data/dynamodb.py +590 -0
- chainlit/data/literalai.py +500 -0
- chainlit/data/sql_alchemy.py +721 -0
- chainlit/data/storage_clients/__init__.py +0 -0
- chainlit/data/storage_clients/azure.py +81 -0
- chainlit/data/storage_clients/azure_blob.py +89 -0
- chainlit/data/storage_clients/base.py +26 -0
- chainlit/data/storage_clients/gcs.py +88 -0
- chainlit/data/storage_clients/s3.py +75 -0
- chainlit/data/utils.py +29 -0
- chainlit/discord/__init__.py +6 -0
- chainlit/discord/app.py +354 -0
- chainlit/element.py +91 -33
- chainlit/emitter.py +80 -29
- chainlit/frontend/dist/assets/DailyMotion-C_XC7xJI.js +1 -0
- chainlit/frontend/dist/assets/Dataframe-Cs4l4hA1.js +22 -0
- chainlit/frontend/dist/assets/Facebook-CUeCH7hk.js +1 -0
- chainlit/frontend/dist/assets/FilePlayer-CB-fYkx8.js +1 -0
- chainlit/frontend/dist/assets/Kaltura-YX6qaq72.js +1 -0
- chainlit/frontend/dist/assets/Mixcloud-DGV0ldjP.js +1 -0
- chainlit/frontend/dist/assets/Mux-CmRss5oc.js +1 -0
- chainlit/frontend/dist/assets/Preview-DBVJn7-H.js +1 -0
- chainlit/frontend/dist/assets/SoundCloud-qLUb18oY.js +1 -0
- chainlit/frontend/dist/assets/Streamable-BvYP7bFp.js +1 -0
- chainlit/frontend/dist/assets/Twitch-CTHt-sGZ.js +1 -0
- chainlit/frontend/dist/assets/Vidyard-B-0mCJbm.js +1 -0
- chainlit/frontend/dist/assets/Vimeo-Dnp7ri8q.js +1 -0
- chainlit/frontend/dist/assets/Wistia-DW0x_UBn.js +1 -0
- chainlit/frontend/dist/assets/YouTube--98FipvA.js +1 -0
- chainlit/frontend/dist/assets/index-D71nZ46o.js +8665 -0
- chainlit/frontend/dist/assets/index-g8LTJwwr.css +1 -0
- chainlit/frontend/dist/assets/react-plotly-Cn_BQTQw.js +3484 -0
- chainlit/frontend/dist/index.html +2 -4
- chainlit/haystack/callbacks.py +4 -7
- chainlit/input_widget.py +8 -4
- chainlit/langchain/callbacks.py +107 -72
- chainlit/langflow/__init__.py +1 -0
- chainlit/llama_index/__init__.py +2 -2
- chainlit/llama_index/callbacks.py +67 -42
- chainlit/markdown.py +22 -6
- chainlit/message.py +54 -56
- chainlit/mistralai/__init__.py +50 -0
- chainlit/oauth_providers.py +266 -8
- chainlit/openai/__init__.py +10 -18
- chainlit/secret.py +1 -1
- chainlit/server.py +789 -228
- chainlit/session.py +108 -90
- chainlit/slack/__init__.py +6 -0
- chainlit/slack/app.py +397 -0
- chainlit/socket.py +199 -116
- chainlit/step.py +141 -89
- chainlit/sync.py +2 -1
- chainlit/teams/__init__.py +6 -0
- chainlit/teams/app.py +338 -0
- chainlit/translations/bn.json +235 -0
- chainlit/translations/en-US.json +83 -4
- chainlit/translations/gu.json +235 -0
- chainlit/translations/he-IL.json +235 -0
- chainlit/translations/hi.json +235 -0
- chainlit/translations/kn.json +235 -0
- chainlit/translations/ml.json +235 -0
- chainlit/translations/mr.json +235 -0
- chainlit/translations/nl-NL.json +233 -0
- chainlit/translations/ta.json +235 -0
- chainlit/translations/te.json +235 -0
- chainlit/translations/zh-CN.json +233 -0
- chainlit/translations.py +60 -0
- chainlit/types.py +133 -28
- chainlit/user.py +14 -3
- chainlit/user_session.py +6 -3
- chainlit/utils.py +52 -5
- chainlit/version.py +3 -2
- {chainlit-1.0.400.dist-info → chainlit-2.0.3.dist-info}/METADATA +48 -50
- chainlit-2.0.3.dist-info/RECORD +106 -0
- chainlit/cli/utils.py +0 -24
- chainlit/frontend/dist/assets/index-9711593e.js +0 -723
- chainlit/frontend/dist/assets/index-d088547c.css +0 -1
- chainlit/frontend/dist/assets/react-plotly-d8762cc2.js +0 -3602
- chainlit/playground/__init__.py +0 -2
- chainlit/playground/config.py +0 -40
- chainlit/playground/provider.py +0 -108
- chainlit/playground/providers/__init__.py +0 -13
- chainlit/playground/providers/anthropic.py +0 -118
- chainlit/playground/providers/huggingface.py +0 -75
- chainlit/playground/providers/langchain.py +0 -89
- chainlit/playground/providers/openai.py +0 -408
- chainlit/playground/providers/vertexai.py +0 -171
- chainlit/translations/pt-BR.json +0 -155
- chainlit-1.0.400.dist-info/RECORD +0 -66
- /chainlit/copilot/dist/assets/{logo_dark-2a3cf740.svg → logo_dark-IkGJ_IwC.svg} +0 -0
- /chainlit/copilot/dist/assets/{logo_light-b078e7bc.svg → logo_light-Bb_IPh6r.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_dark-2a3cf740.svg → logo_dark-IkGJ_IwC.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_light-b078e7bc.svg → logo_light-Bb_IPh6r.svg} +0 -0
- {chainlit-1.0.400.dist-info → chainlit-2.0.3.dist-info}/WHEEL +0 -0
- {chainlit-1.0.400.dist-info → chainlit-2.0.3.dist-info}/entry_points.txt +0 -0
chainlit/context.py
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import uuid
|
|
3
3
|
from contextvars import ContextVar
|
|
4
|
-
from typing import TYPE_CHECKING, Dict, Optional, Union
|
|
4
|
+
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
|
5
5
|
|
|
6
|
-
from chainlit.session import HTTPSession, WebsocketSession
|
|
7
6
|
from lazify import LazyProxy
|
|
8
7
|
|
|
8
|
+
from chainlit.session import ClientType, HTTPSession, WebsocketSession
|
|
9
|
+
|
|
9
10
|
if TYPE_CHECKING:
|
|
10
11
|
from chainlit.emitter import BaseChainlitEmitter
|
|
11
|
-
from chainlit.user import PersistedUser, User
|
|
12
12
|
from chainlit.step import Step
|
|
13
|
+
from chainlit.user import PersistedUser, User
|
|
14
|
+
|
|
15
|
+
CL_RUN_NAMES = ["on_chat_start", "on_message", "on_audio_end"]
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
class ChainlitContextException(Exception):
|
|
@@ -21,20 +24,32 @@ class ChainlitContext:
|
|
|
21
24
|
loop: asyncio.AbstractEventLoop
|
|
22
25
|
emitter: "BaseChainlitEmitter"
|
|
23
26
|
session: Union["HTTPSession", "WebsocketSession"]
|
|
24
|
-
active_steps: List["Step"]
|
|
25
27
|
|
|
26
28
|
@property
|
|
27
29
|
def current_step(self):
|
|
28
|
-
if
|
|
29
|
-
return
|
|
30
|
+
if previous_steps := local_steps.get():
|
|
31
|
+
return previous_steps[-1]
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
@property
|
|
34
|
+
def current_run(self):
|
|
35
|
+
if previous_steps := local_steps.get():
|
|
36
|
+
return next(
|
|
37
|
+
(step for step in previous_steps if step.name in CL_RUN_NAMES), None
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
session: Union["HTTPSession", "WebsocketSession"],
|
|
43
|
+
emitter: Optional["BaseChainlitEmitter"] = None,
|
|
44
|
+
):
|
|
32
45
|
from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter
|
|
33
46
|
|
|
34
47
|
self.loop = asyncio.get_running_loop()
|
|
35
48
|
self.session = session
|
|
36
|
-
|
|
37
|
-
if
|
|
49
|
+
|
|
50
|
+
if emitter:
|
|
51
|
+
self.emitter = emitter
|
|
52
|
+
elif isinstance(self.session, HTTPSession):
|
|
38
53
|
self.emitter = BaseChainlitEmitter(self.session)
|
|
39
54
|
elif isinstance(self.session, WebsocketSession):
|
|
40
55
|
self.emitter = ChainlitEmitter(self.session)
|
|
@@ -56,27 +71,41 @@ def init_ws_context(session_or_sid: Union[WebsocketSession, str]) -> ChainlitCon
|
|
|
56
71
|
|
|
57
72
|
|
|
58
73
|
def init_http_context(
|
|
74
|
+
thread_id: Optional[str] = None,
|
|
59
75
|
user: Optional[Union["User", "PersistedUser"]] = None,
|
|
60
76
|
auth_token: Optional[str] = None,
|
|
61
77
|
user_env: Optional[Dict[str, str]] = None,
|
|
78
|
+
client_type: ClientType = "webapp",
|
|
62
79
|
) -> ChainlitContext:
|
|
80
|
+
from chainlit.data import get_data_layer
|
|
81
|
+
|
|
82
|
+
session_id = str(uuid.uuid4())
|
|
83
|
+
thread_id = thread_id or str(uuid.uuid4())
|
|
63
84
|
session = HTTPSession(
|
|
64
|
-
id=
|
|
85
|
+
id=session_id,
|
|
86
|
+
thread_id=thread_id,
|
|
65
87
|
token=auth_token,
|
|
66
88
|
user=user,
|
|
67
|
-
client_type=
|
|
89
|
+
client_type=client_type,
|
|
68
90
|
user_env=user_env,
|
|
69
91
|
)
|
|
70
92
|
context = ChainlitContext(session)
|
|
71
93
|
context_var.set(context)
|
|
94
|
+
|
|
95
|
+
if data_layer := get_data_layer():
|
|
96
|
+
if user_id := getattr(user, "id", None):
|
|
97
|
+
asyncio.create_task(
|
|
98
|
+
data_layer.update_thread(thread_id=thread_id, user_id=user_id)
|
|
99
|
+
)
|
|
100
|
+
|
|
72
101
|
return context
|
|
73
102
|
|
|
74
103
|
|
|
75
104
|
def get_context() -> ChainlitContext:
|
|
76
105
|
try:
|
|
77
106
|
return context_var.get()
|
|
78
|
-
except LookupError:
|
|
79
|
-
raise ChainlitContextException
|
|
107
|
+
except LookupError as e:
|
|
108
|
+
raise ChainlitContextException from e
|
|
80
109
|
|
|
81
110
|
|
|
82
111
|
context: ChainlitContext = LazyProxy(get_context, enable_cache=False)
|