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

@@ -14,7 +14,7 @@
14
14
  <script>
15
15
  const global = globalThis;
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-2dad8c58.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-03f89089.js"></script>
18
18
  <link rel="stylesheet" href="/assets/index-bdffdaa0.css">
19
19
  </head>
20
20
  <body>
chainlit/lc/utils.py CHANGED
@@ -1,7 +1,6 @@
1
1
  from typing import Any
2
2
  from chainlit.types import LLMSettings
3
3
  from typing import List, Optional
4
- from langchain.llms.base import BaseLLM
5
4
 
6
5
 
7
6
  def run_langchain_agent(agent: Any, input_str: str):
@@ -19,7 +18,7 @@ def run_langchain_agent(agent: Any, input_str: str):
19
18
  return raw_res, output_key
20
19
 
21
20
 
22
- def get_llm_settings(llm: BaseLLM, stop: Optional[List[str]] = None):
21
+ def get_llm_settings(llm, stop: Optional[List[str]] = None):
23
22
  if llm.__class__.__name__ == "OpenAI":
24
23
  return LLMSettings(
25
24
  model_name=llm.model_name,
chainlit/sdk.py CHANGED
@@ -1,8 +1,8 @@
1
1
  from typing import Union
2
- import os
3
2
  import time
3
+ import uuid
4
4
  from chainlit.session import Session
5
- from chainlit.types import ElementDisplay, LLMSettings, ElementType, AskSpec
5
+ from chainlit.types import LLMSettings, AskSpec
6
6
  from chainlit.client import BaseClient
7
7
  from socketio.exceptions import TimeoutError
8
8
  import inspect
@@ -46,89 +46,6 @@ class Chainlit:
46
46
  """Get the 'client' property from the session."""
47
47
  return self._get_session_property("client")
48
48
 
49
- def send_remote_element(
50
- self,
51
- url: str,
52
- name: str,
53
- type: ElementType,
54
- display: ElementDisplay,
55
- ):
56
- """Send an element to the UI."""
57
- element = {
58
- "name": name,
59
- "url": url,
60
- "type": type,
61
- "display": display,
62
- }
63
- if self.emit and element:
64
- self.emit("element", element)
65
-
66
- def send_local_element(
67
- self,
68
- ext: str,
69
- content: bytes,
70
- name: str,
71
- type: ElementType,
72
- display: ElementDisplay,
73
- ):
74
- """Send an element to the UI."""
75
- if self.client:
76
- # Cloud is enabled, upload the element to S3
77
- url = self.client.upload_element(ext=ext, content=content)
78
- if url:
79
- element = self.client.create_element(
80
- name=name, url=url, type=type, display=display
81
- )
82
- else:
83
- element = {
84
- "name": name,
85
- "content": content.decode("utf-8") if type == "text" else content,
86
- "type": type,
87
- "display": display,
88
- }
89
- if self.emit and element:
90
- self.emit("element", element)
91
-
92
- def send_local_image(self, path: str, name: str, display: ElementDisplay = "side"):
93
- """Send a local image to the UI."""
94
- if not self.emit:
95
- return
96
-
97
- with open(path, "rb") as f:
98
- _, ext = os.path.splitext(path)
99
- type = "image"
100
- image_data = f.read()
101
- self.send_local_element(ext, image_data, name, type, display)
102
-
103
- def send_image(self, url: str, name: str, display: ElementDisplay = "side"):
104
- """Send an image to the UI."""
105
- if not self.emit:
106
- return
107
-
108
- type = "image"
109
- self.send_remote_element(url, name, type, display)
110
-
111
- def send_text(self, text: str, name: str, display: ElementDisplay = "side"):
112
- """Send a text element to the UI."""
113
- if not self.emit:
114
- return
115
-
116
- type = "text"
117
- ext = ".txt"
118
- self.send_local_element(ext, bytes(text, "utf-8"), name, type, display)
119
-
120
- def send_action(self, name: str, trigger: str, description=""):
121
- """Send an action to the UI."""
122
- if not self.emit:
123
- return
124
-
125
- action = {
126
- "name": name,
127
- "trigger": trigger,
128
- "description": description,
129
- }
130
- self.emit("action", action)
131
-
132
49
  def send_message(
133
50
  self,
134
51
  author: str,
@@ -162,6 +79,9 @@ class Chainlit:
162
79
  if self.client:
163
80
  message_id = self.client.create_message(msg)
164
81
  msg["id"] = message_id
82
+ else:
83
+ message_id = uuid.uuid4().hex
84
+ msg["tempId"] = message_id
165
85
 
166
86
  msg["createdAt"] = current_milli_time()
167
87
 
@@ -170,6 +90,8 @@ class Chainlit:
170
90
  else:
171
91
  self.emit("message", msg)
172
92
 
93
+ return str(message_id)
94
+
173
95
  def send_ask_timeout(self, author: str):
174
96
  """Send a prompt timeout message to the UI."""
175
97
  self.send_message(author=author, content="Time out", is_error=True)
@@ -295,3 +217,10 @@ def get_sdk() -> Union[Chainlit, None]:
295
217
  sdk = candidate
296
218
  break
297
219
  return sdk
220
+
221
+
222
+ def get_emit():
223
+ sdk = get_sdk()
224
+ if sdk:
225
+ return sdk.emit
226
+ return None
chainlit/server.py CHANGED
@@ -12,7 +12,7 @@ from chainlit.user_session import user_sessions
12
12
  from chainlit.client import CloudClient
13
13
  from chainlit.sdk import Chainlit
14
14
  from chainlit.markdown import get_markdown_str
15
- from chainlit.types import Action
15
+ from chainlit.action import Action
16
16
  from chainlit.telemetry import trace
17
17
  from chainlit.logger import logger
18
18
 
@@ -243,14 +243,16 @@ def process_message(session: Session, author: str, input_str: str):
243
243
  # If a langchain agent is available, run it
244
244
  if config.lc_run:
245
245
  # If the developer provided a custom run function, use it
246
- res = config.lc_run(langchain_agent, input_str)
246
+ config.lc_run(langchain_agent, input_str)
247
+ return
247
248
  else:
248
249
  # Otherwise, use the default run function
249
250
  raw_res, output_key = run_langchain_agent(langchain_agent, input_str)
250
251
 
251
252
  if config.lc_postprocess:
252
253
  # If the developer provided a custom postprocess function, use it
253
- res = config.lc_postprocess(raw_res)
254
+ config.lc_postprocess(raw_res)
255
+ return
254
256
  elif output_key is not None:
255
257
  # Use the output key if provided
256
258
  res = raw_res[output_key]
@@ -293,11 +295,11 @@ def message():
293
295
 
294
296
  def process_action(session: Session, action: Action):
295
297
  __chainlit_sdk__ = Chainlit(session)
296
- callback = config.action_callbacks.get(action["name"])
298
+ callback = config.action_callbacks.get(action.name)
297
299
  if callback:
298
300
  callback(action)
299
301
  else:
300
- logger.warning("No callback found for action %s", action["name"])
302
+ logger.warning("No callback found for action %s", action.name)
301
303
 
302
304
 
303
305
  @app.route("/action", methods=["POST"])
@@ -308,7 +310,7 @@ def on_action():
308
310
 
309
311
  body = request.json
310
312
  session_id = body["sessionId"]
311
- action = body["action"]
313
+ action = Action(**body["action"])
312
314
 
313
315
  session = need_session(session_id)
314
316
 
chainlit/types.py CHANGED
@@ -38,12 +38,6 @@ class AskFileResponse:
38
38
  content: bytes
39
39
 
40
40
 
41
- class Action(TypedDict):
42
- name: str
43
- trigger: str
44
- description: str
45
-
46
-
47
41
  @dataclass_json
48
42
  @dataclass
49
43
  class LLMSettings:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chainlit
3
- Version: 0.1.103
3
+ Version: 0.2.1
4
4
  Summary: A faster way to build chatbot UIs.
5
5
  Home-page: https://github.com/Chainlit/chainlit
6
6
  License: Apache-2.0 license
@@ -37,7 +37,7 @@ Description-Content-Type: text/markdown
37
37
 
38
38
  **A faster way to build chatbot UIs.**
39
39
 
40
- Chainlit lets you create chatbot UIs on top of any Python code in minutes. It’s all Python, open-source, and free!
40
+ Chainlit lets you create chatbot UIs on top of any Python code in minutes. It’s all Python, open-source, and free! Some of the key features include intermediary steps visualisation, element management & display (images, text, carousel, etc.) as well as cloud deployment.
41
41
 
42
42
  [![](https://dcbadge.vercel.app/api/server/ZThrUxbAYw?style=flat)](https://discord.gg/ZThrUxbAYw)
43
43
  [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/chainlit_io.svg?style=social&label=Follow%20%40chainlit_io)](https://twitter.com/chainlit_io)
@@ -1,35 +1,37 @@
1
- chainlit/__init__.py,sha256=eGsejuwLFxmjRXWeTps9qKIM_xEBcu6zOqlCYuR7SwI,14345
1
+ chainlit/__init__.py,sha256=HJ6KYCxKx12uWh-WT8XGGnpwpq4t1jOhWJvK3gO-kn4,12876
2
2
  chainlit/__main__.py,sha256=7Vg3w3T3qDuz4KDu5lQhLH6lQ3cYdume7gHH7Z1V97U,87
3
+ chainlit/action.py,sha256=84pKfaakRW6uUETrIyxQzIzyH859TgCmmZTMp_if9Og,765
3
4
  chainlit/cli/__init__.py,sha256=hOUGpafUkOTbAi4QRNHoebWhLJNk9B7Sr-ERYTXhh5s,3527
4
5
  chainlit/cli/auth.py,sha256=G437UK4BvLA4wWPz_KPDwN6_6dnchMtHWr4tqu5XN-M,4093
5
6
  chainlit/cli/deploy.py,sha256=dOqgmnVI4xsorwd0g6GgQAIB92oBgli-02HKqs1GWTQ,2594
6
7
  chainlit/cli/utils.py,sha256=Pn6ANnw9GgdUduiMphnb8RiGUPRbzDafkCHM2rOPBj4,716
7
- chainlit/client.py,sha256=QqJo2kpTQFmKGThhz0LSv_7PPF5sb0Cf1A7qzdRxdvM,5150
8
- chainlit/config.py,sha256=vt6eudSRgaLXxPM_kN4McuGe18nvKu_K7SVIa7eKVp0,6385
9
- chainlit/frontend/dist/assets/index-2dad8c58.js,sha256=ivDEL0mDGoP-xcbGEo52_6XE4pBXFy9BvXIa9O1ofLU,2070511
8
+ chainlit/client.py,sha256=vIr7J-UJWunm-yIIgqdwKeCccKSNAY4oOBP3ofm2LW0,5278
9
+ chainlit/config.py,sha256=Tp5or5IVdjQRoYXyPnMU3AWVkDwbaetNbpQjBwM4CoU,6426
10
+ chainlit/element.py,sha256=9g9XtRNm7hTAJN6-xVDMorBM2DPg9a6Qta9DBBktOIE,3293
11
+ chainlit/frontend/dist/assets/index-03f89089.js,sha256=iEEQj5vIw0qkSftqMa3dMTP07iz03pR_HUv2RMbRGmM,2071080
10
12
  chainlit/frontend/dist/assets/index-bdffdaa0.css,sha256=vf_aoJGXu6-Km_p1XCjmgjXrcE8IEIRRggIkiIyY-qo,4317
11
13
  chainlit/frontend/dist/assets/logo_dark-bc7401f6.svg,sha256=vHQB9g-n5OqOmuH3Fduuc7ZMg0EmMsGyO9cEnYwLbHg,8889
12
14
  chainlit/frontend/dist/assets/logo_light-f19fc2ea.svg,sha256=8Z_C6t-0V9QL9ldmLjaLfp2REcGDuaTeNynj6-6muNI,8891
13
15
  chainlit/frontend/dist/favicon.svg,sha256=0Cy8x28obT5eWW3nxZRhsEvu6_zMqrqbg0y6hT3D0Q0,6455
14
- chainlit/frontend/dist/index.html,sha256=mwKCq_f23WAEWnxTpsvgnnarH2GO22mzML2vhKuTuhI,772
16
+ chainlit/frontend/dist/index.html,sha256=mBKpZcmK39vFw-XPH_TMCFVk3QM_IcrU9O6o9u2HTAI,772
15
17
  chainlit/hello.py,sha256=dQ7TmXpSQ6mB8Uu3PqAK7eWi_bCgcdexS9EckTdXgLQ,344
16
18
  chainlit/lc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
19
  chainlit/lc/chainlit_handler.py,sha256=4621t82ObvYAyprtoC1s_ywz97M_vWgqAkUrcfKhsLU,8077
18
20
  chainlit/lc/monkey.py,sha256=02c9L0iwqM4nM-fMYUrqMgM2cJY_1kUNYARnpDyWVSk,863
19
21
  chainlit/lc/new_monkey.py,sha256=vRkEi77JpcQDj42iJsqRmPv0u18XyYYCDqbSl8ZP0Sg,5388
20
22
  chainlit/lc/old_monkey.py,sha256=-rT9I_OqRrYtiU8XL3J2dAvamUPNkqdv2skAOzcn5Do,4129
21
- chainlit/lc/utils.py,sha256=WYbtzLn0yQORwRGuP0ylQGllRcsRzIVwfxQTMbEf4n4,1117
23
+ chainlit/lc/utils.py,sha256=CtEVmZagVuWx1GrckX3cngKBgUhLuBc1JsoQEQ7GNLw,1068
22
24
  chainlit/logger.py,sha256=G6-k0WYt7Ghp0QPOZrKlQNAy41X8L7KJyKiHiumxAYw,398
23
25
  chainlit/markdown.py,sha256=CCE5FTqQTKJA0bkMo8nuk8hqkaWSF38VXnjAM69GlTw,1618
24
- chainlit/sdk.py,sha256=kH1FTma_OcZ95T1rAqpuFa5AWKlq1Vr6FSvpumgYZws,9047
25
- chainlit/server.py,sha256=6dNTrP3Ii2GQ0E1uvgVuGQ7WJJJ-DXoySBOsb2PWCdg,9948
26
+ chainlit/sdk.py,sha256=1Zj1VZmv8GMdoYwHcgh1v7U8aQCsk31CdiZmt_lIBzs,6747
27
+ chainlit/server.py,sha256=wCO4T0TWkk1xqZayIlDqhoZO9hNuZM4er2EOd2KD4M4,9991
26
28
  chainlit/session.py,sha256=Guu2NvUYd7o37tTWCC19rDls0JtoK2xAKdbKt9EOKWs,813
27
29
  chainlit/telemetry.py,sha256=G7lLwevIKSyV511JEnse9B_Zy5qYA695R9MdIHEcBkw,2017
28
- chainlit/types.py,sha256=aH49wJ-BUh_6rg4BdeesuJurBFeAz0n5mDUmrzPl3NE,1044
30
+ chainlit/types.py,sha256=TKn8Q9JA7cWg4a3cPy4XryF-hbTW5BWKUbCiqE6wD4w,965
29
31
  chainlit/user_session.py,sha256=ODTLoJowXmRwczQBRwCWpBxRhwC7jZ7z0hEQAXY0ZDQ,1145
30
32
  chainlit/version.py,sha256=iosXhlXclBwBqlADFKEilxAC2wWKbtuBKi87AmPi7s8,196
31
33
  chainlit/watch.py,sha256=9kllA562yvdTceTO7V9xh1WDSXJzccERrAlCQ-8voQE,1551
32
- chainlit-0.1.103.dist-info/METADATA,sha256=oatVbWoCPBlezAyP-Ec7RMMu8CQM50b2rXns5IzGu2c,3779
33
- chainlit-0.1.103.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
34
- chainlit-0.1.103.dist-info/entry_points.txt,sha256=FrkqdjrFl8juSnvBndniyX7XuKojmUwO4ghRh-CFMQc,45
35
- chainlit-0.1.103.dist-info/RECORD,,
34
+ chainlit-0.2.1.dist-info/METADATA,sha256=ft3E8LoiwK-exDcyUUmzS1TFNdz6rQssDMtFnreC1xs,3933
35
+ chainlit-0.2.1.dist-info/WHEEL,sha256=WGfLGfLX43Ei_YORXSnT54hxFygu34kMpcQdmgmEwCQ,88
36
+ chainlit-0.2.1.dist-info/entry_points.txt,sha256=FrkqdjrFl8juSnvBndniyX7XuKojmUwO4ghRh-CFMQc,45
37
+ chainlit-0.2.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.5.2
2
+ Generator: poetry-core 1.6.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any