chainlit 1.1.300rc4__py3-none-any.whl → 1.1.301__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.

Files changed (45) hide show
  1. chainlit/__init__.py +3 -1
  2. chainlit/cli/__init__.py +53 -6
  3. chainlit/config.py +4 -0
  4. chainlit/context.py +9 -0
  5. chainlit/copilot/dist/index.js +180 -180
  6. chainlit/data/__init__.py +6 -3
  7. chainlit/data/sql_alchemy.py +3 -3
  8. chainlit/element.py +33 -9
  9. chainlit/emitter.py +4 -4
  10. chainlit/frontend/dist/assets/{DailyMotion-1a2b7d60.js → DailyMotion-578b63e6.js} +1 -1
  11. chainlit/frontend/dist/assets/{Facebook-8422f48c.js → Facebook-b825e5bb.js} +1 -1
  12. chainlit/frontend/dist/assets/{FilePlayer-a0a41349.js → FilePlayer-bcba3b4e.js} +1 -1
  13. chainlit/frontend/dist/assets/{Kaltura-aa7990f2.js → Kaltura-fc1c9497.js} +1 -1
  14. chainlit/frontend/dist/assets/{Mixcloud-1647b3e4.js → Mixcloud-4cfb2724.js} +1 -1
  15. chainlit/frontend/dist/assets/{Mux-7e57be81.js → Mux-aa92055c.js} +1 -1
  16. chainlit/frontend/dist/assets/{Preview-cb89b2c6.js → Preview-9f55905a.js} +1 -1
  17. chainlit/frontend/dist/assets/{SoundCloud-c0d86d55.js → SoundCloud-f991fe03.js} +1 -1
  18. chainlit/frontend/dist/assets/{Streamable-57c43c18.js → Streamable-53128f49.js} +1 -1
  19. chainlit/frontend/dist/assets/{Twitch-bed3f21d.js → Twitch-fce8b9f5.js} +1 -1
  20. chainlit/frontend/dist/assets/{Vidyard-4dd76e44.js → Vidyard-e35c6102.js} +1 -1
  21. chainlit/frontend/dist/assets/{Vimeo-93bb5ae2.js → Vimeo-fff35f8e.js} +1 -1
  22. chainlit/frontend/dist/assets/{Wistia-97199246.js → Wistia-ec07dc64.js} +1 -1
  23. chainlit/frontend/dist/assets/{YouTube-fe1a7afe.js → YouTube-ad068e2a.js} +1 -1
  24. chainlit/frontend/dist/assets/index-d40d41cc.js +727 -0
  25. chainlit/frontend/dist/assets/{react-plotly-b416b8f9.js → react-plotly-b2c6442b.js} +1 -1
  26. chainlit/frontend/dist/index.html +1 -2
  27. chainlit/message.py +13 -8
  28. chainlit/oauth_providers.py +96 -4
  29. chainlit/server.py +182 -57
  30. chainlit/slack/app.py +2 -2
  31. chainlit/socket.py +24 -21
  32. chainlit/step.py +12 -3
  33. chainlit/teams/__init__.py +6 -0
  34. chainlit/teams/app.py +332 -0
  35. chainlit/translations/en-US.json +1 -1
  36. chainlit/types.py +7 -17
  37. chainlit/user.py +9 -1
  38. chainlit/utils.py +43 -0
  39. {chainlit-1.1.300rc4.dist-info → chainlit-1.1.301.dist-info}/METADATA +2 -2
  40. chainlit-1.1.301.dist-info/RECORD +79 -0
  41. chainlit/cli/utils.py +0 -24
  42. chainlit/frontend/dist/assets/index-919bea8f.js +0 -727
  43. chainlit-1.1.300rc4.dist-info/RECORD +0 -78
  44. {chainlit-1.1.300rc4.dist-info → chainlit-1.1.301.dist-info}/WHEEL +0 -0
  45. {chainlit-1.1.300rc4.dist-info → chainlit-1.1.301.dist-info}/entry_points.txt +0 -0
@@ -4,7 +4,6 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <!-- TAG INJECTION PLACEHOLDER -->
7
- <link rel="icon" href="/favicon" />
8
7
  <link rel="preconnect" href="https://fonts.googleapis.com" />
9
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10
9
  <!-- FONT START -->
@@ -22,7 +21,7 @@
22
21
  <script>
23
22
  const global = globalThis;
24
23
  </script>
25
- <script type="module" crossorigin src="/assets/index-919bea8f.js"></script>
24
+ <script type="module" crossorigin src="/assets/index-d40d41cc.js"></script>
26
25
  <link rel="stylesheet" href="/assets/index-aaf974a9.css">
27
26
  </head>
28
27
  <body>
chainlit/message.py CHANGED
@@ -7,7 +7,7 @@ from typing import Dict, List, Optional, Union, cast
7
7
 
8
8
  from chainlit.action import Action
9
9
  from chainlit.config import config
10
- from chainlit.context import context
10
+ from chainlit.context import context, local_steps
11
11
  from chainlit.data import get_data_layer
12
12
  from chainlit.element import ElementBased
13
13
  from chainlit.logger import logger
@@ -21,7 +21,6 @@ from chainlit.types import (
21
21
  AskSpec,
22
22
  FileDict,
23
23
  )
24
- from literalai import BaseGeneration
25
24
  from literalai.helper import utc_now
26
25
  from literalai.step import MessageStepType
27
26
 
@@ -38,17 +37,22 @@ class MessageBase(ABC):
38
37
  fail_on_persist_error: bool = False
39
38
  persisted = False
40
39
  is_error = False
40
+ parent_id: Optional[str] = None
41
41
  language: Optional[str] = None
42
42
  metadata: Optional[Dict] = None
43
43
  tags: Optional[List[str]] = None
44
44
  wait_for_answer = False
45
45
  indent: Optional[int] = None
46
- generation: Optional[BaseGeneration] = None
47
46
 
48
47
  def __post_init__(self) -> None:
49
48
  trace_event(f"init {self.__class__.__name__}")
50
49
  self.thread_id = context.session.thread_id
51
50
 
51
+ previous_steps = local_steps.get() or []
52
+ parent_step = previous_steps[-1] if previous_steps else None
53
+ if parent_step:
54
+ self.parent_id = parent_step.id
55
+
52
56
  if not getattr(self, "id", None):
53
57
  self.id = str(uuid.uuid4())
54
58
 
@@ -57,6 +61,7 @@ class MessageBase(ABC):
57
61
  type = _dict.get("type", "assistant_message")
58
62
  message = Message(
59
63
  id=_dict["id"],
64
+ parent_id=_dict.get("parentId"),
60
65
  created_at=_dict["createdAt"],
61
66
  content=_dict["output"],
62
67
  author=_dict.get("name", config.ui.name),
@@ -71,6 +76,7 @@ class MessageBase(ABC):
71
76
  _dict: StepDict = {
72
77
  "id": self.id,
73
78
  "threadId": self.thread_id,
79
+ "parentId": self.parent_id,
74
80
  "createdAt": self.created_at,
75
81
  "start": self.created_at,
76
82
  "end": self.created_at,
@@ -84,7 +90,6 @@ class MessageBase(ABC):
84
90
  "isError": self.is_error,
85
91
  "waitForAnswer": self.wait_for_answer,
86
92
  "indent": self.indent,
87
- "generation": self.generation.to_dict() if self.generation else None,
88
93
  "metadata": self.metadata or {},
89
94
  "tags": self.tags,
90
95
  }
@@ -212,15 +217,14 @@ class Message(MessageBase):
212
217
  elements: Optional[List[ElementBased]] = None,
213
218
  disable_feedback: bool = False,
214
219
  type: MessageStepType = "assistant_message",
215
- generation: Optional[BaseGeneration] = None,
216
220
  metadata: Optional[Dict] = None,
217
221
  tags: Optional[List[str]] = None,
218
222
  id: Optional[str] = None,
223
+ parent_id: Optional[str] = None,
219
224
  created_at: Union[str, None] = None,
220
225
  ):
221
226
  time.sleep(0.001)
222
227
  self.language = language
223
- self.generation = generation
224
228
  if isinstance(content, dict):
225
229
  try:
226
230
  self.content = json.dumps(content, indent=4, ensure_ascii=False)
@@ -237,6 +241,9 @@ class Message(MessageBase):
237
241
  if id:
238
242
  self.id = str(id)
239
243
 
244
+ if parent_id:
245
+ self.parent_id = str(parent_id)
246
+
240
247
  if created_at:
241
248
  self.created_at = created_at
242
249
 
@@ -304,8 +311,6 @@ class ErrorMessage(MessageBase):
304
311
  Args:
305
312
  content (str): Text displayed above the upload button.
306
313
  author (str, optional): The author of the message, this will be used in the UI. Defaults to the assistant name (see config).
307
- parent_id (str, optional): If provided, the message will be nested inside the parent in the UI.
308
- indent (int, optional): If positive, the message will be nested in the UI.
309
314
  """
310
315
 
311
316
  def __init__(
@@ -4,6 +4,7 @@ import urllib.parse
4
4
  from typing import Dict, List, Optional, Tuple
5
5
 
6
6
  import httpx
7
+ from chainlit.secret import random_secret
7
8
  from chainlit.user import User
8
9
  from fastapi import HTTPException
9
10
 
@@ -203,9 +204,93 @@ class AzureADOAuthProvider(OAuthProvider):
203
204
  )
204
205
  photo_data = await photo_response.aread()
205
206
  base64_image = base64.b64encode(photo_data)
206
- azure_user[
207
- "image"
208
- ] = f"data:{photo_response.headers['Content-Type']};base64,{base64_image.decode('utf-8')}"
207
+ azure_user["image"] = (
208
+ f"data:{photo_response.headers['Content-Type']};base64,{base64_image.decode('utf-8')}"
209
+ )
210
+ except Exception as e:
211
+ # Ignore errors getting the photo
212
+ pass
213
+
214
+ user = User(
215
+ identifier=azure_user["userPrincipalName"],
216
+ metadata={"image": azure_user.get("image"), "provider": "azure-ad"},
217
+ )
218
+ return (azure_user, user)
219
+
220
+
221
+ class AzureADHybridOAuthProvider(OAuthProvider):
222
+ id = "azure-ad-hybrid"
223
+ env = [
224
+ "OAUTH_AZURE_AD_HYBRID_CLIENT_ID",
225
+ "OAUTH_AZURE_AD_HYBRID_CLIENT_SECRET",
226
+ "OAUTH_AZURE_AD_HYBRID_TENANT_ID",
227
+ ]
228
+ authorize_url = (
229
+ f"https://login.microsoftonline.com/{os.environ.get('OAUTH_AZURE_AD_HYBRID_TENANT_ID', '')}/oauth2/v2.0/authorize"
230
+ if os.environ.get("OAUTH_AZURE_AD_HYBRID_ENABLE_SINGLE_TENANT")
231
+ else "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
232
+ )
233
+ token_url = (
234
+ f"https://login.microsoftonline.com/{os.environ.get('OAUTH_AZURE_AD_HYBRID_TENANT_ID', '')}/oauth2/v2.0/token"
235
+ if os.environ.get("OAUTH_AZURE_AD_HYBRID_ENABLE_SINGLE_TENANT")
236
+ else "https://login.microsoftonline.com/common/oauth2/v2.0/token"
237
+ )
238
+
239
+ def __init__(self):
240
+ self.client_id = os.environ.get("OAUTH_AZURE_AD_HYBRID_CLIENT_ID")
241
+ self.client_secret = os.environ.get("OAUTH_AZURE_AD_HYBRID_CLIENT_SECRET")
242
+ nonce = random_secret(16)
243
+ self.authorize_params = {
244
+ "tenant": os.environ.get("OAUTH_AZURE_AD_HYBRID_TENANT_ID"),
245
+ "response_type": "code id_token",
246
+ "scope": "https://graph.microsoft.com/User.Read https://graph.microsoft.com/openid",
247
+ "response_mode": "form_post",
248
+ "nonce": nonce,
249
+ }
250
+
251
+ async def get_token(self, code: str, url: str):
252
+ payload = {
253
+ "client_id": self.client_id,
254
+ "client_secret": self.client_secret,
255
+ "code": code,
256
+ "grant_type": "authorization_code",
257
+ "redirect_uri": url,
258
+ }
259
+ async with httpx.AsyncClient() as client:
260
+ response = await client.post(
261
+ self.token_url,
262
+ data=payload,
263
+ )
264
+ response.raise_for_status()
265
+ json = response.json()
266
+
267
+ token = json["access_token"]
268
+ if not token:
269
+ raise HTTPException(
270
+ status_code=400, detail="Failed to get the access token"
271
+ )
272
+ return token
273
+
274
+ async def get_user_info(self, token: str):
275
+ async with httpx.AsyncClient() as client:
276
+ response = await client.get(
277
+ "https://graph.microsoft.com/v1.0/me",
278
+ headers={"Authorization": f"Bearer {token}"},
279
+ )
280
+ response.raise_for_status()
281
+
282
+ azure_user = response.json()
283
+
284
+ try:
285
+ photo_response = await client.get(
286
+ "https://graph.microsoft.com/v1.0/me/photos/48x48/$value",
287
+ headers={"Authorization": f"Bearer {token}"},
288
+ )
289
+ photo_data = await photo_response.aread()
290
+ base64_image = base64.b64encode(photo_data)
291
+ azure_user["image"] = (
292
+ f"data:{photo_response.headers['Content-Type']};base64,{base64_image.decode('utf-8')}"
293
+ )
209
294
  except Exception as e:
210
295
  # Ignore errors getting the photo
211
296
  pass
@@ -474,9 +559,14 @@ class AWSCognitoOAuthProvider(OAuthProvider):
474
559
  )
475
560
  return (cognito_user, user)
476
561
 
562
+
477
563
  class GitlabOAuthProvider(OAuthProvider):
478
564
  id = "gitlab"
479
- env = ["OAUTH_GITLAB_CLIENT_ID", "OAUTH_GITLAB_CLIENT_SECRET", "OAUTH_GITLAB_DOMAIN"]
565
+ env = [
566
+ "OAUTH_GITLAB_CLIENT_ID",
567
+ "OAUTH_GITLAB_CLIENT_SECRET",
568
+ "OAUTH_GITLAB_DOMAIN",
569
+ ]
480
570
 
481
571
  def __init__(self):
482
572
  self.client_id = os.environ.get("OAUTH_GITLAB_CLIENT_ID")
@@ -530,10 +620,12 @@ class GitlabOAuthProvider(OAuthProvider):
530
620
  )
531
621
  return (gitlab_user, user)
532
622
 
623
+
533
624
  providers = [
534
625
  GithubOAuthProvider(),
535
626
  GoogleOAuthProvider(),
536
627
  AzureADOAuthProvider(),
628
+ AzureADHybridOAuthProvider(),
537
629
  OktaOAuthProvider(),
538
630
  Auth0OAuthProvider(),
539
631
  DescopeOAuthProvider(),