chainlit 2.0.0__py3-none-any.whl → 2.0.dev0__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.

Files changed (98) hide show
  1. chainlit/__init__.py +57 -56
  2. chainlit/action.py +10 -12
  3. chainlit/{auth/__init__.py → auth.py} +34 -26
  4. chainlit/cache.py +6 -4
  5. chainlit/callbacks.py +7 -52
  6. chainlit/chat_context.py +2 -2
  7. chainlit/chat_settings.py +1 -3
  8. chainlit/cli/__init__.py +2 -15
  9. chainlit/config.py +70 -41
  10. chainlit/context.py +9 -8
  11. chainlit/copilot/dist/index.js +874 -8533
  12. chainlit/data/__init__.py +8 -96
  13. chainlit/data/acl.py +2 -3
  14. chainlit/data/base.py +15 -1
  15. chainlit/data/dynamodb.py +4 -7
  16. chainlit/data/literalai.py +6 -4
  17. chainlit/data/sql_alchemy.py +9 -10
  18. chainlit/data/{storage_clients/azure.py → storage_clients.py} +33 -2
  19. chainlit/discord/__init__.py +4 -4
  20. chainlit/discord/app.py +1 -2
  21. chainlit/element.py +9 -41
  22. chainlit/emitter.py +21 -17
  23. chainlit/frontend/dist/assets/DailyMotion-b4b7af47.js +1 -0
  24. chainlit/frontend/dist/assets/Facebook-572972a0.js +1 -0
  25. chainlit/frontend/dist/assets/FilePlayer-85c69ca8.js +1 -0
  26. chainlit/frontend/dist/assets/Kaltura-dfc24672.js +1 -0
  27. chainlit/frontend/dist/assets/Mixcloud-705011f4.js +1 -0
  28. chainlit/frontend/dist/assets/Mux-4201a9e6.js +1 -0
  29. chainlit/frontend/dist/assets/Preview-23ba40a6.js +1 -0
  30. chainlit/frontend/dist/assets/SoundCloud-1a582d51.js +1 -0
  31. chainlit/frontend/dist/assets/Streamable-5017c4ba.js +1 -0
  32. chainlit/frontend/dist/assets/Twitch-bb2de2fa.js +1 -0
  33. chainlit/frontend/dist/assets/Vidyard-54e269b1.js +1 -0
  34. chainlit/frontend/dist/assets/Vimeo-d92c37dd.js +1 -0
  35. chainlit/frontend/dist/assets/Wistia-25a1363b.js +1 -0
  36. chainlit/frontend/dist/assets/YouTube-616e8cb7.js +1 -0
  37. chainlit/frontend/dist/assets/index-aaf974a9.css +1 -0
  38. chainlit/frontend/dist/assets/index-f5df2072.js +1027 -0
  39. chainlit/frontend/dist/assets/{react-plotly-BpxUS-ab.js → react-plotly-f0315f86.js} +94 -94
  40. chainlit/frontend/dist/index.html +3 -2
  41. chainlit/haystack/callbacks.py +4 -5
  42. chainlit/input_widget.py +4 -6
  43. chainlit/langchain/callbacks.py +47 -56
  44. chainlit/langflow/__init__.py +0 -1
  45. chainlit/llama_index/callbacks.py +7 -7
  46. chainlit/message.py +10 -8
  47. chainlit/mistralai/__init__.py +2 -3
  48. chainlit/oauth_providers.py +12 -113
  49. chainlit/openai/__init__.py +7 -6
  50. chainlit/secret.py +1 -1
  51. chainlit/server.py +181 -491
  52. chainlit/session.py +5 -7
  53. chainlit/slack/__init__.py +3 -3
  54. chainlit/slack/app.py +2 -3
  55. chainlit/socket.py +103 -78
  56. chainlit/step.py +29 -21
  57. chainlit/sync.py +1 -2
  58. chainlit/teams/__init__.py +3 -3
  59. chainlit/teams/app.py +0 -1
  60. chainlit/types.py +4 -20
  61. chainlit/user.py +1 -2
  62. chainlit/utils.py +2 -3
  63. chainlit/version.py +2 -3
  64. {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/METADATA +39 -27
  65. chainlit-2.0.dev0.dist-info/RECORD +96 -0
  66. chainlit/auth/cookie.py +0 -123
  67. chainlit/auth/jwt.py +0 -37
  68. chainlit/data/chainlit_data_layer.py +0 -584
  69. chainlit/data/storage_clients/__init__.py +0 -0
  70. chainlit/data/storage_clients/azure_blob.py +0 -80
  71. chainlit/data/storage_clients/base.py +0 -22
  72. chainlit/data/storage_clients/gcs.py +0 -78
  73. chainlit/data/storage_clients/s3.py +0 -49
  74. chainlit/frontend/dist/assets/DailyMotion-DgRzV5GZ.js +0 -1
  75. chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +0 -22
  76. chainlit/frontend/dist/assets/Facebook-C0vx6HWv.js +0 -1
  77. chainlit/frontend/dist/assets/FilePlayer-CdhzeHPP.js +0 -1
  78. chainlit/frontend/dist/assets/Kaltura-5iVmeUct.js +0 -1
  79. chainlit/frontend/dist/assets/Mixcloud-C2zi77Ex.js +0 -1
  80. chainlit/frontend/dist/assets/Mux-Vkebogdf.js +0 -1
  81. chainlit/frontend/dist/assets/Preview-DwY_sEIl.js +0 -1
  82. chainlit/frontend/dist/assets/SoundCloud-CREBXAWo.js +0 -1
  83. chainlit/frontend/dist/assets/Streamable-B5Lu25uy.js +0 -1
  84. chainlit/frontend/dist/assets/Twitch-y9iKCcM1.js +0 -1
  85. chainlit/frontend/dist/assets/Vidyard-ClYvcuEu.js +0 -1
  86. chainlit/frontend/dist/assets/Vimeo-D6HvM2jt.js +0 -1
  87. chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +0 -1
  88. chainlit/frontend/dist/assets/YouTube-D10tR6CJ.js +0 -1
  89. chainlit/frontend/dist/assets/index-CI4qFOt5.js +0 -8665
  90. chainlit/frontend/dist/assets/index-CrrqM0nZ.css +0 -1
  91. chainlit/translations/nl-NL.json +0 -229
  92. chainlit-2.0.0.dist-info/RECORD +0 -106
  93. /chainlit/copilot/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
  94. /chainlit/copilot/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
  95. /chainlit/frontend/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
  96. /chainlit/frontend/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
  97. {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/WHEEL +0 -0
  98. {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/entry_points.txt +0 -0
@@ -21,10 +21,11 @@
21
21
  <script>
22
22
  const global = globalThis;
23
23
  </script>
24
- <script type="module" crossorigin src="/assets/index-CI4qFOt5.js"></script>
25
- <link rel="stylesheet" crossorigin href="/assets/index-CrrqM0nZ.css">
24
+ <script type="module" crossorigin src="/assets/index-f5df2072.js"></script>
25
+ <link rel="stylesheet" href="/assets/index-aaf974a9.css">
26
26
  </head>
27
27
  <body>
28
28
  <div id="root"></div>
29
+
29
30
  </body>
30
31
  </html>
@@ -1,13 +1,12 @@
1
1
  import re
2
2
  from typing import Any, Generic, List, Optional, TypeVar
3
3
 
4
- from haystack.agents import Agent, Tool
5
- from haystack.agents.agent_step import AgentStep
6
- from literalai.helper import utc_now
7
-
8
4
  from chainlit import Message
9
5
  from chainlit.step import Step
10
6
  from chainlit.sync import run_sync
7
+ from haystack.agents import Agent, Tool
8
+ from haystack.agents.agent_step import AgentStep
9
+ from literalai.helper import utc_now
11
10
 
12
11
  T = TypeVar("T")
13
12
 
@@ -132,7 +131,7 @@ class HaystackAgentCallbackHandler:
132
131
  tool_result: str,
133
132
  tool_name: Optional[str] = None,
134
133
  tool_input: Optional[str] = None,
135
- **kwargs: Any,
134
+ **kwargs: Any
136
135
  ) -> None:
137
136
  # Tool finished, send step with tool_result
138
137
  tool_step = self.stack.pop()
chainlit/input_widget.py CHANGED
@@ -2,10 +2,8 @@ from abc import abstractmethod
2
2
  from collections import defaultdict
3
3
  from typing import Any, Dict, List, Optional
4
4
 
5
- from pydantic import Field
6
- from pydantic.dataclasses import dataclass
7
-
8
5
  from chainlit.types import InputWidgetType
6
+ from pydantic.dataclasses import Field, dataclass
9
7
 
10
8
 
11
9
  @dataclass
@@ -77,7 +75,7 @@ class Select(InputWidget):
77
75
  initial: Optional[str] = None
78
76
  initial_index: Optional[int] = None
79
77
  initial_value: Optional[str] = None
80
- values: List[str] = Field(default_factory=list)
78
+ values: List[str] = Field(default_factory=lambda: [])
81
79
  items: Dict[str, str] = Field(default_factory=lambda: defaultdict(dict))
82
80
 
83
81
  def __post_init__(
@@ -169,8 +167,8 @@ class Tags(InputWidget):
169
167
  """Useful to create an input for an array of strings."""
170
168
 
171
169
  type: InputWidgetType = "tags"
172
- initial: List[str] = Field(default_factory=list)
173
- values: List[str] = Field(default_factory=list)
170
+ initial: List[str] = Field(default_factory=lambda: [])
171
+ values: List[str] = Field(default_factory=lambda: [])
174
172
 
175
173
  def to_dict(self) -> Dict[str, Any]:
176
174
  return {
@@ -3,19 +3,17 @@ import time
3
3
  from typing import Any, Dict, List, Optional, Sequence, Tuple, TypedDict, Union
4
4
  from uuid import UUID
5
5
 
6
- import pydantic
6
+ from chainlit.context import context_var
7
+ from chainlit.message import Message
8
+ from chainlit.step import Step
9
+ from langchain.callbacks.tracers.base import BaseTracer
7
10
  from langchain.callbacks.tracers.schemas import Run
8
11
  from langchain.schema import BaseMessage
9
12
  from langchain_core.outputs import ChatGenerationChunk, GenerationChunk
10
- from langchain_core.tracers.base import AsyncBaseTracer
11
13
  from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
12
14
  from literalai.helper import utc_now
13
15
  from literalai.observability.step import TrueStepType
14
16
 
15
- from chainlit.context import context_var
16
- from chainlit.message import Message
17
- from chainlit.step import Step
18
-
19
17
  DEFAULT_ANSWER_PREFIX_TOKENS = ["Final", "Answer", ":"]
20
18
 
21
19
 
@@ -124,14 +122,6 @@ class GenerationHelper:
124
122
  key: self.ensure_values_serializable(value)
125
123
  for key, value in data.items()
126
124
  }
127
- elif isinstance(data, pydantic.BaseModel):
128
- # Fallback to support pydantic v1
129
- # https://docs.pydantic.dev/latest/migration/#changes-to-pydanticbasemodel
130
- if pydantic.VERSION.startswith("1"):
131
- return data.dict()
132
-
133
- # pydantic v2
134
- return data.model_dump() # pyright: ignore reportAttributeAccessIssue
135
125
  elif isinstance(data, list):
136
126
  return [self.ensure_values_serializable(item) for item in data]
137
127
  elif isinstance(data, (str, int, float, bool, type(None))):
@@ -259,7 +249,7 @@ DEFAULT_TO_IGNORE = [
259
249
  DEFAULT_TO_KEEP = ["retriever", "llm", "agent", "chain", "tool"]
260
250
 
261
251
 
262
- class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
252
+ class LangchainTracer(BaseTracer, GenerationHelper, FinalStreamHelper):
263
253
  steps: Dict[str, Step]
264
254
  parent_id_map: Dict[str, str]
265
255
  ignored_runs: set
@@ -278,7 +268,7 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
278
268
  to_keep: Optional[List[str]] = None,
279
269
  **kwargs: Any,
280
270
  ) -> None:
281
- AsyncBaseTracer.__init__(self, **kwargs)
271
+ BaseTracer.__init__(self, **kwargs)
282
272
  GenerationHelper.__init__(self)
283
273
  FinalStreamHelper.__init__(
284
274
  self,
@@ -306,7 +296,7 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
306
296
  else:
307
297
  self.to_keep = to_keep
308
298
 
309
- async def on_chat_model_start(
299
+ def on_chat_model_start(
310
300
  self,
311
301
  serialized: Dict[str, Any],
312
302
  messages: List[List[BaseMessage]],
@@ -315,9 +305,8 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
315
305
  parent_run_id: Optional["UUID"] = None,
316
306
  tags: Optional[List[str]] = None,
317
307
  metadata: Optional[Dict[str, Any]] = None,
318
- name: Optional[str] = None,
319
308
  **kwargs: Any,
320
- ) -> Run:
309
+ ) -> Any:
321
310
  lc_messages = messages[0]
322
311
  self.chat_generations[str(run_id)] = {
323
312
  "input_messages": lc_messages,
@@ -326,48 +315,46 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
326
315
  "tt_first_token": None,
327
316
  }
328
317
 
329
- return await super().on_chat_model_start(
318
+ return super().on_chat_model_start(
330
319
  serialized,
331
320
  messages,
332
321
  run_id=run_id,
333
322
  parent_run_id=parent_run_id,
334
323
  tags=tags,
335
324
  metadata=metadata,
336
- name=name,
337
325
  **kwargs,
338
326
  )
339
327
 
340
- async def on_llm_start(
328
+ def on_llm_start(
341
329
  self,
342
330
  serialized: Dict[str, Any],
343
331
  prompts: List[str],
344
332
  *,
345
333
  run_id: "UUID",
346
- parent_run_id: Optional[UUID] = None,
347
334
  tags: Optional[List[str]] = None,
335
+ parent_run_id: Optional["UUID"] = None,
348
336
  metadata: Optional[Dict[str, Any]] = None,
337
+ name: Optional[str] = None,
349
338
  **kwargs: Any,
350
- ) -> None:
351
- await super().on_llm_start(
339
+ ) -> Run:
340
+ self.completion_generations[str(run_id)] = {
341
+ "prompt": prompts[0],
342
+ "start": time.time(),
343
+ "token_count": 0,
344
+ "tt_first_token": None,
345
+ }
346
+ return super().on_llm_start(
352
347
  serialized,
353
348
  prompts,
354
349
  run_id=run_id,
355
350
  parent_run_id=parent_run_id,
356
351
  tags=tags,
357
352
  metadata=metadata,
353
+ name=name,
358
354
  **kwargs,
359
355
  )
360
356
 
361
- self.completion_generations[str(run_id)] = {
362
- "prompt": prompts[0],
363
- "start": time.time(),
364
- "token_count": 0,
365
- "tt_first_token": None,
366
- }
367
-
368
- return None
369
-
370
- async def on_llm_new_token(
357
+ def on_llm_new_token(
371
358
  self,
372
359
  token: str,
373
360
  *,
@@ -375,14 +362,7 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
375
362
  run_id: "UUID",
376
363
  parent_run_id: Optional["UUID"] = None,
377
364
  **kwargs: Any,
378
- ) -> None:
379
- await super().on_llm_new_token(
380
- token=token,
381
- chunk=chunk,
382
- run_id=run_id,
383
- parent_run_id=parent_run_id,
384
- **kwargs,
385
- )
365
+ ) -> Run:
386
366
  if isinstance(chunk, ChatGenerationChunk):
387
367
  start = self.chat_generations[str(run_id)]
388
368
  else:
@@ -397,13 +377,24 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
397
377
  if self.answer_reached:
398
378
  if not self.final_stream:
399
379
  self.final_stream = Message(content="")
400
- await self.final_stream.send()
401
- await self.final_stream.stream_token(token)
380
+ self._run_sync(self.final_stream.send())
381
+ self._run_sync(self.final_stream.stream_token(token))
402
382
  self.has_streamed_final_answer = True
403
383
  else:
404
384
  self.answer_reached = self._check_if_answer_reached()
405
385
 
406
- async def _persist_run(self, run: Run) -> None:
386
+ return super().on_llm_new_token(
387
+ token,
388
+ chunk=chunk,
389
+ run_id=run_id,
390
+ parent_run_id=parent_run_id,
391
+ )
392
+
393
+ def _run_sync(self, co): # TODO: WHAT TO DO WITH THIS?
394
+ context_var.set(self.context)
395
+ self.context.loop.create_task(co)
396
+
397
+ def _persist_run(self, run: Run) -> None:
407
398
  pass
408
399
 
409
400
  def _get_run_parent_id(self, run: Run):
@@ -454,8 +445,8 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
454
445
  self.ignored_runs.add(str(run.id))
455
446
  return ignore, parent_id
456
447
 
457
- async def _start_trace(self, run: Run) -> None:
458
- await super()._start_trace(run)
448
+ def _start_trace(self, run: Run) -> None:
449
+ super()._start_trace(run)
459
450
  context_var.set(self.context)
460
451
 
461
452
  ignore, parent_id = self._should_ignore_run(run)
@@ -468,7 +459,7 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
468
459
  if ignore:
469
460
  return
470
461
 
471
- step_type: TrueStepType = "undefined"
462
+ step_type: "TrueStepType" = "undefined"
472
463
  if run.run_type == "agent":
473
464
  step_type = "run"
474
465
  elif run.run_type == "chain":
@@ -498,9 +489,9 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
498
489
 
499
490
  self.steps[str(run.id)] = step
500
491
 
501
- await step.send()
492
+ self._run_sync(step.send())
502
493
 
503
- async def _on_run_update(self, run: Run) -> None:
494
+ def _on_run_update(self, run: Run) -> None:
504
495
  """Process a run upon update."""
505
496
  context_var.set(self.context)
506
497
 
@@ -585,10 +576,10 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
585
576
 
586
577
  if current_step:
587
578
  current_step.end = utc_now()
588
- await current_step.update()
579
+ self._run_sync(current_step.update())
589
580
 
590
581
  if self.final_stream and self.has_streamed_final_answer:
591
- await self.final_stream.update()
582
+ self._run_sync(self.final_stream.update())
592
583
 
593
584
  return
594
585
 
@@ -608,16 +599,16 @@ class LangchainTracer(AsyncBaseTracer, GenerationHelper, FinalStreamHelper):
608
599
  else output
609
600
  )
610
601
  current_step.end = utc_now()
611
- await current_step.update()
602
+ self._run_sync(current_step.update())
612
603
 
613
- async def _on_error(self, error: BaseException, *, run_id: UUID, **kwargs: Any):
604
+ def _on_error(self, error: BaseException, *, run_id: UUID, **kwargs: Any):
614
605
  context_var.set(self.context)
615
606
 
616
607
  if current_step := self.steps.get(str(run_id), None):
617
608
  current_step.is_error = True
618
609
  current_step.output = str(error)
619
610
  current_step.end = utc_now()
620
- await current_step.update()
611
+ self._run_sync(current_step.update())
621
612
 
622
613
  on_llm_error = _on_error
623
614
  on_chain_error = _on_error
@@ -8,7 +8,6 @@ if not check_module_version("langflow", "0.1.4"):
8
8
  from typing import Dict, Optional, Union
9
9
 
10
10
  import httpx
11
-
12
11
  from chainlit.telemetry import trace_event
13
12
 
14
13
 
@@ -1,5 +1,8 @@
1
1
  from typing import Any, Dict, List, Optional
2
2
 
3
+ from chainlit.context import context_var
4
+ from chainlit.element import Text
5
+ from chainlit.step import Step, StepType
3
6
  from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
4
7
  from literalai.helper import utc_now
5
8
  from llama_index.core.callbacks import TokenCountingHandler
@@ -7,10 +10,6 @@ from llama_index.core.callbacks.schema import CBEventType, EventPayload
7
10
  from llama_index.core.llms import ChatMessage, ChatResponse, CompletionResponse
8
11
  from llama_index.core.tools.types import ToolMetadata
9
12
 
10
- from chainlit.context import context_var
11
- from chainlit.element import Text
12
- from chainlit.step import Step, StepType
13
-
14
13
  DEFAULT_IGNORE = [
15
14
  CBEventType.CHUNKING,
16
15
  CBEventType.SYNTHESIZE,
@@ -144,15 +143,16 @@ class LlamaIndexCallbackHandler(TokenCountingHandler):
144
143
  context_var.get().loop.create_task(step.update())
145
144
 
146
145
  elif event_type == CBEventType.LLM:
147
- formatted_messages = payload.get(EventPayload.MESSAGES) # type: Optional[List[ChatMessage]]
146
+ formatted_messages = payload.get(
147
+ EventPayload.MESSAGES
148
+ ) # type: Optional[List[ChatMessage]]
148
149
  formatted_prompt = payload.get(EventPayload.PROMPT)
149
150
  response = payload.get(EventPayload.RESPONSE)
150
151
 
151
152
  if formatted_messages:
152
153
  messages = [
153
154
  GenerationMessage(
154
- role=m.role.value, # type: ignore
155
- content=m.content or "",
155
+ role=m.role.value, content=m.content or "" # type: ignore
156
156
  )
157
157
  for m in formatted_messages
158
158
  ]
chainlit/message.py CHANGED
@@ -5,9 +5,6 @@ import uuid
5
5
  from abc import ABC
6
6
  from typing import Dict, List, Optional, Union, cast
7
7
 
8
- from literalai.helper import utc_now
9
- from literalai.observability.step import MessageStepType
10
-
11
8
  from chainlit.action import Action
12
9
  from chainlit.chat_context import chat_context
13
10
  from chainlit.config import config
@@ -25,6 +22,8 @@ from chainlit.types import (
25
22
  AskSpec,
26
23
  FileDict,
27
24
  )
25
+ from literalai.helper import utc_now
26
+ from literalai.observability.step import MessageStepType
28
27
 
29
28
 
30
29
  class MessageBase(ABC):
@@ -43,6 +42,7 @@ class MessageBase(ABC):
43
42
  metadata: Optional[Dict] = None
44
43
  tags: Optional[List[str]] = None
45
44
  wait_for_answer = False
45
+ indent: Optional[int] = None
46
46
 
47
47
  def __post_init__(self) -> None:
48
48
  trace_event(f"init {self.__class__.__name__}")
@@ -59,7 +59,7 @@ class MessageBase(ABC):
59
59
  @classmethod
60
60
  def from_dict(self, _dict: StepDict):
61
61
  type = _dict.get("type", "assistant_message")
62
- return Message(
62
+ message = Message(
63
63
  id=_dict["id"],
64
64
  parent_id=_dict.get("parentId"),
65
65
  created_at=_dict["createdAt"],
@@ -67,9 +67,10 @@ class MessageBase(ABC):
67
67
  author=_dict.get("name", config.ui.name),
68
68
  type=type, # type: ignore
69
69
  language=_dict.get("language"),
70
- metadata=_dict.get("metadata", {}),
71
70
  )
72
71
 
72
+ return message
73
+
73
74
  def to_dict(self) -> StepDict:
74
75
  _dict: StepDict = {
75
76
  "id": self.id,
@@ -85,6 +86,7 @@ class MessageBase(ABC):
85
86
  "streaming": self.streaming,
86
87
  "isError": self.is_error,
87
88
  "waitForAnswer": self.wait_for_answer,
89
+ "indent": self.indent,
88
90
  "metadata": self.metadata or {},
89
91
  "tags": self.tags,
90
92
  }
@@ -112,7 +114,7 @@ class MessageBase(ABC):
112
114
  except Exception as e:
113
115
  if self.fail_on_persist_error:
114
116
  raise e
115
- logger.error(f"Failed to persist message update: {e!s}")
117
+ logger.error(f"Failed to persist message update: {str(e)}")
116
118
 
117
119
  await context.emitter.update_step(step_dict)
118
120
 
@@ -132,7 +134,7 @@ class MessageBase(ABC):
132
134
  except Exception as e:
133
135
  if self.fail_on_persist_error:
134
136
  raise e
135
- logger.error(f"Failed to persist message deletion: {e!s}")
137
+ logger.error(f"Failed to persist message deletion: {str(e)}")
136
138
 
137
139
  await context.emitter.delete_step(step_dict)
138
140
 
@@ -148,7 +150,7 @@ class MessageBase(ABC):
148
150
  except Exception as e:
149
151
  if self.fail_on_persist_error:
150
152
  raise e
151
- logger.error(f"Failed to persist message creation: {e!s}")
153
+ logger.error(f"Failed to persist message creation: {str(e)}")
152
154
 
153
155
  return step_dict
154
156
 
@@ -1,11 +1,10 @@
1
1
  import asyncio
2
2
  from typing import Union
3
3
 
4
- from literalai import ChatGeneration, CompletionGeneration
5
- from literalai.helper import timestamp_utc
6
-
7
4
  from chainlit.context import get_context
8
5
  from chainlit.step import Step
6
+ from literalai import ChatGeneration, CompletionGeneration
7
+ from literalai.helper import timestamp_utc
9
8
 
10
9
 
11
10
  def instrument_mistralai():