chainlit 1.1.303__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)
chainlit/server.py CHANGED
@@ -317,8 +317,6 @@ def get_user_facing_url(url: URL):
317
317
  Return the user facing URL for a given URL.
318
318
  Handles deployment with proxies (like cloud run).
319
319
  """
320
-
321
- ROOT_PATH = os.environ.get("CHAINLIT_ROOT_PATH", "")
322
320
  chainlit_url = os.environ.get("CHAINLIT_URL")
323
321
 
324
322
  # No config, we keep the URL as is
@@ -524,9 +522,12 @@ async def oauth_callback(
524
522
  "token_type": "bearer",
525
523
  }
526
524
  )
525
+
526
+ root_path = os.environ.get("CHAINLIT_ROOT_PATH", "")
527
+
527
528
  response = RedirectResponse(
528
529
  # FIXME: redirect to the right frontend base url to improve the dev environment
529
- url=f"/login/callback?{params}",
530
+ url=f"{root_path}/login/callback?{params}",
530
531
  )
531
532
  response.delete_cookie("oauth_state")
532
533
  return response
@@ -601,9 +602,12 @@ async def oauth_azure_hf_callback(
601
602
  "token_type": "bearer",
602
603
  }
603
604
  )
605
+
606
+ root_path = os.environ.get("CHAINLIT_ROOT_PATH", "")
607
+
604
608
  response = RedirectResponse(
605
609
  # FIXME: redirect to the right frontend base url to improve the dev environment
606
- url=f"/login/callback?{params}",
610
+ url=f"{root_path}/login/callback?{params}",
607
611
  status_code=302,
608
612
  )
609
613
  response.delete_cookie("oauth_state")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 1.1.303
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,11 +52,12 @@ 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
58
59
  chainlit/secret.py,sha256=cQvIFGTQ7r2heC8EOGdgifSZZYqslh-qQxhUhKhD8vU,295
59
- chainlit/server.py,sha256=NXqTS_bSRrpqj6wSNh2xOIFJvCrXTLEHbOVm0Ls_MR4,28240
60
+ chainlit/server.py,sha256=kZ_L3v1C-jM85HJZyZZYPkiPtfYpP9iQRn5sdMOlMGo,28322
60
61
  chainlit/session.py,sha256=SOX2zFct3apiSNcIzCDWgDRsUFgUG_6hewqWU8gfIZE,9694
61
62
  chainlit/slack/__init__.py,sha256=Q41ztJHeVmpoXVgVqAcwGOufQp_bjf7dDT7eEXDdhPI,207
62
63
  chainlit/slack/app.py,sha256=FgrlaupsCo-_1m8FiFcS5s-wFg_28bCjfKnawvlVbEM,11646
@@ -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.303.dist-info/METADATA,sha256=koit2Jy5GpodiSOkktZXTL20VjYuqTV8cRAX5yfaY-A,6291
77
- chainlit-1.1.303.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
78
- chainlit-1.1.303.dist-info/entry_points.txt,sha256=FrkqdjrFl8juSnvBndniyX7XuKojmUwO4ghRh-CFMQc,45
79
- chainlit-1.1.303.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,,