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.
- chainlit/__init__.py +57 -56
- chainlit/action.py +10 -12
- chainlit/{auth/__init__.py → auth.py} +34 -26
- chainlit/cache.py +6 -4
- chainlit/callbacks.py +7 -52
- chainlit/chat_context.py +2 -2
- chainlit/chat_settings.py +1 -3
- chainlit/cli/__init__.py +2 -15
- chainlit/config.py +70 -41
- chainlit/context.py +9 -8
- chainlit/copilot/dist/index.js +874 -8533
- chainlit/data/__init__.py +8 -96
- chainlit/data/acl.py +2 -3
- chainlit/data/base.py +15 -1
- chainlit/data/dynamodb.py +4 -7
- chainlit/data/literalai.py +6 -4
- chainlit/data/sql_alchemy.py +9 -10
- chainlit/data/{storage_clients/azure.py → storage_clients.py} +33 -2
- chainlit/discord/__init__.py +4 -4
- chainlit/discord/app.py +1 -2
- chainlit/element.py +9 -41
- chainlit/emitter.py +21 -17
- chainlit/frontend/dist/assets/DailyMotion-b4b7af47.js +1 -0
- chainlit/frontend/dist/assets/Facebook-572972a0.js +1 -0
- chainlit/frontend/dist/assets/FilePlayer-85c69ca8.js +1 -0
- chainlit/frontend/dist/assets/Kaltura-dfc24672.js +1 -0
- chainlit/frontend/dist/assets/Mixcloud-705011f4.js +1 -0
- chainlit/frontend/dist/assets/Mux-4201a9e6.js +1 -0
- chainlit/frontend/dist/assets/Preview-23ba40a6.js +1 -0
- chainlit/frontend/dist/assets/SoundCloud-1a582d51.js +1 -0
- chainlit/frontend/dist/assets/Streamable-5017c4ba.js +1 -0
- chainlit/frontend/dist/assets/Twitch-bb2de2fa.js +1 -0
- chainlit/frontend/dist/assets/Vidyard-54e269b1.js +1 -0
- chainlit/frontend/dist/assets/Vimeo-d92c37dd.js +1 -0
- chainlit/frontend/dist/assets/Wistia-25a1363b.js +1 -0
- chainlit/frontend/dist/assets/YouTube-616e8cb7.js +1 -0
- chainlit/frontend/dist/assets/index-aaf974a9.css +1 -0
- chainlit/frontend/dist/assets/index-f5df2072.js +1027 -0
- chainlit/frontend/dist/assets/{react-plotly-BpxUS-ab.js → react-plotly-f0315f86.js} +94 -94
- chainlit/frontend/dist/index.html +3 -2
- chainlit/haystack/callbacks.py +4 -5
- chainlit/input_widget.py +4 -6
- chainlit/langchain/callbacks.py +47 -56
- chainlit/langflow/__init__.py +0 -1
- chainlit/llama_index/callbacks.py +7 -7
- chainlit/message.py +10 -8
- chainlit/mistralai/__init__.py +2 -3
- chainlit/oauth_providers.py +12 -113
- chainlit/openai/__init__.py +7 -6
- chainlit/secret.py +1 -1
- chainlit/server.py +181 -491
- chainlit/session.py +5 -7
- chainlit/slack/__init__.py +3 -3
- chainlit/slack/app.py +2 -3
- chainlit/socket.py +103 -78
- chainlit/step.py +29 -21
- chainlit/sync.py +1 -2
- chainlit/teams/__init__.py +3 -3
- chainlit/teams/app.py +0 -1
- chainlit/types.py +4 -20
- chainlit/user.py +1 -2
- chainlit/utils.py +2 -3
- chainlit/version.py +2 -3
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/METADATA +39 -27
- chainlit-2.0.dev0.dist-info/RECORD +96 -0
- chainlit/auth/cookie.py +0 -123
- chainlit/auth/jwt.py +0 -37
- chainlit/data/chainlit_data_layer.py +0 -584
- chainlit/data/storage_clients/__init__.py +0 -0
- chainlit/data/storage_clients/azure_blob.py +0 -80
- chainlit/data/storage_clients/base.py +0 -22
- chainlit/data/storage_clients/gcs.py +0 -78
- chainlit/data/storage_clients/s3.py +0 -49
- chainlit/frontend/dist/assets/DailyMotion-DgRzV5GZ.js +0 -1
- chainlit/frontend/dist/assets/Dataframe-DVgwSMU2.js +0 -22
- chainlit/frontend/dist/assets/Facebook-C0vx6HWv.js +0 -1
- chainlit/frontend/dist/assets/FilePlayer-CdhzeHPP.js +0 -1
- chainlit/frontend/dist/assets/Kaltura-5iVmeUct.js +0 -1
- chainlit/frontend/dist/assets/Mixcloud-C2zi77Ex.js +0 -1
- chainlit/frontend/dist/assets/Mux-Vkebogdf.js +0 -1
- chainlit/frontend/dist/assets/Preview-DwY_sEIl.js +0 -1
- chainlit/frontend/dist/assets/SoundCloud-CREBXAWo.js +0 -1
- chainlit/frontend/dist/assets/Streamable-B5Lu25uy.js +0 -1
- chainlit/frontend/dist/assets/Twitch-y9iKCcM1.js +0 -1
- chainlit/frontend/dist/assets/Vidyard-ClYvcuEu.js +0 -1
- chainlit/frontend/dist/assets/Vimeo-D6HvM2jt.js +0 -1
- chainlit/frontend/dist/assets/Wistia-Cu4zZ2Ci.js +0 -1
- chainlit/frontend/dist/assets/YouTube-D10tR6CJ.js +0 -1
- chainlit/frontend/dist/assets/index-CI4qFOt5.js +0 -8665
- chainlit/frontend/dist/assets/index-CrrqM0nZ.css +0 -1
- chainlit/translations/nl-NL.json +0 -229
- chainlit-2.0.0.dist-info/RECORD +0 -106
- /chainlit/copilot/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
- /chainlit/copilot/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_dark-IkGJ_IwC.svg → logo_dark-2a3cf740.svg} +0 -0
- /chainlit/frontend/dist/assets/{logo_light-Bb_IPh6r.svg → logo_light-b078e7bc.svg} +0 -0
- {chainlit-2.0.0.dist-info → chainlit-2.0.dev0.dist-info}/WHEEL +0 -0
- {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-
|
|
25
|
-
<link rel="stylesheet"
|
|
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>
|
chainlit/haystack/callbacks.py
CHANGED
|
@@ -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=
|
|
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=
|
|
173
|
-
values: List[str] = Field(default_factory=
|
|
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 {
|
chainlit/langchain/callbacks.py
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
) ->
|
|
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
|
|
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
|
-
|
|
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
|
-
) ->
|
|
351
|
-
|
|
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
|
-
|
|
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
|
-
) ->
|
|
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
|
-
|
|
401
|
-
|
|
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
|
-
|
|
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
|
-
|
|
458
|
-
|
|
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
|
-
|
|
492
|
+
self._run_sync(step.send())
|
|
502
493
|
|
|
503
|
-
|
|
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
|
-
|
|
579
|
+
self._run_sync(current_step.update())
|
|
589
580
|
|
|
590
581
|
if self.final_stream and self.has_streamed_final_answer:
|
|
591
|
-
|
|
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
|
-
|
|
602
|
+
self._run_sync(current_step.update())
|
|
612
603
|
|
|
613
|
-
|
|
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
|
-
|
|
611
|
+
self._run_sync(current_step.update())
|
|
621
612
|
|
|
622
613
|
on_llm_error = _on_error
|
|
623
614
|
on_chain_error = _on_error
|
chainlit/langflow/__init__.py
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
153
|
+
logger.error(f"Failed to persist message creation: {str(e)}")
|
|
152
154
|
|
|
153
155
|
return step_dict
|
|
154
156
|
|
chainlit/mistralai/__init__.py
CHANGED
|
@@ -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():
|