chainlit 1.0.401__py3-none-any.whl → 2.0.4__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 (113) hide show
  1. chainlit/__init__.py +98 -279
  2. chainlit/_utils.py +8 -0
  3. chainlit/action.py +12 -10
  4. chainlit/{auth.py → auth/__init__.py} +28 -36
  5. chainlit/auth/cookie.py +123 -0
  6. chainlit/auth/jwt.py +39 -0
  7. chainlit/cache.py +4 -6
  8. chainlit/callbacks.py +362 -0
  9. chainlit/chat_context.py +64 -0
  10. chainlit/chat_settings.py +3 -1
  11. chainlit/cli/__init__.py +77 -8
  12. chainlit/config.py +191 -102
  13. chainlit/context.py +42 -13
  14. chainlit/copilot/dist/index.js +8750 -903
  15. chainlit/data/__init__.py +101 -416
  16. chainlit/data/acl.py +6 -2
  17. chainlit/data/base.py +107 -0
  18. chainlit/data/chainlit_data_layer.py +614 -0
  19. chainlit/data/dynamodb.py +590 -0
  20. chainlit/data/literalai.py +500 -0
  21. chainlit/data/sql_alchemy.py +721 -0
  22. chainlit/data/storage_clients/__init__.py +0 -0
  23. chainlit/data/storage_clients/azure.py +81 -0
  24. chainlit/data/storage_clients/azure_blob.py +89 -0
  25. chainlit/data/storage_clients/base.py +26 -0
  26. chainlit/data/storage_clients/gcs.py +88 -0
  27. chainlit/data/storage_clients/s3.py +75 -0
  28. chainlit/data/utils.py +29 -0
  29. chainlit/discord/__init__.py +6 -0
  30. chainlit/discord/app.py +354 -0
  31. chainlit/element.py +91 -33
  32. chainlit/emitter.py +81 -29
  33. chainlit/frontend/dist/assets/DailyMotion-Ce9dQoqZ.js +1 -0
  34. chainlit/frontend/dist/assets/Dataframe-C1XonMcV.js +22 -0
  35. chainlit/frontend/dist/assets/Facebook-DVVt6lrr.js +1 -0
  36. chainlit/frontend/dist/assets/FilePlayer-c7stW4vz.js +1 -0
  37. chainlit/frontend/dist/assets/Kaltura-BmMmgorA.js +1 -0
  38. chainlit/frontend/dist/assets/Mixcloud-Cw8hDmiO.js +1 -0
  39. chainlit/frontend/dist/assets/Mux-DiRZfeUf.js +1 -0
  40. chainlit/frontend/dist/assets/Preview-6Jt2mRHx.js +1 -0
  41. chainlit/frontend/dist/assets/SoundCloud-DKwcT58_.js +1 -0
  42. chainlit/frontend/dist/assets/Streamable-BVdxrEeX.js +1 -0
  43. chainlit/frontend/dist/assets/Twitch-DFqZR7Gu.js +1 -0
  44. chainlit/frontend/dist/assets/Vidyard-0BQAAtVk.js +1 -0
  45. chainlit/frontend/dist/assets/Vimeo-CRFSH0Vu.js +1 -0
  46. chainlit/frontend/dist/assets/Wistia-CKrmdQaG.js +1 -0
  47. chainlit/frontend/dist/assets/YouTube-CQpL-rvU.js +1 -0
  48. chainlit/frontend/dist/assets/index-DQmLRKyv.css +1 -0
  49. chainlit/frontend/dist/assets/index-QdmxtIMQ.js +8665 -0
  50. chainlit/frontend/dist/assets/react-plotly-B9hvVpUG.js +3484 -0
  51. chainlit/frontend/dist/index.html +2 -4
  52. chainlit/haystack/callbacks.py +4 -7
  53. chainlit/input_widget.py +8 -4
  54. chainlit/langchain/callbacks.py +103 -68
  55. chainlit/langflow/__init__.py +1 -0
  56. chainlit/llama_index/callbacks.py +65 -40
  57. chainlit/markdown.py +22 -6
  58. chainlit/message.py +54 -56
  59. chainlit/mistralai/__init__.py +50 -0
  60. chainlit/oauth_providers.py +266 -8
  61. chainlit/openai/__init__.py +10 -18
  62. chainlit/secret.py +1 -1
  63. chainlit/server.py +789 -228
  64. chainlit/session.py +108 -90
  65. chainlit/slack/__init__.py +6 -0
  66. chainlit/slack/app.py +397 -0
  67. chainlit/socket.py +199 -116
  68. chainlit/step.py +141 -89
  69. chainlit/sync.py +2 -1
  70. chainlit/teams/__init__.py +6 -0
  71. chainlit/teams/app.py +338 -0
  72. chainlit/translations/bn.json +244 -0
  73. chainlit/translations/en-US.json +122 -8
  74. chainlit/translations/gu.json +244 -0
  75. chainlit/translations/he-IL.json +244 -0
  76. chainlit/translations/hi.json +244 -0
  77. chainlit/translations/ja.json +242 -0
  78. chainlit/translations/kn.json +244 -0
  79. chainlit/translations/ml.json +244 -0
  80. chainlit/translations/mr.json +244 -0
  81. chainlit/translations/nl-NL.json +242 -0
  82. chainlit/translations/ta.json +244 -0
  83. chainlit/translations/te.json +244 -0
  84. chainlit/translations/zh-CN.json +243 -0
  85. chainlit/translations.py +60 -0
  86. chainlit/types.py +133 -28
  87. chainlit/user.py +14 -3
  88. chainlit/user_session.py +6 -3
  89. chainlit/utils.py +52 -5
  90. chainlit/version.py +3 -2
  91. {chainlit-1.0.401.dist-info → chainlit-2.0.4.dist-info}/METADATA +48 -50
  92. chainlit-2.0.4.dist-info/RECORD +107 -0
  93. chainlit/cli/utils.py +0 -24
  94. chainlit/frontend/dist/assets/index-9711593e.js +0 -723
  95. chainlit/frontend/dist/assets/index-d088547c.css +0 -1
  96. chainlit/frontend/dist/assets/react-plotly-d8762cc2.js +0 -3602
  97. chainlit/playground/__init__.py +0 -2
  98. chainlit/playground/config.py +0 -40
  99. chainlit/playground/provider.py +0 -108
  100. chainlit/playground/providers/__init__.py +0 -13
  101. chainlit/playground/providers/anthropic.py +0 -118
  102. chainlit/playground/providers/huggingface.py +0 -75
  103. chainlit/playground/providers/langchain.py +0 -89
  104. chainlit/playground/providers/openai.py +0 -408
  105. chainlit/playground/providers/vertexai.py +0 -171
  106. chainlit/translations/pt-BR.json +0 -155
  107. chainlit-1.0.401.dist-info/RECORD +0 -66
  108. /chainlit/copilot/dist/assets/{logo_dark-2a3cf740.svg → logo_dark-IkGJ_IwC.svg} +0 -0
  109. /chainlit/copilot/dist/assets/{logo_light-b078e7bc.svg → logo_light-Bb_IPh6r.svg} +0 -0
  110. /chainlit/frontend/dist/assets/{logo_dark-2a3cf740.svg → logo_dark-IkGJ_IwC.svg} +0 -0
  111. /chainlit/frontend/dist/assets/{logo_light-b078e7bc.svg → logo_light-Bb_IPh6r.svg} +0 -0
  112. {chainlit-1.0.401.dist-info → chainlit-2.0.4.dist-info}/WHEEL +0 -0
  113. {chainlit-1.0.401.dist-info → chainlit-2.0.4.dist-info}/entry_points.txt +0 -0
File without changes
@@ -0,0 +1,81 @@
1
+ from typing import TYPE_CHECKING, Any, Dict, Optional, Union
2
+
3
+ from azure.storage.filedatalake import (
4
+ ContentSettings,
5
+ DataLakeFileClient,
6
+ DataLakeServiceClient,
7
+ FileSystemClient,
8
+ )
9
+
10
+ from chainlit.data.storage_clients.base import BaseStorageClient
11
+ from chainlit.logger import logger
12
+
13
+ if TYPE_CHECKING:
14
+ from azure.core.credentials import (
15
+ AzureNamedKeyCredential,
16
+ AzureSasCredential,
17
+ TokenCredential,
18
+ )
19
+
20
+
21
+ class AzureStorageClient(BaseStorageClient):
22
+ """
23
+ Class to enable Azure Data Lake Storage (ADLS) Gen2
24
+
25
+ parms:
26
+ account_url: "https://<your_account>.dfs.core.windows.net"
27
+ credential: Access credential (AzureKeyCredential)
28
+ sas_token: Optionally include SAS token to append to urls
29
+ """
30
+
31
+ def __init__(
32
+ self,
33
+ account_url: str,
34
+ container: str,
35
+ credential: Optional[
36
+ Union[
37
+ str,
38
+ Dict[str, str],
39
+ "AzureNamedKeyCredential",
40
+ "AzureSasCredential",
41
+ "TokenCredential",
42
+ ]
43
+ ],
44
+ sas_token: Optional[str] = None,
45
+ ):
46
+ try:
47
+ self.data_lake_client = DataLakeServiceClient(
48
+ account_url=account_url, credential=credential
49
+ )
50
+ self.container_client: FileSystemClient = (
51
+ self.data_lake_client.get_file_system_client(file_system=container)
52
+ )
53
+ self.sas_token = sas_token
54
+ logger.info("AzureStorageClient initialized")
55
+ except Exception as e:
56
+ logger.warn(f"AzureStorageClient initialization error: {e}")
57
+
58
+ async def upload_file(
59
+ self,
60
+ object_key: str,
61
+ data: Union[bytes, str],
62
+ mime: str = "application/octet-stream",
63
+ overwrite: bool = True,
64
+ ) -> Dict[str, Any]:
65
+ try:
66
+ file_client: DataLakeFileClient = self.container_client.get_file_client(
67
+ object_key
68
+ )
69
+ content_settings = ContentSettings(content_type=mime)
70
+ file_client.upload_data(
71
+ data, overwrite=overwrite, content_settings=content_settings
72
+ )
73
+ url = (
74
+ f"{file_client.url}{self.sas_token}"
75
+ if self.sas_token
76
+ else file_client.url
77
+ )
78
+ return {"object_key": object_key, "url": url}
79
+ except Exception as e:
80
+ logger.warn(f"AzureStorageClient, upload_file error: {e}")
81
+ return {}
@@ -0,0 +1,89 @@
1
+ from datetime import datetime, timedelta
2
+ from typing import Any, Dict, Union
3
+
4
+ from azure.storage.blob import BlobSasPermissions, ContentSettings, generate_blob_sas
5
+ from azure.storage.blob.aio import BlobServiceClient as AsyncBlobServiceClient
6
+
7
+ from chainlit.data.storage_clients.base import EXPIRY_TIME, BaseStorageClient
8
+ from chainlit.logger import logger
9
+
10
+
11
+ class AzureBlobStorageClient(BaseStorageClient):
12
+ def __init__(self, container_name: str, storage_account: str, storage_key: str):
13
+ self.container_name = container_name
14
+ self.storage_account = storage_account
15
+ self.storage_key = storage_key
16
+ connection_string = (
17
+ f"DefaultEndpointsProtocol=https;"
18
+ f"AccountName={storage_account};"
19
+ f"AccountKey={storage_key};"
20
+ f"EndpointSuffix=core.windows.net"
21
+ )
22
+ self.service_client = AsyncBlobServiceClient.from_connection_string(
23
+ connection_string
24
+ )
25
+ self.container_client = self.service_client.get_container_client(
26
+ self.container_name
27
+ )
28
+ logger.info("AzureBlobStorageClient initialized")
29
+
30
+ async def get_read_url(self, object_key: str) -> str:
31
+ if not self.storage_key:
32
+ raise Exception("Not using Azure Storage")
33
+
34
+ sas_permissions = BlobSasPermissions(read=True)
35
+ start_time = datetime.now()
36
+ expiry_time = start_time + timedelta(seconds=EXPIRY_TIME)
37
+
38
+ sas_token = generate_blob_sas(
39
+ account_name=self.storage_account,
40
+ container_name=self.container_name,
41
+ blob_name=object_key,
42
+ account_key=self.storage_key,
43
+ permission=sas_permissions,
44
+ start=start_time,
45
+ expiry=expiry_time,
46
+ )
47
+
48
+ return f"https://{self.storage_account}.blob.core.windows.net/{self.container_name}/{object_key}?{sas_token}"
49
+
50
+ async def upload_file(
51
+ self,
52
+ object_key: str,
53
+ data: Union[bytes, str],
54
+ mime: str = "application/octet-stream",
55
+ overwrite: bool = True,
56
+ ) -> Dict[str, Any]:
57
+ try:
58
+ blob_client = self.container_client.get_blob_client(object_key)
59
+
60
+ if isinstance(data, str):
61
+ data = data.encode("utf-8")
62
+
63
+ content_settings = ContentSettings(content_type=mime)
64
+
65
+ await blob_client.upload_blob(
66
+ data, overwrite=overwrite, content_settings=content_settings
67
+ )
68
+
69
+ properties = await blob_client.get_blob_properties()
70
+
71
+ return {
72
+ "path": object_key,
73
+ "size": properties.size,
74
+ "last_modified": properties.last_modified,
75
+ "etag": properties.etag,
76
+ "content_type": properties.content_settings.content_type,
77
+ }
78
+
79
+ except Exception as e:
80
+ raise Exception(f"Failed to upload file to Azure Blob Storage: {e!s}")
81
+
82
+ async def delete_file(self, object_key: str) -> bool:
83
+ try:
84
+ blob_client = self.container_client.get_blob_client(blob=object_key)
85
+ await blob_client.delete_blob()
86
+ return True
87
+ except Exception as e:
88
+ logger.warn(f"AzureBlobStorageClient, delete_file error: {e}")
89
+ return False
@@ -0,0 +1,26 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Any, Dict, Union
3
+
4
+ EXPIRY_TIME = 3600
5
+
6
+
7
+ class BaseStorageClient(ABC):
8
+ """Base class for non-text data persistence like Azure Data Lake, S3, Google Storage, etc."""
9
+
10
+ @abstractmethod
11
+ async def upload_file(
12
+ self,
13
+ object_key: str,
14
+ data: Union[bytes, str],
15
+ mime: str = "application/octet-stream",
16
+ overwrite: bool = True,
17
+ ) -> Dict[str, Any]:
18
+ pass
19
+
20
+ @abstractmethod
21
+ async def delete_file(self, object_key: str) -> bool:
22
+ pass
23
+
24
+ @abstractmethod
25
+ async def get_read_url(self, object_key: str) -> str:
26
+ pass
@@ -0,0 +1,88 @@
1
+ import base64
2
+ from typing import Any, Dict, Union
3
+
4
+ from google.cloud import storage # type: ignore
5
+ from google.oauth2 import service_account
6
+
7
+ from chainlit import make_async
8
+ from chainlit.data.storage_clients.base import EXPIRY_TIME, BaseStorageClient
9
+ from chainlit.logger import logger
10
+
11
+
12
+ class GCSStorageClient(BaseStorageClient):
13
+ def __init__(
14
+ self, project_id: str, client_email: str, private_key: str, bucket_name: str
15
+ ):
16
+ private_key = base64.b64decode(private_key).decode("utf-8")
17
+
18
+ credentials = service_account.Credentials.from_service_account_info(
19
+ {
20
+ "type": "service_account",
21
+ "project_id": project_id,
22
+ "private_key": private_key,
23
+ "client_email": client_email,
24
+ "token_uri": "https://oauth2.googleapis.com/token",
25
+ }
26
+ )
27
+
28
+ self.client = storage.Client(project=project_id, credentials=credentials)
29
+ self.bucket = self.client.bucket(bucket_name)
30
+ logger.info("GCSStorageClient initialized")
31
+
32
+ def sync_get_read_url(self, object_key: str) -> str:
33
+ return self.bucket.blob(object_key).generate_signed_url(
34
+ version="v4", expiration=EXPIRY_TIME, method="GET"
35
+ )
36
+
37
+ async def get_read_url(self, object_key: str) -> str:
38
+ return await make_async(self.sync_get_read_url)(object_key)
39
+
40
+ def sync_upload_file(
41
+ self,
42
+ object_key: str,
43
+ data: Union[bytes, str],
44
+ mime: str = "application/octet-stream",
45
+ overwrite: bool = True,
46
+ ) -> Dict[str, Any]:
47
+ try:
48
+ blob = self.bucket.blob(object_key)
49
+
50
+ if not overwrite and blob.exists():
51
+ raise Exception(
52
+ f"File {object_key} already exists and overwrite is False"
53
+ )
54
+
55
+ if isinstance(data, str):
56
+ data = data.encode("utf-8")
57
+
58
+ blob.upload_from_string(data, content_type=mime)
59
+
60
+ return {
61
+ "object_key": object_key,
62
+ "url": f"gs://{self.bucket.name}/{object_key}",
63
+ }
64
+
65
+ except Exception as e:
66
+ raise Exception(f"Failed to upload file to GCS: {e!s}")
67
+
68
+ async def upload_file(
69
+ self,
70
+ object_key: str,
71
+ data: Union[bytes, str],
72
+ mime: str = "application/octet-stream",
73
+ overwrite: bool = True,
74
+ ) -> Dict[str, Any]:
75
+ return await make_async(self.sync_upload_file)(
76
+ object_key, data, mime, overwrite
77
+ )
78
+
79
+ def sync_delete_file(self, object_key: str) -> bool:
80
+ try:
81
+ self.bucket.blob(object_key).delete()
82
+ return True
83
+ except Exception as e:
84
+ logger.warn(f"GCSStorageClient, delete_file error: {e}")
85
+ return False
86
+
87
+ async def delete_file(self, object_key: str) -> bool:
88
+ return await make_async(self.sync_delete_file)(object_key)
@@ -0,0 +1,75 @@
1
+ from typing import Any, Dict, Union
2
+
3
+ import boto3 # type: ignore
4
+
5
+ from chainlit import make_async
6
+ from chainlit.data.storage_clients.base import EXPIRY_TIME, BaseStorageClient
7
+ from chainlit.logger import logger
8
+
9
+
10
+ class S3StorageClient(BaseStorageClient):
11
+ """
12
+ Class to enable Amazon S3 storage provider
13
+ """
14
+
15
+ def __init__(self, bucket: str, **kwargs: Any):
16
+ try:
17
+ self.bucket = bucket
18
+ self.client = boto3.client("s3", **kwargs)
19
+ logger.info("S3StorageClient initialized")
20
+ except Exception as e:
21
+ logger.warn(f"S3StorageClient initialization error: {e}")
22
+
23
+ def sync_get_read_url(self, object_key: str) -> str:
24
+ try:
25
+ url = self.client.generate_presigned_url(
26
+ "get_object",
27
+ Params={"Bucket": self.bucket, "Key": object_key},
28
+ ExpiresIn=EXPIRY_TIME,
29
+ )
30
+ return url
31
+ except Exception as e:
32
+ logger.warn(f"S3StorageClient, get_read_url error: {e}")
33
+ return object_key
34
+
35
+ async def get_read_url(self, object_key: str) -> str:
36
+ return await make_async(self.sync_get_read_url)(object_key)
37
+
38
+ def sync_upload_file(
39
+ self,
40
+ object_key: str,
41
+ data: Union[bytes, str],
42
+ mime: str = "application/octet-stream",
43
+ overwrite: bool = True,
44
+ ) -> Dict[str, Any]:
45
+ try:
46
+ self.client.put_object(
47
+ Bucket=self.bucket, Key=object_key, Body=data, ContentType=mime
48
+ )
49
+ url = f"https://{self.bucket}.s3.amazonaws.com/{object_key}"
50
+ return {"object_key": object_key, "url": url}
51
+ except Exception as e:
52
+ logger.warn(f"S3StorageClient, upload_file error: {e}")
53
+ return {}
54
+
55
+ async def upload_file(
56
+ self,
57
+ object_key: str,
58
+ data: Union[bytes, str],
59
+ mime: str = "application/octet-stream",
60
+ overwrite: bool = True,
61
+ ) -> Dict[str, Any]:
62
+ return await make_async(self.sync_upload_file)(
63
+ object_key, data, mime, overwrite
64
+ )
65
+
66
+ def sync_delete_file(self, object_key: str) -> bool:
67
+ try:
68
+ self.client.delete_object(Bucket=self.bucket, Key=object_key)
69
+ return True
70
+ except Exception as e:
71
+ logger.warn(f"S3StorageClient, delete_file error: {e}")
72
+ return False
73
+
74
+ async def delete_file(self, object_key: str) -> bool:
75
+ return await make_async(self.sync_delete_file)(object_key)
chainlit/data/utils.py ADDED
@@ -0,0 +1,29 @@
1
+ import functools
2
+ from collections import deque
3
+
4
+ from chainlit.context import context
5
+ from chainlit.session import WebsocketSession
6
+
7
+
8
+ def queue_until_user_message():
9
+ def decorator(method):
10
+ @functools.wraps(method)
11
+ async def wrapper(self, *args, **kwargs):
12
+ if (
13
+ isinstance(context.session, WebsocketSession)
14
+ and not context.session.has_first_interaction
15
+ ):
16
+ # Queue the method invocation waiting for the first user message
17
+ queues = context.session.thread_queues
18
+ method_name = method.__name__
19
+ if method_name not in queues:
20
+ queues[method_name] = deque()
21
+ queues[method_name].append((method, self, args, kwargs))
22
+
23
+ else:
24
+ # Otherwise, Execute the method immediately
25
+ return await method(self, *args, **kwargs)
26
+
27
+ return wrapper
28
+
29
+ return decorator
@@ -0,0 +1,6 @@
1
+ import importlib.util
2
+
3
+ if importlib.util.find_spec("discord") is None:
4
+ raise ValueError(
5
+ "The discord package is required to integrate Chainlit with a Discord app. Run `pip install discord --upgrade`"
6
+ )