chainlit 1.1.305__tar.gz → 1.1.400__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 (82) hide show
  1. {chainlit-1.1.305 → chainlit-1.1.400}/PKG-INFO +1 -1
  2. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/__init__.py +19 -5
  3. chainlit-1.1.400/chainlit/chat_context.py +64 -0
  4. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/config.py +6 -3
  5. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/context.py +9 -0
  6. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/copilot/dist/index.js +150 -147
  7. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/data/__init__.py +8 -12
  8. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/data/sql_alchemy.py +0 -4
  9. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/discord/app.py +44 -24
  10. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/emitter.py +9 -11
  11. chainlit-1.1.305/chainlit/frontend/dist/assets/DailyMotion-4f715d15.js → chainlit-1.1.400/chainlit/frontend/dist/assets/DailyMotion-e2c926d0.js +1 -1
  12. chainlit-1.1.305/chainlit/frontend/dist/assets/Facebook-25f45c09.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Facebook-88f80aba.js +1 -1
  13. chainlit-1.1.305/chainlit/frontend/dist/assets/FilePlayer-04482650.js → chainlit-1.1.400/chainlit/frontend/dist/assets/FilePlayer-febd1b0d.js +1 -1
  14. chainlit-1.1.305/chainlit/frontend/dist/assets/Kaltura-37152a96.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Kaltura-606fe0bd.js +1 -1
  15. chainlit-1.1.305/chainlit/frontend/dist/assets/Mixcloud-914b75ee.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Mixcloud-b3db090a.js +1 -1
  16. chainlit-1.1.305/chainlit/frontend/dist/assets/Mux-fb751398.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Mux-ca847a7d.js +1 -1
  17. chainlit-1.1.305/chainlit/frontend/dist/assets/Preview-85fbb8da.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Preview-7a3747b5.js +1 -1
  18. chainlit-1.1.305/chainlit/frontend/dist/assets/SoundCloud-8afad6c0.js → chainlit-1.1.400/chainlit/frontend/dist/assets/SoundCloud-0da01fb1.js +1 -1
  19. chainlit-1.1.305/chainlit/frontend/dist/assets/Streamable-08844d93.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Streamable-4a6ab048.js +1 -1
  20. chainlit-1.1.305/chainlit/frontend/dist/assets/Twitch-1b95f5c8.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Twitch-3e260619.js +1 -1
  21. chainlit-1.1.305/chainlit/frontend/dist/assets/Vidyard-5028fa2f.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Vidyard-73692980.js +1 -1
  22. chainlit-1.1.305/chainlit/frontend/dist/assets/Vimeo-ca732959.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Vimeo-6627c7a8.js +1 -1
  23. chainlit-1.1.305/chainlit/frontend/dist/assets/Wistia-74e58d71.js → chainlit-1.1.400/chainlit/frontend/dist/assets/Wistia-27df9c66.js +1 -1
  24. chainlit-1.1.305/chainlit/frontend/dist/assets/YouTube-bdf4ca10.js → chainlit-1.1.400/chainlit/frontend/dist/assets/YouTube-a11d419d.js +1 -1
  25. chainlit-1.1.400/chainlit/frontend/dist/assets/index-d66d1800.js +730 -0
  26. chainlit-1.1.305/chainlit/frontend/dist/assets/react-plotly-cf9b99cc.js → chainlit-1.1.400/chainlit/frontend/dist/assets/react-plotly-012ed517.js +1 -1
  27. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/frontend/dist/index.html +1 -1
  28. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/haystack/callbacks.py +1 -3
  29. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/langchain/callbacks.py +39 -20
  30. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/llama_index/callbacks.py +8 -28
  31. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/message.py +4 -17
  32. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/mistralai/__init__.py +2 -5
  33. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/openai/__init__.py +0 -2
  34. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/server.py +1 -1
  35. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/session.py +2 -12
  36. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/slack/app.py +38 -31
  37. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/socket.py +37 -1
  38. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/step.py +37 -32
  39. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/teams/app.py +23 -18
  40. chainlit-1.1.400/chainlit/translations/zh-CN.json +229 -0
  41. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/types.py +0 -1
  42. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/user_session.py +0 -3
  43. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/utils.py +1 -0
  44. {chainlit-1.1.305 → chainlit-1.1.400}/pyproject.toml +1 -1
  45. chainlit-1.1.305/chainlit/frontend/dist/assets/index-621140f9.js +0 -727
  46. {chainlit-1.1.305 → chainlit-1.1.400}/README.md +0 -0
  47. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/__main__.py +0 -0
  48. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/action.py +0 -0
  49. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/auth.py +0 -0
  50. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/cache.py +0 -0
  51. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/chat_settings.py +0 -0
  52. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/cli/__init__.py +0 -0
  53. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/copilot/dist/assets/logo_dark-2a3cf740.svg +0 -0
  54. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/copilot/dist/assets/logo_light-b078e7bc.svg +0 -0
  55. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/data/acl.py +0 -0
  56. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/data/dynamodb.py +0 -0
  57. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/data/storage_clients.py +0 -0
  58. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/discord/__init__.py +0 -0
  59. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/element.py +0 -0
  60. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/frontend/dist/assets/index-aaf974a9.css +0 -0
  61. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/frontend/dist/assets/logo_dark-2a3cf740.svg +0 -0
  62. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/frontend/dist/assets/logo_light-b078e7bc.svg +0 -0
  63. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/frontend/dist/favicon.svg +0 -0
  64. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/haystack/__init__.py +0 -0
  65. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/hello.py +0 -0
  66. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/input_widget.py +0 -0
  67. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/langchain/__init__.py +0 -0
  68. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/langflow/__init__.py +0 -0
  69. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/llama_index/__init__.py +0 -0
  70. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/logger.py +0 -0
  71. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/markdown.py +0 -0
  72. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/oauth_providers.py +0 -0
  73. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/py.typed +0 -0
  74. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/secret.py +0 -0
  75. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/slack/__init__.py +0 -0
  76. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/sync.py +0 -0
  77. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/teams/__init__.py +0 -0
  78. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/telemetry.py +0 -0
  79. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/translations/en-US.json +0 -0
  80. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/translations.py +0 -0
  81. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/user.py +0 -0
  82. {chainlit-1.1.305 → chainlit-1.1.400}/chainlit/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 1.1.305
3
+ Version: 1.1.400
4
4
  Summary: Build Conversational AI.
5
5
  Home-page: https://github.com/Chainlit/chainlit
6
6
  License: Apache-2.0 license
@@ -1,3 +1,4 @@
1
+ import inspect
1
2
  import os
2
3
 
3
4
  from dotenv import load_dotenv
@@ -21,11 +22,10 @@ if TYPE_CHECKING:
21
22
  from chainlit.openai import instrument_openai
22
23
  from chainlit.mistralai import instrument_mistralai
23
24
 
24
- from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
25
-
26
25
  import chainlit.input_widget as input_widget
27
26
  from chainlit.action import Action
28
27
  from chainlit.cache import cache
28
+ from chainlit.chat_context import chat_context
29
29
  from chainlit.chat_settings import ChatSettings
30
30
  from chainlit.config import config
31
31
  from chainlit.context import context
@@ -60,6 +60,7 @@ from chainlit.user import PersistedUser, User
60
60
  from chainlit.user_session import user_session
61
61
  from chainlit.utils import make_module_getattr, wrap_user_function
62
62
  from chainlit.version import __version__
63
+ from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
63
64
 
64
65
  if env_found:
65
66
  logger.info("Loaded .env file")
@@ -156,7 +157,15 @@ def on_message(func: Callable) -> Callable:
156
157
  Callable[[str], Any]: The decorated on_message function.
157
158
  """
158
159
 
159
- config.code.on_message = wrap_user_function(func)
160
+ async def with_parent_id(message: Message):
161
+ async with Step(name="on_message", type="run", parent_id=message.id) as s:
162
+ s.input = message.content
163
+ if len(inspect.signature(func).parameters) > 0:
164
+ await func(message)
165
+ else:
166
+ await func()
167
+
168
+ config.code.on_message = wrap_user_function(with_parent_id)
160
169
  return func
161
170
 
162
171
 
@@ -172,7 +181,9 @@ def on_chat_start(func: Callable) -> Callable:
172
181
  Callable[], Any]: The decorated hook.
173
182
  """
174
183
 
175
- config.code.on_chat_start = wrap_user_function(func, with_task=True)
184
+ config.code.on_chat_start = wrap_user_function(
185
+ step(func, name="on_chat_start", type="run"), with_task=True
186
+ )
176
187
  return func
177
188
 
178
189
 
@@ -270,7 +281,9 @@ def on_audio_end(func: Callable) -> Callable:
270
281
  Callable[], Any]: The decorated hook.
271
282
  """
272
283
 
273
- config.code.on_audio_end = wrap_user_function(func, with_task=True)
284
+ config.code.on_audio_end = wrap_user_function(
285
+ step(func, name="on_audio_end", type="run"), with_task=True
286
+ )
274
287
  return func
275
288
 
276
289
 
@@ -370,6 +383,7 @@ __all__ = [
370
383
  "ChatProfile",
371
384
  "Starter",
372
385
  "user_session",
386
+ "chat_context",
373
387
  "CopilotFunction",
374
388
  "AudioChunk",
375
389
  "Action",
@@ -0,0 +1,64 @@
1
+ from typing import TYPE_CHECKING, Dict, List
2
+
3
+ from chainlit.context import context
4
+
5
+ if TYPE_CHECKING:
6
+ from chainlit.message import Message
7
+
8
+ chat_contexts: Dict[str, List["Message"]] = {}
9
+
10
+
11
+ class ChatContext:
12
+ def get(self) -> List["Message"]:
13
+ if not context.session:
14
+ return []
15
+
16
+ if context.session.id not in chat_contexts:
17
+ # Create a new chat context
18
+ chat_contexts[context.session.id] = []
19
+
20
+ return chat_contexts[context.session.id].copy()
21
+
22
+ def add(self, message: "Message"):
23
+ if not context.session:
24
+ return
25
+
26
+ if context.session.id not in chat_contexts:
27
+ chat_contexts[context.session.id] = []
28
+
29
+ if message not in chat_contexts[context.session.id]:
30
+ chat_contexts[context.session.id].append(message)
31
+
32
+ return message
33
+
34
+ def remove(self, message: "Message") -> bool:
35
+ if not context.session:
36
+ return False
37
+
38
+ if context.session.id not in chat_contexts:
39
+ return False
40
+
41
+ if message in chat_contexts[context.session.id]:
42
+ chat_contexts[context.session.id].remove(message)
43
+ return True
44
+
45
+ return False
46
+
47
+ def clear(self) -> None:
48
+ if context.session and context.session.id in chat_contexts:
49
+ chat_contexts[context.session.id] = []
50
+
51
+ def to_openai(self):
52
+ messages = []
53
+ for message in self.get():
54
+ if message.type == "assistant_message":
55
+ messages.append({"role": "assistant", "content": message.content})
56
+ elif message.type == "user_message":
57
+ messages.append({"role": "user", "content": message.content})
58
+ else:
59
+ messages.append({"role": "system", "content": message.content})
60
+
61
+ return messages
62
+
63
+
64
+ chat_context = ChatContext()
@@ -91,6 +91,8 @@ auto_tag_thread = true
91
91
  # Sample rate of the audio
92
92
  sample_rate = 44100
93
93
 
94
+ edit_message = true
95
+
94
96
  [UI]
95
97
  # Name of the assistant.
96
98
  name = "Assistant"
@@ -101,8 +103,8 @@ name = "Assistant"
101
103
  # Large size content are by default collapsed for a cleaner ui
102
104
  default_collapse_content = true
103
105
 
104
- # Hide the chain of thought details from the user in the UI.
105
- hide_cot = false
106
+ # Chain of Thought (CoT) display mode. Can be "hidden", "tool_call" or "full".
107
+ cot = "full"
106
108
 
107
109
  # Link to your github repo. This will add a github button in the UI's header.
108
110
  # github = ""
@@ -238,13 +240,14 @@ class FeaturesSettings(DataClassJsonMixin):
238
240
  latex: bool = False
239
241
  unsafe_allow_html: bool = False
240
242
  auto_tag_thread: bool = True
243
+ edit_message: bool = True
241
244
 
242
245
 
243
246
  @dataclass()
244
247
  class UISettings(DataClassJsonMixin):
245
248
  name: str
246
249
  description: str = ""
247
- hide_cot: bool = False
250
+ cot: Literal["hidden", "tool_call", "full"] = "full"
248
251
  # Large size content are by default collapsed for a cleaner ui
249
252
  default_collapse_content: bool = True
250
253
  github: Optional[str] = None
@@ -11,6 +11,8 @@ if TYPE_CHECKING:
11
11
  from chainlit.step import Step
12
12
  from chainlit.user import PersistedUser, User
13
13
 
14
+ CL_RUN_NAMES = ["on_chat_start", "on_message", "on_audio_end"]
15
+
14
16
 
15
17
  class ChainlitContextException(Exception):
16
18
  def __init__(self, msg="Chainlit context not found", *args, **kwargs):
@@ -28,6 +30,13 @@ class ChainlitContext:
28
30
  if self.active_steps:
29
31
  return self.active_steps[-1]
30
32
 
33
+ @property
34
+ def current_run(self):
35
+ if self.active_steps:
36
+ return next(
37
+ (step for step in self.active_steps if step.name in CL_RUN_NAMES), None
38
+ )
39
+
31
40
  def __init__(
32
41
  self,
33
42
  session: Union["HTTPSession", "WebsocketSession"],