chainlit 1.3.2__py3-none-any.whl → 2.0.0__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 (82) hide show
  1. chainlit/__init__.py +58 -56
  2. chainlit/action.py +12 -10
  3. chainlit/{auth.py → auth/__init__.py} +24 -34
  4. chainlit/auth/cookie.py +123 -0
  5. chainlit/auth/jwt.py +37 -0
  6. chainlit/cache.py +4 -6
  7. chainlit/callbacks.py +65 -11
  8. chainlit/chat_context.py +2 -2
  9. chainlit/chat_settings.py +3 -1
  10. chainlit/cli/__init__.py +15 -2
  11. chainlit/config.py +46 -90
  12. chainlit/context.py +4 -3
  13. chainlit/copilot/dist/index.js +8608 -642
  14. chainlit/data/__init__.py +96 -8
  15. chainlit/data/acl.py +3 -2
  16. chainlit/data/base.py +1 -15
  17. chainlit/data/chainlit_data_layer.py +584 -0
  18. chainlit/data/dynamodb.py +7 -4
  19. chainlit/data/literalai.py +4 -6
  20. chainlit/data/sql_alchemy.py +9 -8
  21. chainlit/data/storage_clients/__init__.py +0 -0
  22. chainlit/data/{storage_clients.py → storage_clients/azure.py} +2 -33
  23. chainlit/data/storage_clients/azure_blob.py +80 -0
  24. chainlit/data/storage_clients/base.py +22 -0
  25. chainlit/data/storage_clients/gcs.py +78 -0
  26. chainlit/data/storage_clients/s3.py +49 -0
  27. chainlit/discord/__init__.py +4 -4
  28. chainlit/discord/app.py +2 -1
  29. chainlit/element.py +41 -9
  30. chainlit/emitter.py +37 -16
  31. chainlit/frontend/dist/assets/{DailyMotion-Bq4wFES6.js → DailyMotion-DgRzV5GZ.js} +1 -1
  32. chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +22 -0
  33. chainlit/frontend/dist/assets/{Facebook-CHEgeJDe.js → Facebook-C0vx6HWv.js} +1 -1
  34. chainlit/frontend/dist/assets/{FilePlayer-BMFA6He5.js → FilePlayer-CdhzeHPP.js} +1 -1
  35. chainlit/frontend/dist/assets/{Kaltura-BS4Q0SKd.js → Kaltura-5iVmeUct.js} +1 -1
  36. chainlit/frontend/dist/assets/{Mixcloud-tLlgZy_i.js → Mixcloud-C2zi77Ex.js} +1 -1
  37. chainlit/frontend/dist/assets/{Mux-Bcz0qNhS.js → Mux-Vkebogdf.js} +1 -1
  38. chainlit/frontend/dist/assets/{Preview-RsJjlwJx.js → Preview-DwY_sEIl.js} +1 -1
  39. chainlit/frontend/dist/assets/{SoundCloud-B9UgR7Bk.js → SoundCloud-CREBXAWo.js} +1 -1
  40. chainlit/frontend/dist/assets/{Streamable-BOgIqbui.js → Streamable-B5Lu25uy.js} +1 -1
  41. chainlit/frontend/dist/assets/{Twitch-CBX_d6nV.js → Twitch-y9iKCcM1.js} +1 -1
  42. chainlit/frontend/dist/assets/{Vidyard-C5HPuozf.js → Vidyard-ClYvcuEu.js} +1 -1
  43. chainlit/frontend/dist/assets/{Vimeo-CHBmywi9.js → Vimeo-D6HvM2jt.js} +1 -1
  44. chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +1 -0
  45. chainlit/frontend/dist/assets/{YouTube-CA7t0q0j.js → YouTube-D10tR6CJ.js} +1 -1
  46. chainlit/frontend/dist/assets/index-CI4qFOt5.js +8665 -0
  47. chainlit/frontend/dist/assets/index-CrrqM0nZ.css +1 -0
  48. chainlit/frontend/dist/assets/{react-plotly-Ba2Cl614.js → react-plotly-BpxUS-ab.js} +1 -1
  49. chainlit/frontend/dist/index.html +2 -2
  50. chainlit/haystack/callbacks.py +5 -4
  51. chainlit/input_widget.py +6 -4
  52. chainlit/langchain/callbacks.py +56 -47
  53. chainlit/langflow/__init__.py +1 -0
  54. chainlit/llama_index/callbacks.py +7 -7
  55. chainlit/message.py +8 -10
  56. chainlit/mistralai/__init__.py +3 -2
  57. chainlit/oauth_providers.py +70 -3
  58. chainlit/openai/__init__.py +3 -2
  59. chainlit/secret.py +1 -1
  60. chainlit/server.py +481 -182
  61. chainlit/session.py +7 -5
  62. chainlit/slack/__init__.py +3 -3
  63. chainlit/slack/app.py +3 -2
  64. chainlit/socket.py +89 -112
  65. chainlit/step.py +12 -12
  66. chainlit/sync.py +2 -1
  67. chainlit/teams/__init__.py +3 -3
  68. chainlit/teams/app.py +1 -0
  69. chainlit/translations/en-US.json +2 -1
  70. chainlit/translations/nl-NL.json +229 -0
  71. chainlit/types.py +24 -8
  72. chainlit/user.py +2 -1
  73. chainlit/utils.py +3 -2
  74. chainlit/version.py +3 -2
  75. {chainlit-1.3.2.dist-info → chainlit-2.0.0.dist-info}/METADATA +15 -35
  76. chainlit-2.0.0.dist-info/RECORD +106 -0
  77. chainlit/frontend/dist/assets/Wistia-1Gb23ljh.js +0 -1
  78. chainlit/frontend/dist/assets/index-CwmincdQ.css +0 -1
  79. chainlit/frontend/dist/assets/index-DnjoDoLU.js +0 -723
  80. chainlit-1.3.2.dist-info/RECORD +0 -96
  81. {chainlit-1.3.2.dist-info → chainlit-2.0.0.dist-info}/WHEEL +0 -0
  82. {chainlit-1.3.2.dist-info → chainlit-2.0.0.dist-info}/entry_points.txt +0 -0
chainlit/data/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import warnings
2
3
  from typing import Optional
3
4
 
4
5
  from .base import BaseDataLayer
@@ -7,19 +8,106 @@ from .utils import (
7
8
  )
8
9
 
9
10
  _data_layer: Optional[BaseDataLayer] = None
11
+ _data_layer_initialized = False
10
12
 
11
13
 
12
14
  def get_data_layer():
13
- global _data_layer
15
+ global _data_layer, _data_layer_initialized
14
16
 
15
- if not _data_layer:
16
- if api_key := os.environ.get("LITERAL_API_KEY"):
17
- from .literalai import LiteralDataLayer
17
+ if not _data_layer_initialized:
18
+ if _data_layer:
19
+ # Data layer manually set, warn user that this is deprecated.
18
20
 
19
- # support legacy LITERAL_SERVER variable as fallback
20
- server = os.environ.get("LITERAL_API_URL") or os.environ.get(
21
- "LITERAL_SERVER"
21
+ warnings.warn(
22
+ "Setting data layer manually is deprecated. Use @data_layer instead.",
23
+ DeprecationWarning,
22
24
  )
23
- _data_layer = LiteralDataLayer(api_key=api_key, server=server)
25
+
26
+ else:
27
+ from chainlit.config import config
28
+
29
+ if config.code.data_layer:
30
+ # When @data_layer is configured, call it to get data layer.
31
+ _data_layer = config.code.data_layer()
32
+ elif database_url := os.environ.get("DATABASE_URL"):
33
+ # Default to Chainlit data layer if DATABASE_URL specified.
34
+ from .chainlit_data_layer import ChainlitDataLayer
35
+
36
+ if os.environ.get("LITERAL_API_KEY"):
37
+ warnings.warn(
38
+ "Both LITERAL_API_KEY and DATABASE_URL specified. Ignoring Literal AI data layer and relying on data layer pointing to DATABASE_URL."
39
+ )
40
+ bucket_name = os.environ.get("BUCKET_NAME")
41
+
42
+ # AWS S3
43
+ aws_region = os.getenv("APP_AWS_REGION")
44
+ aws_access_key = os.getenv("APP_AWS_ACCESS_KEY")
45
+ aws_secret_key = os.getenv("APP_AWS_SECRET_KEY")
46
+ dev_aws_endpoint = os.getenv("DEV_AWS_ENDPOINT")
47
+ is_using_s3 = bool(aws_access_key and aws_secret_key and aws_region)
48
+
49
+ # Google Cloud Storage
50
+ gcs_project_id = os.getenv("APP_GCS_PROJECT_ID")
51
+ gcs_client_email = os.getenv("APP_GCS_CLIENT_EMAIL")
52
+ gcs_private_key = os.getenv("APP_GCS_PRIVATE_KEY")
53
+ is_using_gcs = bool(
54
+ gcs_project_id and gcs_client_email and gcs_private_key
55
+ )
56
+
57
+ # Azure Storage
58
+ azure_storage_account = os.getenv("APP_AZURE_STORAGE_ACCOUNT")
59
+ azure_storage_key = os.getenv("APP_AZURE_STORAGE_ACCESS_KEY")
60
+ is_using_azure = bool(azure_storage_account and azure_storage_key)
61
+
62
+ storage_client = None
63
+
64
+ if sum([is_using_s3, is_using_gcs, is_using_azure]) > 1:
65
+ warnings.warn(
66
+ "Multiple storage configurations detected. Please use only one."
67
+ )
68
+ elif is_using_s3:
69
+ from chainlit.data.storage_clients.s3 import S3StorageClient
70
+
71
+ storage_client = S3StorageClient(
72
+ bucket=bucket_name,
73
+ region_name=aws_region,
74
+ aws_access_key_id=aws_access_key,
75
+ aws_secret_access_key=aws_secret_key,
76
+ endpoint_url=dev_aws_endpoint,
77
+ )
78
+ elif is_using_gcs:
79
+ from chainlit.data.storage_clients.gcs import GCSStorageClient
80
+
81
+ storage_client = GCSStorageClient(
82
+ project_id=gcs_project_id,
83
+ client_email=gcs_client_email,
84
+ private_key=gcs_private_key,
85
+ bucket_name=bucket_name,
86
+ )
87
+ elif is_using_azure:
88
+ from chainlit.data.storage_clients.azure_blob import (
89
+ AzureBlobStorageClient,
90
+ )
91
+
92
+ storage_client = AzureBlobStorageClient(
93
+ container_name=bucket_name,
94
+ storage_account=azure_storage_account,
95
+ storage_key=azure_storage_key,
96
+ )
97
+
98
+ _data_layer = ChainlitDataLayer(
99
+ database_url=database_url, storage_client=storage_client
100
+ )
101
+ elif api_key := os.environ.get("LITERAL_API_KEY"):
102
+ # When LITERAL_API_KEY is defined, use Literal AI data layer
103
+ from .literalai import LiteralDataLayer
104
+
105
+ # support legacy LITERAL_SERVER variable as fallback
106
+ server = os.environ.get("LITERAL_API_URL") or os.environ.get(
107
+ "LITERAL_SERVER"
108
+ )
109
+ _data_layer = LiteralDataLayer(api_key=api_key, server=server)
110
+
111
+ _data_layer_initialized = True
24
112
 
25
113
  return _data_layer
chainlit/data/acl.py CHANGED
@@ -1,6 +1,7 @@
1
- from chainlit.data import get_data_layer
2
1
  from fastapi import HTTPException
3
2
 
3
+ from chainlit.data import get_data_layer
4
+
4
5
 
5
6
  async def is_thread_author(username: str, thread_id: str):
6
7
  data_layer = get_data_layer()
@@ -8,7 +9,7 @@ async def is_thread_author(username: str, thread_id: str):
8
9
  raise HTTPException(status_code=400, detail="Data layer not initialized")
9
10
 
10
11
  thread_author = await data_layer.get_thread_author(thread_id)
11
-
12
+
12
13
  if not thread_author:
13
14
  raise HTTPException(status_code=404, detail="Thread not found")
14
15
 
chainlit/data/base.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from abc import ABC, abstractmethod
2
- from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
2
+ from typing import TYPE_CHECKING, Dict, List, Optional
3
3
 
4
4
  from chainlit.types import (
5
5
  Feedback,
@@ -105,17 +105,3 @@ class BaseDataLayer(ABC):
105
105
  @abstractmethod
106
106
  async def build_debug_url(self) -> str:
107
107
  pass
108
-
109
-
110
- class BaseStorageClient(ABC):
111
- """Base class for non-text data persistence like Azure Data Lake, S3, Google Storage, etc."""
112
-
113
- @abstractmethod
114
- async def upload_file(
115
- self,
116
- object_key: str,
117
- data: Union[bytes, str],
118
- mime: str = "application/octet-stream",
119
- overwrite: bool = True,
120
- ) -> Dict[str, Any]:
121
- pass