chainlit 2.0.0__py3-none-any.whl → 2.0.dev0__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 -56
- chainlit/action.py +10 -12
- chainlit/{auth/__init__.py → auth.py} +34 -26
- chainlit/cache.py +6 -4
- chainlit/callbacks.py +7 -52
- chainlit/chat_context.py +2 -2
- chainlit/chat_settings.py +1 -3
- chainlit/cli/__init__.py +2 -15
- chainlit/config.py +70 -41
- chainlit/context.py +9 -8
- chainlit/copilot/dist/index.js +874 -8533
- chainlit/data/__init__.py +8 -96
- chainlit/data/acl.py +2 -3
- chainlit/data/base.py +15 -1
- chainlit/data/dynamodb.py +4 -7
- chainlit/data/literalai.py +6 -4
- chainlit/data/sql_alchemy.py +9 -10
- chainlit/data/{storage_clients/azure.py → storage_clients.py} +33 -2
- chainlit/discord/__init__.py +4 -4
- chainlit/discord/app.py +1 -2
- chainlit/element.py +9 -41
- chainlit/emitter.py +21 -17
- chainlit/frontend/dist/assets/DailyMotion-b4b7af47.js +1 -0
- chainlit/frontend/dist/assets/Facebook-572972a0.js +1 -0
- chainlit/frontend/dist/assets/FilePlayer-85c69ca8.js +1 -0
- chainlit/frontend/dist/assets/Kaltura-dfc24672.js +1 -0
- chainlit/frontend/dist/assets/Mixcloud-705011f4.js +1 -0
- chainlit/frontend/dist/assets/Mux-4201a9e6.js +1 -0
- chainlit/frontend/dist/assets/Preview-23ba40a6.js +1 -0
- chainlit/frontend/dist/assets/SoundCloud-1a582d51.js +1 -0
- chainlit/frontend/dist/assets/Streamable-5017c4ba.js +1 -0
- chainlit/frontend/dist/assets/Twitch-bb2de2fa.js +1 -0
- chainlit/frontend/dist/assets/Vidyard-54e269b1.js +1 -0
- chainlit/frontend/dist/assets/Vimeo-d92c37dd.js +1 -0
- chainlit/frontend/dist/assets/Wistia-25a1363b.js +1 -0
- chainlit/frontend/dist/assets/YouTube-616e8cb7.js +1 -0
- chainlit/frontend/dist/assets/index-aaf974a9.css +1 -0
- chainlit/frontend/dist/assets/index-f5df2072.js +1027 -0
- chainlit/frontend/dist/assets/{react-plotly-BpxUS-ab.js → react-plotly-f0315f86.js} +94 -94
- chainlit/frontend/dist/index.html +3 -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 +10 -8
- chainlit/mistralai/__init__.py +2 -3
- chainlit/oauth_providers.py +12 -113
- chainlit/openai/__init__.py +7 -6
- chainlit/secret.py +1 -1
- chainlit/server.py +181 -491
- chainlit/session.py +5 -7
- chainlit/slack/__init__.py +3 -3
- chainlit/slack/app.py +2 -3
- chainlit/socket.py +103 -78
- chainlit/step.py +29 -21
- chainlit/sync.py +1 -2
- chainlit/teams/__init__.py +3 -3
- chainlit/teams/app.py +0 -1
- chainlit/types.py +4 -20
- chainlit/user.py +1 -2
- chainlit/utils.py +2 -3
- chainlit/version.py +2 -3
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/METADATA +39 -27
- chainlit-2.0.dev0.dist-info/RECORD +96 -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/__init__.py +0 -0
- chainlit/data/storage_clients/azure_blob.py +0 -80
- chainlit/data/storage_clients/base.py +0 -22
- chainlit/data/storage_clients/gcs.py +0 -78
- chainlit/data/storage_clients/s3.py +0 -49
- chainlit/frontend/dist/assets/DailyMotion-DgRzV5GZ.js +0 -1
- chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +0 -22
- chainlit/frontend/dist/assets/Facebook-C0vx6HWv.js +0 -1
- chainlit/frontend/dist/assets/FilePlayer-CdhzeHPP.js +0 -1
- chainlit/frontend/dist/assets/Kaltura-5iVmeUct.js +0 -1
- chainlit/frontend/dist/assets/Mixcloud-C2zi77Ex.js +0 -1
- chainlit/frontend/dist/assets/Mux-Vkebogdf.js +0 -1
- chainlit/frontend/dist/assets/Preview-DwY_sEIl.js +0 -1
- chainlit/frontend/dist/assets/SoundCloud-CREBXAWo.js +0 -1
- chainlit/frontend/dist/assets/Streamable-B5Lu25uy.js +0 -1
- chainlit/frontend/dist/assets/Twitch-y9iKCcM1.js +0 -1
- chainlit/frontend/dist/assets/Vidyard-ClYvcuEu.js +0 -1
- chainlit/frontend/dist/assets/Vimeo-D6HvM2jt.js +0 -1
- chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +0 -1
- chainlit/frontend/dist/assets/YouTube-D10tR6CJ.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/copilot/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
- /chainlit/copilot/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/WHEEL +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/entry_points.txt +0 -0
chainlit/oauth_providers.py
CHANGED
|
@@ -4,10 +4,9 @@ import urllib.parse
|
|
|
4
4
|
from typing import Dict, List, Optional, Tuple
|
|
5
5
|
|
|
6
6
|
import httpx
|
|
7
|
-
from fastapi import HTTPException
|
|
8
|
-
|
|
9
7
|
from chainlit.secret import random_secret
|
|
10
8
|
from chainlit.user import User
|
|
9
|
+
from fastapi import HTTPException
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class OAuthProvider:
|
|
@@ -17,31 +16,15 @@ class OAuthProvider:
|
|
|
17
16
|
client_secret: str
|
|
18
17
|
authorize_url: str
|
|
19
18
|
authorize_params: Dict[str, str]
|
|
20
|
-
default_prompt: Optional[str] = None
|
|
21
19
|
|
|
22
20
|
def is_configured(self):
|
|
23
21
|
return all([os.environ.get(env) for env in self.env])
|
|
24
22
|
|
|
25
23
|
async def get_token(self, code: str, url: str) -> str:
|
|
26
|
-
raise NotImplementedError
|
|
24
|
+
raise NotImplementedError()
|
|
27
25
|
|
|
28
26
|
async def get_user_info(self, token: str) -> Tuple[Dict[str, str], User]:
|
|
29
|
-
raise NotImplementedError
|
|
30
|
-
|
|
31
|
-
def get_env_prefix(self) -> str:
|
|
32
|
-
"""Return environment prefix, like AZURE_AD."""
|
|
33
|
-
|
|
34
|
-
return self.id.replace("-", "_").upper()
|
|
35
|
-
|
|
36
|
-
def get_prompt(self) -> Optional[str]:
|
|
37
|
-
"""Return OAuth prompt param."""
|
|
38
|
-
if prompt := os.environ.get(f"OAUTH_{self.get_env_prefix()}_PROMPT"):
|
|
39
|
-
return prompt
|
|
40
|
-
|
|
41
|
-
if prompt := os.environ.get("OAUTH_PROMPT"):
|
|
42
|
-
return prompt
|
|
43
|
-
|
|
44
|
-
return self.default_prompt
|
|
27
|
+
raise NotImplementedError()
|
|
45
28
|
|
|
46
29
|
|
|
47
30
|
class GithubOAuthProvider(OAuthProvider):
|
|
@@ -54,11 +37,9 @@ class GithubOAuthProvider(OAuthProvider):
|
|
|
54
37
|
self.client_secret = os.environ.get("OAUTH_GITHUB_CLIENT_SECRET")
|
|
55
38
|
self.authorize_params = {
|
|
56
39
|
"scope": "user:email",
|
|
40
|
+
"prompt": "consent",
|
|
57
41
|
}
|
|
58
42
|
|
|
59
|
-
if prompt := self.get_prompt():
|
|
60
|
-
self.authorize_params["prompt"] = prompt
|
|
61
|
-
|
|
62
43
|
async def get_token(self, code: str, url: str):
|
|
63
44
|
payload = {
|
|
64
45
|
"client_id": self.client_id,
|
|
@@ -115,11 +96,9 @@ class GoogleOAuthProvider(OAuthProvider):
|
|
|
115
96
|
"scope": "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
|
|
116
97
|
"response_type": "code",
|
|
117
98
|
"access_type": "offline",
|
|
99
|
+
"prompt": "login",
|
|
118
100
|
}
|
|
119
101
|
|
|
120
|
-
if prompt := self.get_prompt():
|
|
121
|
-
self.authorize_params["prompt"] = prompt
|
|
122
|
-
|
|
123
102
|
async def get_token(self, code: str, url: str):
|
|
124
103
|
payload = {
|
|
125
104
|
"client_id": self.client_id,
|
|
@@ -185,11 +164,9 @@ class AzureADOAuthProvider(OAuthProvider):
|
|
|
185
164
|
"response_type": "code",
|
|
186
165
|
"scope": "https://graph.microsoft.com/User.Read",
|
|
187
166
|
"response_mode": "query",
|
|
167
|
+
"prompt": "login",
|
|
188
168
|
}
|
|
189
169
|
|
|
190
|
-
if prompt := self.get_prompt():
|
|
191
|
-
self.authorize_params["prompt"] = prompt
|
|
192
|
-
|
|
193
170
|
async def get_token(self, code: str, url: str):
|
|
194
171
|
payload = {
|
|
195
172
|
"client_id": self.client_id,
|
|
@@ -272,11 +249,9 @@ class AzureADHybridOAuthProvider(OAuthProvider):
|
|
|
272
249
|
"scope": "https://graph.microsoft.com/User.Read https://graph.microsoft.com/openid",
|
|
273
250
|
"response_mode": "form_post",
|
|
274
251
|
"nonce": nonce,
|
|
252
|
+
"prompt": "login",
|
|
275
253
|
}
|
|
276
254
|
|
|
277
|
-
if prompt := self.get_prompt():
|
|
278
|
-
self.authorize_params["prompt"] = prompt
|
|
279
|
-
|
|
280
255
|
async def get_token(self, code: str, url: str):
|
|
281
256
|
payload = {
|
|
282
257
|
"client_id": self.client_id,
|
|
@@ -354,11 +329,9 @@ class OktaOAuthProvider(OAuthProvider):
|
|
|
354
329
|
"response_type": "code",
|
|
355
330
|
"scope": "openid profile email",
|
|
356
331
|
"response_mode": "query",
|
|
332
|
+
"prompt": "login",
|
|
357
333
|
}
|
|
358
334
|
|
|
359
|
-
if prompt := self.get_prompt():
|
|
360
|
-
self.authorize_params["prompt"] = prompt
|
|
361
|
-
|
|
362
335
|
def get_authorization_server_path(self):
|
|
363
336
|
if not self.authorization_server_id:
|
|
364
337
|
return "/default"
|
|
@@ -428,11 +401,9 @@ class Auth0OAuthProvider(OAuthProvider):
|
|
|
428
401
|
"response_type": "code",
|
|
429
402
|
"scope": "openid profile email",
|
|
430
403
|
"audience": f"{self.original_domain}/userinfo",
|
|
404
|
+
"prompt": "login",
|
|
431
405
|
}
|
|
432
406
|
|
|
433
|
-
if prompt := self.get_prompt():
|
|
434
|
-
self.authorize_params["prompt"] = prompt
|
|
435
|
-
|
|
436
407
|
async def get_token(self, code: str, url: str):
|
|
437
408
|
payload = {
|
|
438
409
|
"client_id": self.client_id,
|
|
@@ -488,11 +459,9 @@ class DescopeOAuthProvider(OAuthProvider):
|
|
|
488
459
|
"response_type": "code",
|
|
489
460
|
"scope": "openid profile email",
|
|
490
461
|
"audience": f"{self.domain}/userinfo",
|
|
462
|
+
"prompt": "login",
|
|
491
463
|
}
|
|
492
464
|
|
|
493
|
-
if prompt := self.get_prompt():
|
|
494
|
-
self.authorize_params["prompt"] = prompt
|
|
495
|
-
|
|
496
465
|
async def get_token(self, code: str, url: str):
|
|
497
466
|
payload = {
|
|
498
467
|
"client_id": self.client_id,
|
|
@@ -549,11 +518,9 @@ class AWSCognitoOAuthProvider(OAuthProvider):
|
|
|
549
518
|
"response_type": "code",
|
|
550
519
|
"client_id": self.client_id,
|
|
551
520
|
"scope": "openid profile email",
|
|
521
|
+
"prompt": "login",
|
|
552
522
|
}
|
|
553
523
|
|
|
554
|
-
if prompt := self.get_prompt():
|
|
555
|
-
self.authorize_params["prompt"] = prompt
|
|
556
|
-
|
|
557
524
|
async def get_token(self, code: str, url: str):
|
|
558
525
|
payload = {
|
|
559
526
|
"client_id": self.client_id,
|
|
@@ -620,11 +587,9 @@ class GitlabOAuthProvider(OAuthProvider):
|
|
|
620
587
|
self.authorize_params = {
|
|
621
588
|
"scope": "openid profile email",
|
|
622
589
|
"response_type": "code",
|
|
590
|
+
"prompt": "login",
|
|
623
591
|
}
|
|
624
592
|
|
|
625
|
-
if prompt := self.get_prompt():
|
|
626
|
-
self.authorize_params["prompt"] = prompt
|
|
627
|
-
|
|
628
593
|
async def get_token(self, code: str, url: str):
|
|
629
594
|
payload = {
|
|
630
595
|
"client_id": self.client_id,
|
|
@@ -665,71 +630,6 @@ class GitlabOAuthProvider(OAuthProvider):
|
|
|
665
630
|
return (gitlab_user, user)
|
|
666
631
|
|
|
667
632
|
|
|
668
|
-
class KeycloakOAuthProvider(OAuthProvider):
|
|
669
|
-
env = [
|
|
670
|
-
"OAUTH_KEYCLOAK_CLIENT_ID",
|
|
671
|
-
"OAUTH_KEYCLOAK_CLIENT_SECRET",
|
|
672
|
-
"OAUTH_KEYCLOAK_REALM",
|
|
673
|
-
"OAUTH_KEYCLOAK_BASE_URL",
|
|
674
|
-
]
|
|
675
|
-
id = os.environ.get("OAUTH_KEYCLOAK_NAME", "keycloak")
|
|
676
|
-
|
|
677
|
-
def __init__(self):
|
|
678
|
-
self.client_id = os.environ.get("OAUTH_KEYCLOAK_CLIENT_ID")
|
|
679
|
-
self.client_secret = os.environ.get("OAUTH_KEYCLOAK_CLIENT_SECRET")
|
|
680
|
-
self.realm = os.environ.get("OAUTH_KEYCLOAK_REALM")
|
|
681
|
-
self.base_url = os.environ.get("OAUTH_KEYCLOAK_BASE_URL")
|
|
682
|
-
self.authorize_url = (
|
|
683
|
-
f"{self.base_url}/realms/{self.realm}/protocol/openid-connect/auth"
|
|
684
|
-
)
|
|
685
|
-
|
|
686
|
-
self.authorize_params = {
|
|
687
|
-
"scope": "profile email openid",
|
|
688
|
-
"response_type": "code",
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
if prompt := self.get_prompt():
|
|
692
|
-
self.authorize_params["prompt"] = prompt
|
|
693
|
-
|
|
694
|
-
async def get_token(self, code: str, url: str):
|
|
695
|
-
payload = {
|
|
696
|
-
"client_id": self.client_id,
|
|
697
|
-
"client_secret": self.client_secret,
|
|
698
|
-
"code": code,
|
|
699
|
-
"grant_type": "authorization_code",
|
|
700
|
-
"redirect_uri": url,
|
|
701
|
-
}
|
|
702
|
-
async with httpx.AsyncClient() as client:
|
|
703
|
-
response = await client.post(
|
|
704
|
-
f"{self.base_url}/realms/{self.realm}/protocol/openid-connect/token",
|
|
705
|
-
data=payload,
|
|
706
|
-
)
|
|
707
|
-
response.raise_for_status()
|
|
708
|
-
json = response.json()
|
|
709
|
-
token = json.get("access_token")
|
|
710
|
-
if not token:
|
|
711
|
-
raise httpx.HTTPStatusError(
|
|
712
|
-
"Failed to get the access token",
|
|
713
|
-
request=response.request,
|
|
714
|
-
response=response,
|
|
715
|
-
)
|
|
716
|
-
return token
|
|
717
|
-
|
|
718
|
-
async def get_user_info(self, token: str):
|
|
719
|
-
async with httpx.AsyncClient() as client:
|
|
720
|
-
response = await client.get(
|
|
721
|
-
f"{self.base_url}/realms/{self.realm}/protocol/openid-connect/userinfo",
|
|
722
|
-
headers={"Authorization": f"Bearer {token}"},
|
|
723
|
-
)
|
|
724
|
-
response.raise_for_status()
|
|
725
|
-
kc_user = response.json()
|
|
726
|
-
user = User(
|
|
727
|
-
identifier=kc_user["email"],
|
|
728
|
-
metadata={"provider": "keycloak"},
|
|
729
|
-
)
|
|
730
|
-
return (kc_user, user)
|
|
731
|
-
|
|
732
|
-
|
|
733
633
|
providers = [
|
|
734
634
|
GithubOAuthProvider(),
|
|
735
635
|
GoogleOAuthProvider(),
|
|
@@ -740,7 +640,6 @@ providers = [
|
|
|
740
640
|
DescopeOAuthProvider(),
|
|
741
641
|
AWSCognitoOAuthProvider(),
|
|
742
642
|
GitlabOAuthProvider(),
|
|
743
|
-
KeycloakOAuthProvider(),
|
|
744
643
|
]
|
|
745
644
|
|
|
746
645
|
|
chainlit/openai/__init__.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
from typing import Union
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
from literalai.helper import timestamp_utc
|
|
6
|
-
|
|
7
|
-
from chainlit.context import local_steps
|
|
4
|
+
from chainlit.context import get_context
|
|
8
5
|
from chainlit.step import Step
|
|
9
6
|
from chainlit.utils import check_module_version
|
|
7
|
+
from literalai import ChatGeneration, CompletionGeneration
|
|
8
|
+
from literalai.helper import timestamp_utc
|
|
10
9
|
|
|
11
10
|
|
|
12
11
|
def instrument_openai():
|
|
@@ -20,9 +19,11 @@ def instrument_openai():
|
|
|
20
19
|
def on_new_generation(
|
|
21
20
|
generation: Union["ChatGeneration", "CompletionGeneration"], timing
|
|
22
21
|
):
|
|
23
|
-
|
|
22
|
+
context = get_context()
|
|
24
23
|
|
|
25
|
-
parent_id =
|
|
24
|
+
parent_id = None
|
|
25
|
+
if context.current_step:
|
|
26
|
+
parent_id = context.current_step.id
|
|
26
27
|
|
|
27
28
|
step = Step(
|
|
28
29
|
name=generation.model if generation.model else generation.provider,
|
chainlit/secret.py
CHANGED