chainlit 1.1.304__py3-none-any.whl → 1.1.305__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.

chainlit/__init__.py CHANGED
@@ -19,6 +19,9 @@ if TYPE_CHECKING:
19
19
  )
20
20
  from chainlit.llama_index.callbacks import LlamaIndexCallbackHandler
21
21
  from chainlit.openai import instrument_openai
22
+ from chainlit.mistralai import instrument_mistralai
23
+
24
+ from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
22
25
 
23
26
  import chainlit.input_widget as input_widget
24
27
  from chainlit.action import Action
@@ -57,7 +60,6 @@ from chainlit.user import PersistedUser, User
57
60
  from chainlit.user_session import user_session
58
61
  from chainlit.utils import make_module_getattr, wrap_user_function
59
62
  from chainlit.version import __version__
60
- from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
61
63
 
62
64
  if env_found:
63
65
  logger.info("Loaded .env file")
@@ -360,6 +362,7 @@ __getattr__ = make_module_getattr(
360
362
  "LlamaIndexCallbackHandler": "chainlit.llama_index.callbacks",
361
363
  "HaystackAgentCallbackHandler": "chainlit.haystack.callbacks",
362
364
  "instrument_openai": "chainlit.openai",
365
+ "instrument_mistralai": "chainlit.mistralai",
363
366
  }
364
367
  )
365
368
 
@@ -416,6 +419,7 @@ __all__ = [
416
419
  "LlamaIndexCallbackHandler",
417
420
  "HaystackAgentCallbackHandler",
418
421
  "instrument_openai",
422
+ "instrument_mistralai",
419
423
  ]
420
424
 
421
425
 
@@ -0,0 +1,53 @@
1
+ import asyncio
2
+ from typing import Union
3
+
4
+ from literalai import ChatGeneration, CompletionGeneration
5
+ from literalai.helper import timestamp_utc
6
+
7
+ from chainlit.context import get_context
8
+ from chainlit.step import Step
9
+ from chainlit.utils import check_module_version
10
+
11
+
12
+ def instrument_mistralai():
13
+ from literalai.instrumentation.mistralai import instrument_mistralai
14
+
15
+ def on_new_generation(
16
+ generation: Union["ChatGeneration", "CompletionGeneration"], timing
17
+ ):
18
+ context = get_context()
19
+
20
+ parent_id = None
21
+ if context.current_step:
22
+ parent_id = context.current_step.id
23
+ elif context.session.root_message:
24
+ parent_id = context.session.root_message.id
25
+
26
+ step = Step(
27
+ name=generation.model if generation.model else generation.provider,
28
+ type="llm",
29
+ parent_id=parent_id,
30
+ )
31
+ step.generation = generation
32
+ # Convert start/end time from seconds to milliseconds
33
+ step.start = (
34
+ timestamp_utc(timing.get("start"))
35
+ if timing.get("start", None) is not None
36
+ else None
37
+ )
38
+ step.end = (
39
+ timestamp_utc(timing.get("end"))
40
+ if timing.get("end", None) is not None
41
+ else None
42
+ )
43
+
44
+ if isinstance(generation, ChatGeneration):
45
+ step.input = generation.messages
46
+ step.output = generation.message_completion # type: ignore
47
+ else:
48
+ step.input = generation.prompt
49
+ step.output = generation.completion
50
+
51
+ asyncio.create_task(step.send())
52
+
53
+ instrument_mistralai(None, on_new_generation)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 1.1.304
3
+ Version: 1.1.305
4
4
  Summary: Build Conversational AI.
5
5
  Home-page: https://github.com/Chainlit/chainlit
6
6
  License: Apache-2.0 license
@@ -21,7 +21,7 @@ Requires-Dist: fastapi (>=0.110.1,<0.111.0)
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)
24
- Requires-Dist: literalai (==0.0.604)
24
+ Requires-Dist: literalai (==0.0.607)
25
25
  Requires-Dist: nest-asyncio (>=1.5.6,<2.0.0)
26
26
  Requires-Dist: numpy (>=1.24.4,<2.0.0) ; python_version < "3.9"
27
27
  Requires-Dist: numpy (>=1.26,<2.0) ; python_version >= "3.9"
@@ -1,4 +1,4 @@
1
- chainlit/__init__.py,sha256=g6MbN4Vuf8PbJTpTE2XNqVt-GklWQCk8g5_JZGbrB8M,11052
1
+ chainlit/__init__.py,sha256=wA6GUIlzgv5nT7i4EckzrFj8mUxFXjTGOeupJYLkvR0,11191
2
2
  chainlit/__main__.py,sha256=7Vg3w3T3qDuz4KDu5lQhLH6lQ3cYdume7gHH7Z1V97U,87
3
3
  chainlit/action.py,sha256=k-GsblVHI4DnDWFyF-RZgq3KfdfAFICFh2OBeU4w8N8,1410
4
4
  chainlit/auth.py,sha256=lLHePwmwKzX0LiWqpTAtKTdSecrDLqCMSY9Yw4c-TD8,2681
@@ -52,6 +52,7 @@ chainlit/llama_index/callbacks.py,sha256=THFmwotSF_ibqFuaQgxGvEjgKmmzoGJKNlVI75S
52
52
  chainlit/logger.py,sha256=wTwRSZsLfXwWy6U4351IgWAm4KCMThgxm9EZpjGUEr4,373
53
53
  chainlit/markdown.py,sha256=VUpqW7MqgjiPIQYHU4funwqC4GmHZBu_TGZTjTI4B0k,2025
54
54
  chainlit/message.py,sha256=aEw2VNZ0-4mAC3PSG-0j5ZjO1qZ9MaUFDnfiAXLM_q8,17997
55
+ chainlit/mistralai/__init__.py,sha256=79jNSSF0BdIwA0jmkREeN1diZ1RLoPA2BbaJWO7KyAE,1655
55
56
  chainlit/oauth_providers.py,sha256=Mv31biQ84EBJfQGBxqhFfnbpl-jfQ_Zn6IxKY3XZg6Q,22972
56
57
  chainlit/openai/__init__.py,sha256=DJP_ptclLUM5Zylr4RO1Vk0lCufo3yDqXyH5J9izYS8,1814
57
58
  chainlit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -73,7 +74,7 @@ chainlit/user.py,sha256=8PgRJvv59b7BKTNguObo68gyFoOGNJfVkT3WW-fvhAM,671
73
74
  chainlit/user_session.py,sha256=G1amgs1_h2tVn4mtAXZmunm9nlBHQ_rCYvJQh3nsVwQ,1645
74
75
  chainlit/utils.py,sha256=w3UIzvaQ72y5VrycFoWaqS_NocS40No7mzPWqkelzCE,3939
75
76
  chainlit/version.py,sha256=iosXhlXclBwBqlADFKEilxAC2wWKbtuBKi87AmPi7s8,196
76
- chainlit-1.1.304.dist-info/METADATA,sha256=E2kJ1O5OcOTkOIGnI9KhWaVKkUO0Y-97Wy6qwED-vzw,6291
77
- chainlit-1.1.304.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
78
- chainlit-1.1.304.dist-info/entry_points.txt,sha256=FrkqdjrFl8juSnvBndniyX7XuKojmUwO4ghRh-CFMQc,45
79
- chainlit-1.1.304.dist-info/RECORD,,
77
+ chainlit-1.1.305.dist-info/METADATA,sha256=Q1wbUcQ_qWt52az_jGLX3DDGl-iw90WsHKMZZ8Wsnuw,6291
78
+ chainlit-1.1.305.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
79
+ chainlit-1.1.305.dist-info/entry_points.txt,sha256=FrkqdjrFl8juSnvBndniyX7XuKojmUwO4ghRh-CFMQc,45
80
+ chainlit-1.1.305.dist-info/RECORD,,