chainlit 1.1.404__tar.gz → 1.2.0__tar.gz

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 (98) hide show
  1. {chainlit-1.1.404 → chainlit-1.2.0}/PKG-INFO +3 -3
  2. chainlit-1.2.0/chainlit/__init__.py +189 -0
  3. chainlit-1.2.0/chainlit/_utils.py +8 -0
  4. chainlit-1.1.404/chainlit/__init__.py → chainlit-1.2.0/chainlit/callbacks.py +36 -169
  5. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/config.py +55 -29
  6. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/copilot/dist/index.js +510 -629
  7. chainlit-1.2.0/chainlit/data/__init__.py +20 -0
  8. chainlit-1.2.0/chainlit/data/base.py +121 -0
  9. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/data/dynamodb.py +2 -5
  10. chainlit-1.1.404/chainlit/data/__init__.py → chainlit-1.2.0/chainlit/data/literalai.py +5 -145
  11. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/data/sql_alchemy.py +10 -9
  12. chainlit-1.2.0/chainlit/data/storage_clients.py +112 -0
  13. chainlit-1.2.0/chainlit/data/utils.py +29 -0
  14. chainlit-1.1.404/chainlit/frontend/dist/assets/DailyMotion-e665b444.js → chainlit-1.2.0/chainlit/frontend/dist/assets/DailyMotion-05f4fe48.js +1 -1
  15. chainlit-1.1.404/chainlit/frontend/dist/assets/Facebook-5207db92.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Facebook-f25411d1.js +1 -1
  16. chainlit-1.1.404/chainlit/frontend/dist/assets/FilePlayer-86937d6e.js → chainlit-1.2.0/chainlit/frontend/dist/assets/FilePlayer-40ff3414.js +1 -1
  17. chainlit-1.1.404/chainlit/frontend/dist/assets/Kaltura-c96622c1.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Kaltura-6cbf3897.js +1 -1
  18. chainlit-1.1.404/chainlit/frontend/dist/assets/Mixcloud-57ae3e32.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Mixcloud-34e7c912.js +1 -1
  19. chainlit-1.1.404/chainlit/frontend/dist/assets/Mux-20373920.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Mux-8aaff6ac.js +1 -1
  20. chainlit-1.1.404/chainlit/frontend/dist/assets/Preview-c68c0613.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Preview-2d3bf558.js +1 -1
  21. chainlit-1.1.404/chainlit/frontend/dist/assets/SoundCloud-8a9e3eae.js → chainlit-1.2.0/chainlit/frontend/dist/assets/SoundCloud-b835f90f.js +1 -1
  22. chainlit-1.1.404/chainlit/frontend/dist/assets/Streamable-1ed099af.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Streamable-1293e4f3.js +1 -1
  23. chainlit-1.1.404/chainlit/frontend/dist/assets/Twitch-6820039f.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Twitch-c69660cd.js +1 -1
  24. chainlit-1.1.404/chainlit/frontend/dist/assets/Vidyard-d39ab91d.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Vidyard-43bda599.js +1 -1
  25. chainlit-1.1.404/chainlit/frontend/dist/assets/Vimeo-017cd9a7.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Vimeo-54150039.js +1 -1
  26. chainlit-1.1.404/chainlit/frontend/dist/assets/Wistia-a509d9f2.js → chainlit-1.2.0/chainlit/frontend/dist/assets/Wistia-aa3c721b.js +1 -1
  27. chainlit-1.1.404/chainlit/frontend/dist/assets/YouTube-42dfd82f.js → chainlit-1.2.0/chainlit/frontend/dist/assets/YouTube-dd0f3cc2.js +1 -1
  28. chainlit-1.2.0/chainlit/frontend/dist/assets/index-cf48bedd.js +729 -0
  29. chainlit-1.2.0/chainlit/frontend/dist/assets/react-plotly-f52a41eb.js +3484 -0
  30. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/frontend/dist/index.html +1 -1
  31. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/langchain/callbacks.py +6 -1
  32. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/llama_index/callbacks.py +20 -4
  33. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/markdown.py +15 -9
  34. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/message.py +0 -1
  35. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/server.py +90 -36
  36. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/session.py +4 -1
  37. chainlit-1.2.0/chainlit/translations/bn.json +231 -0
  38. chainlit-1.2.0/chainlit/translations/gu.json +231 -0
  39. chainlit-1.2.0/chainlit/translations/he-IL.json +231 -0
  40. chainlit-1.2.0/chainlit/translations/hi.json +231 -0
  41. chainlit-1.2.0/chainlit/translations/kn.json +231 -0
  42. chainlit-1.2.0/chainlit/translations/ml.json +231 -0
  43. chainlit-1.2.0/chainlit/translations/mr.json +231 -0
  44. chainlit-1.2.0/chainlit/translations/ta.json +231 -0
  45. chainlit-1.2.0/chainlit/translations/te.json +231 -0
  46. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/utils.py +1 -1
  47. {chainlit-1.1.404 → chainlit-1.2.0}/pyproject.toml +5 -3
  48. chainlit-1.1.404/chainlit/data/storage_clients.py +0 -58
  49. chainlit-1.1.404/chainlit/frontend/dist/assets/index-30df9b2b.js +0 -730
  50. chainlit-1.1.404/chainlit/frontend/dist/assets/react-plotly-5bb34118.js +0 -3602
  51. {chainlit-1.1.404 → chainlit-1.2.0}/README.md +0 -0
  52. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/__main__.py +0 -0
  53. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/action.py +0 -0
  54. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/auth.py +0 -0
  55. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/cache.py +0 -0
  56. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/chat_context.py +0 -0
  57. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/chat_settings.py +0 -0
  58. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/cli/__init__.py +0 -0
  59. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/context.py +0 -0
  60. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/copilot/dist/assets/logo_dark-2a3cf740.svg +0 -0
  61. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/copilot/dist/assets/logo_light-b078e7bc.svg +0 -0
  62. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/data/acl.py +0 -0
  63. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/discord/__init__.py +0 -0
  64. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/discord/app.py +0 -0
  65. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/element.py +0 -0
  66. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/emitter.py +0 -0
  67. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/frontend/dist/assets/index-aaf974a9.css +0 -0
  68. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/frontend/dist/assets/logo_dark-2a3cf740.svg +0 -0
  69. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/frontend/dist/assets/logo_light-b078e7bc.svg +0 -0
  70. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/frontend/dist/favicon.svg +0 -0
  71. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/haystack/__init__.py +0 -0
  72. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/haystack/callbacks.py +0 -0
  73. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/hello.py +0 -0
  74. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/input_widget.py +0 -0
  75. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/langchain/__init__.py +0 -0
  76. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/langflow/__init__.py +0 -0
  77. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/llama_index/__init__.py +0 -0
  78. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/logger.py +0 -0
  79. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/mistralai/__init__.py +0 -0
  80. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/oauth_providers.py +0 -0
  81. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/openai/__init__.py +0 -0
  82. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/py.typed +0 -0
  83. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/secret.py +0 -0
  84. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/slack/__init__.py +0 -0
  85. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/slack/app.py +0 -0
  86. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/socket.py +0 -0
  87. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/step.py +0 -0
  88. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/sync.py +0 -0
  89. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/teams/__init__.py +0 -0
  90. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/teams/app.py +0 -0
  91. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/telemetry.py +0 -0
  92. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/translations/en-US.json +0 -0
  93. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/translations/zh-CN.json +0 -0
  94. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/translations.py +0 -0
  95. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/types.py +0 -0
  96. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/user.py +0 -0
  97. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/user_session.py +0 -0
  98. {chainlit-1.1.404 → chainlit-1.2.0}/chainlit/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 1.1.404
3
+ Version: 1.2.0
4
4
  Summary: Build Conversational AI.
5
5
  Home-page: https://github.com/Chainlit/chainlit
6
6
  License: Apache-2.0 license
@@ -16,8 +16,8 @@ Classifier: Programming Language :: Python :: 3.12
16
16
  Requires-Dist: aiofiles (>=23.1.0,<24.0.0)
17
17
  Requires-Dist: asyncer (>=0.0.7,<0.0.8)
18
18
  Requires-Dist: click (>=8.1.3,<9.0.0)
19
- Requires-Dist: dataclasses_json (>=0.5.7,<0.6.0)
20
- Requires-Dist: fastapi (>=0.110.1,<0.111.0)
19
+ Requires-Dist: dataclasses_json (>=0.6.7,<0.7.0)
20
+ Requires-Dist: fastapi (>=0.110.1,<0.113)
21
21
  Requires-Dist: filetype (>=1.2.0,<2.0.0)
22
22
  Requires-Dist: httpx (>=0.23.0)
23
23
  Requires-Dist: lazify (>=0.4.0,<0.5.0)
@@ -0,0 +1,189 @@
1
+ import os
2
+
3
+ from dotenv import load_dotenv
4
+
5
+ # ruff: noqa: E402
6
+ # Keep this here to ensure imports have environment available.
7
+ env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
8
+
9
+ from chainlit.logger import logger
10
+
11
+ if env_found:
12
+ logger.info("Loaded .env file")
13
+
14
+ import asyncio
15
+ from typing import TYPE_CHECKING, Any, Dict
16
+
17
+ import chainlit.input_widget as input_widget
18
+ from chainlit.action import Action
19
+ from chainlit.cache import cache
20
+ from chainlit.chat_context import chat_context
21
+ from chainlit.chat_settings import ChatSettings
22
+ from chainlit.context import context
23
+ from chainlit.element import (
24
+ Audio,
25
+ Component,
26
+ File,
27
+ Image,
28
+ Pdf,
29
+ Plotly,
30
+ Pyplot,
31
+ Task,
32
+ TaskList,
33
+ TaskStatus,
34
+ Text,
35
+ Video,
36
+ )
37
+ from chainlit.message import (
38
+ AskActionMessage,
39
+ AskFileMessage,
40
+ AskUserMessage,
41
+ ErrorMessage,
42
+ Message,
43
+ )
44
+ from chainlit.step import Step, step
45
+ from chainlit.sync import make_async, run_sync
46
+ from chainlit.types import AudioChunk, ChatProfile, Starter
47
+ from chainlit.user import PersistedUser, User
48
+ from chainlit.user_session import user_session
49
+ from chainlit.utils import make_module_getattr
50
+ from chainlit.version import __version__
51
+ from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
52
+ from pydantic.dataclasses import dataclass
53
+
54
+ from .callbacks import (
55
+ action_callback,
56
+ author_rename,
57
+ header_auth_callback,
58
+ oauth_callback,
59
+ on_audio_chunk,
60
+ on_audio_end,
61
+ on_chat_end,
62
+ on_chat_resume,
63
+ on_chat_start,
64
+ on_logout,
65
+ on_message,
66
+ on_settings_update,
67
+ on_stop,
68
+ password_auth_callback,
69
+ set_chat_profiles,
70
+ set_starters,
71
+ )
72
+
73
+ if TYPE_CHECKING:
74
+ from chainlit.haystack.callbacks import HaystackAgentCallbackHandler
75
+ from chainlit.langchain.callbacks import (
76
+ AsyncLangchainCallbackHandler,
77
+ LangchainCallbackHandler,
78
+ )
79
+ from chainlit.llama_index.callbacks import LlamaIndexCallbackHandler
80
+ from chainlit.mistralai import instrument_mistralai
81
+ from chainlit.openai import instrument_openai
82
+
83
+
84
+ def sleep(duration: int):
85
+ """
86
+ Sleep for a given duration.
87
+ Args:
88
+ duration (int): The duration in seconds.
89
+ """
90
+ return asyncio.sleep(duration)
91
+
92
+
93
+ @dataclass()
94
+ class CopilotFunction:
95
+ name: str
96
+ args: Dict[str, Any]
97
+
98
+ def acall(self):
99
+ return context.emitter.send_call_fn(self.name, self.args)
100
+
101
+
102
+ __getattr__ = make_module_getattr(
103
+ {
104
+ "LangchainCallbackHandler": "chainlit.langchain.callbacks",
105
+ "AsyncLangchainCallbackHandler": "chainlit.langchain.callbacks",
106
+ "LlamaIndexCallbackHandler": "chainlit.llama_index.callbacks",
107
+ "HaystackAgentCallbackHandler": "chainlit.haystack.callbacks",
108
+ "instrument_openai": "chainlit.openai",
109
+ "instrument_mistralai": "chainlit.mistralai",
110
+ }
111
+ )
112
+
113
+ __all__ = [
114
+ "__version__",
115
+ "ChatProfile",
116
+ "Starter",
117
+ "user_session",
118
+ "chat_context",
119
+ "CopilotFunction",
120
+ "AudioChunk",
121
+ "Action",
122
+ "User",
123
+ "PersistedUser",
124
+ "Audio",
125
+ "Pdf",
126
+ "Plotly",
127
+ "Image",
128
+ "Text",
129
+ "Component",
130
+ "Pyplot",
131
+ "File",
132
+ "Task",
133
+ "TaskList",
134
+ "TaskStatus",
135
+ "Video",
136
+ "ChatSettings",
137
+ "input_widget",
138
+ "Message",
139
+ "ErrorMessage",
140
+ "AskUserMessage",
141
+ "AskActionMessage",
142
+ "AskFileMessage",
143
+ "Step",
144
+ "step",
145
+ "ChatGeneration",
146
+ "CompletionGeneration",
147
+ "GenerationMessage",
148
+ "on_logout",
149
+ "on_chat_start",
150
+ "on_chat_end",
151
+ "on_chat_resume",
152
+ "on_stop",
153
+ "action_callback",
154
+ "author_rename",
155
+ "on_settings_update",
156
+ "password_auth_callback",
157
+ "header_auth_callback",
158
+ "sleep",
159
+ "run_sync",
160
+ "make_async",
161
+ "cache",
162
+ "context",
163
+ "LangchainCallbackHandler",
164
+ "AsyncLangchainCallbackHandler",
165
+ "LlamaIndexCallbackHandler",
166
+ "HaystackAgentCallbackHandler",
167
+ "instrument_openai",
168
+ "instrument_mistralai",
169
+ "password_auth_callback",
170
+ "header_auth_callback",
171
+ "oauth_callback",
172
+ "on_logout",
173
+ "on_message",
174
+ "on_chat_start",
175
+ "on_chat_resume",
176
+ "set_chat_profiles",
177
+ "set_starters",
178
+ "on_chat_end",
179
+ "on_audio_chunk",
180
+ "on_audio_end",
181
+ "author_rename",
182
+ "on_stop",
183
+ "action_callback",
184
+ "on_settings_update",
185
+ ]
186
+
187
+
188
+ def __dir__():
189
+ return __all__
@@ -0,0 +1,8 @@
1
+ """Util functions which are explicitly not part of the public API."""
2
+
3
+ from pathlib import Path
4
+
5
+
6
+ def is_path_inside(child_path: Path, parent_path: Path) -> bool:
7
+ """Check if the child path is inside the parent path."""
8
+ return parent_path.resolve() in child_path.resolve().parents
@@ -1,85 +1,35 @@
1
1
  import inspect
2
- import os
2
+ from typing import Any, Awaitable, Callable, Dict, List, Optional
3
3
 
4
- from dotenv import load_dotenv
5
-
6
- env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
7
-
8
- import asyncio
9
- from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
10
-
11
- from fastapi import Request, Response
12
- from pydantic.dataclasses import dataclass
13
- from starlette.datastructures import Headers
14
-
15
- if TYPE_CHECKING:
16
- from chainlit.haystack.callbacks import HaystackAgentCallbackHandler
17
- from chainlit.langchain.callbacks import (
18
- LangchainCallbackHandler,
19
- AsyncLangchainCallbackHandler,
20
- )
21
- from chainlit.llama_index.callbacks import LlamaIndexCallbackHandler
22
- from chainlit.openai import instrument_openai
23
- from chainlit.mistralai import instrument_mistralai
24
-
25
- import chainlit.input_widget as input_widget
26
4
  from chainlit.action import Action
27
- from chainlit.cache import cache
28
- from chainlit.chat_context import chat_context
29
- from chainlit.chat_settings import ChatSettings
30
5
  from chainlit.config import config
31
- from chainlit.context import context
32
- from chainlit.element import (
33
- Audio,
34
- Component,
35
- File,
36
- Image,
37
- Pdf,
38
- Plotly,
39
- Pyplot,
40
- Task,
41
- TaskList,
42
- TaskStatus,
43
- Text,
44
- Video,
45
- )
46
- from chainlit.logger import logger
47
- from chainlit.message import (
48
- AskActionMessage,
49
- AskFileMessage,
50
- AskUserMessage,
51
- ErrorMessage,
52
- Message,
53
- )
6
+ from chainlit.message import Message
54
7
  from chainlit.oauth_providers import get_configured_oauth_providers
55
8
  from chainlit.step import Step, step
56
- from chainlit.sync import make_async, run_sync
57
9
  from chainlit.telemetry import trace
58
- from chainlit.types import AudioChunk, ChatProfile, Starter, ThreadDict
59
- from chainlit.user import PersistedUser, User
60
- from chainlit.user_session import user_session
61
- from chainlit.utils import make_module_getattr, wrap_user_function
62
- from chainlit.version import __version__
63
- from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
64
-
65
- if env_found:
66
- logger.info("Loaded .env file")
10
+ from chainlit.types import ChatProfile, Starter, ThreadDict
11
+ from chainlit.user import User
12
+ from chainlit.utils import wrap_user_function
13
+ from fastapi import Request, Response
14
+ from starlette.datastructures import Headers
67
15
 
68
16
 
69
17
  @trace
70
- def password_auth_callback(func: Callable[[str, str], Optional[User]]) -> Callable:
18
+ def password_auth_callback(
19
+ func: Callable[[str, str], Awaitable[Optional[User]]]
20
+ ) -> Callable:
71
21
  """
72
22
  Framework agnostic decorator to authenticate the user.
73
23
 
74
24
  Args:
75
- func (Callable[[str, str], Optional[User]]): The authentication callback to execute. Takes the email and password as parameters.
25
+ func (Callable[[str, str], Awaitable[Optional[User]]]): The authentication callback to execute. Takes the email and password as parameters.
76
26
 
77
27
  Example:
78
28
  @cl.password_auth_callback
79
29
  async def password_auth_callback(username: str, password: str) -> Optional[User]:
80
30
 
81
31
  Returns:
82
- Callable[[str, str], Optional[User]]: The decorated authentication callback.
32
+ Callable[[str, str], Awaitable[Optional[User]]]: The decorated authentication callback.
83
33
  """
84
34
 
85
35
  config.code.password_auth_callback = wrap_user_function(func)
@@ -87,19 +37,21 @@ def password_auth_callback(func: Callable[[str, str], Optional[User]]) -> Callab
87
37
 
88
38
 
89
39
  @trace
90
- def header_auth_callback(func: Callable[[Headers], Optional[User]]) -> Callable:
40
+ def header_auth_callback(
41
+ func: Callable[[Headers], Awaitable[Optional[User]]]
42
+ ) -> Callable:
91
43
  """
92
44
  Framework agnostic decorator to authenticate the user via a header
93
45
 
94
46
  Args:
95
- func (Callable[[Headers], Optional[User]]): The authentication callback to execute.
47
+ func (Callable[[Headers], Awaitable[Optional[User]]]): The authentication callback to execute.
96
48
 
97
49
  Example:
98
50
  @cl.header_auth_callback
99
51
  async def header_auth_callback(headers: Headers) -> Optional[User]:
100
52
 
101
53
  Returns:
102
- Callable[[Headers], Optional[User]]: The decorated authentication callback.
54
+ Callable[[Headers], Awaitable[Optional[User]]]: The decorated authentication callback.
103
55
  """
104
56
 
105
57
  config.code.header_auth_callback = wrap_user_function(func)
@@ -108,20 +60,22 @@ def header_auth_callback(func: Callable[[Headers], Optional[User]]) -> Callable:
108
60
 
109
61
  @trace
110
62
  def oauth_callback(
111
- func: Callable[[str, str, Dict[str, str], User], Optional[User]]
63
+ func: Callable[
64
+ [str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]
65
+ ],
112
66
  ) -> Callable:
113
67
  """
114
68
  Framework agnostic decorator to authenticate the user via oauth
115
69
 
116
70
  Args:
117
- func (Callable[[str, str, Dict[str, str], User], Optional[User]]): The authentication callback to execute.
71
+ func (Callable[[str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]]): The authentication callback to execute.
118
72
 
119
73
  Example:
120
74
  @cl.oauth_callback
121
75
  async def oauth_callback(provider_id: str, token: str, raw_user_data: Dict[str, str], default_app_user: User, id_token: Optional[str]) -> Optional[User]:
122
76
 
123
77
  Returns:
124
- Callable[[str, str, Dict[str, str], User], Optional[User]]: The decorated authentication callback.
78
+ Callable[[str, str, Dict[str, str], User, Optional[str]], Awaitable[Optional[User]]]: The decorated authentication callback.
125
79
  """
126
80
 
127
81
  if len(get_configured_oauth_providers()) == 0:
@@ -205,16 +159,16 @@ def on_chat_resume(func: Callable[[ThreadDict], Any]) -> Callable:
205
159
 
206
160
  @trace
207
161
  def set_chat_profiles(
208
- func: Callable[[Optional["User"]], List["ChatProfile"]]
162
+ func: Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]],
209
163
  ) -> Callable:
210
164
  """
211
165
  Programmatic declaration of the available chat profiles (can depend on the User from the session if authentication is setup).
212
166
 
213
167
  Args:
214
- func (Callable[[Optional["User"]], List["ChatProfile"]]): The function declaring the chat profiles.
168
+ func (Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]): The function declaring the chat profiles.
215
169
 
216
170
  Returns:
217
- Callable[[Optional["User"]], List["ChatProfile"]]: The decorated function.
171
+ Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]: The decorated function.
218
172
  """
219
173
 
220
174
  config.code.set_chat_profiles = wrap_user_function(func)
@@ -222,15 +176,17 @@ def set_chat_profiles(
222
176
 
223
177
 
224
178
  @trace
225
- def set_starters(func: Callable[[Optional["User"]], List["Starter"]]) -> Callable:
179
+ def set_starters(
180
+ func: Callable[[Optional["User"]], Awaitable[List["Starter"]]]
181
+ ) -> Callable:
226
182
  """
227
183
  Programmatic declaration of the available starter (can depend on the User from the session if authentication is setup).
228
184
 
229
185
  Args:
230
- func (Callable[[Optional["User"]], List["Starter"]]): The function declaring the starters.
186
+ func (Callable[[Optional["User"]], Awaitable[List["Starter"]]]): The function declaring the starters.
231
187
 
232
188
  Returns:
233
- Callable[[Optional["User"]], List["Starter"]]: The decorated function.
189
+ Callable[[Optional["User"]], Awaitable[List["Starter"]]]: The decorated function.
234
190
  """
235
191
 
236
192
  config.code.set_starters = wrap_user_function(func)
@@ -288,14 +244,16 @@ def on_audio_end(func: Callable) -> Callable:
288
244
 
289
245
 
290
246
  @trace
291
- def author_rename(func: Callable[[str], str]) -> Callable[[str], str]:
247
+ def author_rename(
248
+ func: Callable[[str], Awaitable[str]]
249
+ ) -> Callable[[str], Awaitable[str]]:
292
250
  """
293
251
  Useful to rename the author of message to display more friendly author names in the UI.
294
252
  Args:
295
- func (Callable[[str], str]): The function to be called to rename an author. Takes the original author name as parameter.
253
+ func (Callable[[str], Awaitable[str]]): The function to be called to rename an author. Takes the original author name as parameter.
296
254
 
297
255
  Returns:
298
- Callable[[Any, str], Any]: The decorated function.
256
+ Callable[[Any, str], Awaitable[Any]]: The decorated function.
299
257
  """
300
258
 
301
259
  config.code.author_rename = wrap_user_function(func)
@@ -334,7 +292,7 @@ def action_callback(name: str) -> Callable:
334
292
 
335
293
 
336
294
  def on_settings_update(
337
- func: Callable[[Dict[str, Any]], Any]
295
+ func: Callable[[Dict[str, Any]], Any],
338
296
  ) -> Callable[[Dict[str, Any]], Any]:
339
297
  """
340
298
  Hook to react to the user changing any settings.
@@ -348,94 +306,3 @@ def on_settings_update(
348
306
 
349
307
  config.code.on_settings_update = wrap_user_function(func, with_task=True)
350
308
  return func
351
-
352
-
353
- def sleep(duration: int):
354
- """
355
- Sleep for a given duration.
356
- Args:
357
- duration (int): The duration in seconds.
358
- """
359
- return asyncio.sleep(duration)
360
-
361
-
362
- @dataclass()
363
- class CopilotFunction:
364
- name: str
365
- args: Dict[str, Any]
366
-
367
- def acall(self):
368
- return context.emitter.send_call_fn(self.name, self.args)
369
-
370
-
371
- __getattr__ = make_module_getattr(
372
- {
373
- "LangchainCallbackHandler": "chainlit.langchain.callbacks",
374
- "AsyncLangchainCallbackHandler": "chainlit.langchain.callbacks",
375
- "LlamaIndexCallbackHandler": "chainlit.llama_index.callbacks",
376
- "HaystackAgentCallbackHandler": "chainlit.haystack.callbacks",
377
- "instrument_openai": "chainlit.openai",
378
- "instrument_mistralai": "chainlit.mistralai",
379
- }
380
- )
381
-
382
- __all__ = [
383
- "ChatProfile",
384
- "Starter",
385
- "user_session",
386
- "chat_context",
387
- "CopilotFunction",
388
- "AudioChunk",
389
- "Action",
390
- "User",
391
- "PersistedUser",
392
- "Audio",
393
- "Pdf",
394
- "Plotly",
395
- "Image",
396
- "Text",
397
- "Component",
398
- "Pyplot",
399
- "File",
400
- "Task",
401
- "TaskList",
402
- "TaskStatus",
403
- "Video",
404
- "ChatSettings",
405
- "input_widget",
406
- "Message",
407
- "ErrorMessage",
408
- "AskUserMessage",
409
- "AskActionMessage",
410
- "AskFileMessage",
411
- "Step",
412
- "step",
413
- "ChatGeneration",
414
- "CompletionGeneration",
415
- "GenerationMessage",
416
- "on_logout",
417
- "on_chat_start",
418
- "on_chat_end",
419
- "on_chat_resume",
420
- "on_stop",
421
- "action_callback",
422
- "author_rename",
423
- "on_settings_update",
424
- "password_auth_callback",
425
- "header_auth_callback",
426
- "sleep",
427
- "run_sync",
428
- "make_async",
429
- "cache",
430
- "context",
431
- "LangchainCallbackHandler",
432
- "AsyncLangchainCallbackHandler",
433
- "LlamaIndexCallbackHandler",
434
- "HaystackAgentCallbackHandler",
435
- "instrument_openai",
436
- "instrument_mistralai",
437
- ]
438
-
439
-
440
- def __dir__():
441
- return __all__
@@ -4,7 +4,17 @@ import site
4
4
  import sys
5
5
  from importlib import util
6
6
  from pathlib import Path
7
- from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Union
7
+ from typing import (
8
+ TYPE_CHECKING,
9
+ Any,
10
+ Awaitable,
11
+ Callable,
12
+ Dict,
13
+ List,
14
+ Literal,
15
+ Optional,
16
+ Union,
17
+ )
8
18
 
9
19
  import tomli
10
20
  from chainlit.logger import logger
@@ -14,6 +24,8 @@ from dataclasses_json import DataClassJsonMixin
14
24
  from pydantic.dataclasses import Field, dataclass
15
25
  from starlette.datastructures import Headers
16
26
 
27
+ from ._utils import is_path_inside
28
+
17
29
  if TYPE_CHECKING:
18
30
  from chainlit.action import Action
19
31
  from chainlit.element import ElementBased
@@ -270,10 +282,14 @@ class CodeSettings:
270
282
  # Module object loaded from the module_name
271
283
  module: Any = None
272
284
  # Bunch of callbacks defined by the developer
273
- password_auth_callback: Optional[Callable[[str, str], Optional["User"]]] = None
274
- header_auth_callback: Optional[Callable[[Headers], Optional["User"]]] = None
285
+ password_auth_callback: Optional[
286
+ Callable[[str, str], Awaitable[Optional["User"]]]
287
+ ] = None
288
+ header_auth_callback: Optional[
289
+ Callable[[Headers], Awaitable[Optional["User"]]]
290
+ ] = None
275
291
  oauth_callback: Optional[
276
- Callable[[str, str, Dict[str, str], "User"], Optional["User"]]
292
+ Callable[[str, str, Dict[str, str], "User"], Awaitable[Optional["User"]]]
277
293
  ] = None
278
294
  on_logout: Optional[Callable[["Request", "Response"], Any]] = None
279
295
  on_stop: Optional[Callable[[], Any]] = None
@@ -284,12 +300,14 @@ class CodeSettings:
284
300
  on_audio_chunk: Optional[Callable[["AudioChunk"], Any]] = None
285
301
  on_audio_end: Optional[Callable[[List["ElementBased"]], Any]] = None
286
302
 
287
- author_rename: Optional[Callable[[str], str]] = None
303
+ author_rename: Optional[Callable[[str], Awaitable[str]]] = None
288
304
  on_settings_update: Optional[Callable[[Dict[str, Any]], Any]] = None
289
- set_chat_profiles: Optional[Callable[[Optional["User"]], List["ChatProfile"]]] = (
290
- None
291
- )
292
- set_starters: Optional[Callable[[Optional["User"]], List["Starter"]]] = None
305
+ set_chat_profiles: Optional[
306
+ Callable[[Optional["User"]], Awaitable[List["ChatProfile"]]]
307
+ ] = None
308
+ set_starters: Optional[
309
+ Callable[[Optional["User"]], Awaitable[List["Starter"]]]
310
+ ] = None
293
311
 
294
312
 
295
313
  @dataclass()
@@ -327,33 +345,41 @@ class ChainlitConfig:
327
345
  # fallback to root language (ex: `de` when `de-DE` is not found)
328
346
  parent_language = language.split("-")[0]
329
347
 
330
- translation_lib_file_path = os.path.join(
331
- config_translation_dir, f"{language}.json"
332
- )
333
- translation_lib_parent_language_file_path = os.path.join(
334
- config_translation_dir, f"{parent_language}.json"
335
- )
336
- default_translation_lib_file_path = os.path.join(
337
- config_translation_dir, f"{default_language}.json"
338
- )
348
+ translation_dir = Path(config_translation_dir)
339
349
 
340
- if os.path.exists(translation_lib_file_path):
341
- with open(translation_lib_file_path, "r", encoding="utf-8") as f:
342
- translation = json.load(f)
343
- elif os.path.exists(translation_lib_parent_language_file_path):
350
+ translation_lib_file_path = translation_dir / f"{language}.json"
351
+ translation_lib_parent_language_file_path = (
352
+ translation_dir / f"{parent_language}.json"
353
+ )
354
+ default_translation_lib_file_path = translation_dir / f"{default_language}.json"
355
+
356
+ if (
357
+ is_path_inside(translation_lib_file_path, translation_dir)
358
+ and translation_lib_file_path.is_file()
359
+ ):
360
+ translation = json.loads(
361
+ translation_lib_file_path.read_text(encoding="utf-8")
362
+ )
363
+ elif (
364
+ is_path_inside(translation_lib_parent_language_file_path, translation_dir)
365
+ and translation_lib_parent_language_file_path.is_file()
366
+ ):
344
367
  logger.warning(
345
368
  f"Translation file for {language} not found. Using parent translation {parent_language}."
346
369
  )
347
- with open(
348
- translation_lib_parent_language_file_path, "r", encoding="utf-8"
349
- ) as f:
350
- translation = json.load(f)
351
- elif os.path.exists(default_translation_lib_file_path):
370
+ translation = json.loads(
371
+ translation_lib_parent_language_file_path.read_text(encoding="utf-8")
372
+ )
373
+ elif (
374
+ is_path_inside(default_translation_lib_file_path, translation_dir)
375
+ and default_translation_lib_file_path.is_file()
376
+ ):
352
377
  logger.warning(
353
378
  f"Translation file for {language} not found. Using default translation {default_language}."
354
379
  )
355
- with open(default_translation_lib_file_path, "r", encoding="utf-8") as f:
356
- translation = json.load(f)
380
+ translation = json.loads(
381
+ default_translation_lib_file_path.read_text(encoding="utf-8")
382
+ )
357
383
 
358
384
  return translation
359
385