zrb 1.9.11__py3-none-any.whl → 1.9.12__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.
zrb/task/llm/history.py
CHANGED
@@ -4,8 +4,6 @@ from collections.abc import Callable
|
|
4
4
|
from copy import deepcopy
|
5
5
|
from typing import Any, Optional
|
6
6
|
|
7
|
-
from pydantic import BaseModel, Field
|
8
|
-
|
9
7
|
from zrb.attr.type import StrAttr
|
10
8
|
from zrb.context.any_context import AnyContext
|
11
9
|
from zrb.context.any_shared_context import AnySharedContext
|
@@ -16,19 +14,31 @@ from zrb.util.run import run_async
|
|
16
14
|
|
17
15
|
|
18
16
|
# Define the new ConversationHistoryData model
|
19
|
-
class ConversationHistoryData
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
class ConversationHistoryData:
|
18
|
+
def __init__(
|
19
|
+
self,
|
20
|
+
long_term_context: str = "",
|
21
|
+
conversation_summary: str = "",
|
22
|
+
history: Optional[ListOfDict] = None,
|
23
|
+
messages: Optional[ListOfDict] = None,
|
24
|
+
):
|
25
|
+
self.long_term_context = long_term_context
|
26
|
+
self.conversation_summary = conversation_summary
|
27
|
+
self.history = (
|
28
|
+
history
|
29
|
+
if history is not None
|
30
|
+
else (messages if messages is not None else [])
|
31
|
+
)
|
32
|
+
|
33
|
+
def to_dict(self) -> dict[str, Any]:
|
34
|
+
return {
|
35
|
+
"long_term_context": self.long_term_context,
|
36
|
+
"conversation_summary": self.conversation_summary,
|
37
|
+
"history": self.history,
|
38
|
+
}
|
39
|
+
|
40
|
+
def model_dump_json(self, indent: int = 2) -> str:
|
41
|
+
return json.dumps(self.to_dict(), indent=indent)
|
32
42
|
|
33
43
|
@classmethod
|
34
44
|
async def read_from_sources(
|
@@ -81,7 +91,11 @@ class ConversationHistoryData(BaseModel):
|
|
81
91
|
return data # Already a valid instance
|
82
92
|
if isinstance(data, dict):
|
83
93
|
# This handles both the new format and the old {'context': ..., 'history': ...}
|
84
|
-
return cls
|
94
|
+
return cls(
|
95
|
+
long_term_context=data.get("long_term_context", ""),
|
96
|
+
conversation_summary=data.get("conversation_summary", ""),
|
97
|
+
history=data.get("history", data.get("messages")),
|
98
|
+
)
|
85
99
|
elif isinstance(data, list):
|
86
100
|
# Handle very old format (just a list) - wrap it
|
87
101
|
ctx.log_warning(
|
@@ -183,7 +197,7 @@ async def write_conversation_history(
|
|
183
197
|
ctx, conversation_history_file_attr, render_history_file
|
184
198
|
)
|
185
199
|
if history_file != "":
|
186
|
-
write_file(history_file, history_data.
|
200
|
+
write_file(history_file, json.dumps(history_data.to_dict(), indent=2))
|
187
201
|
|
188
202
|
|
189
203
|
def replace_system_prompt_in_history_list(
|
@@ -342,7 +342,7 @@ zrb/task/llm/config.py,sha256=TlyH925_fboIlK2Ixf34tynmenqs9s9rfsnPs4jff78,3490
|
|
342
342
|
zrb/task/llm/context.py,sha256=LGGQ_mb1dWorfshHjGgXEW_pRweGj-6MZcIUFq3AHy4,2213
|
343
343
|
zrb/task/llm/context_enrichment.py,sha256=djY4fE9C0zUxJPrrb2xDboBXr_2kPUS_b4HjqslVpHg,6051
|
344
344
|
zrb/task/llm/error.py,sha256=s5PSK3ibGupMzOM0P81nstHWrMr3205H0FSDwfhWUDA,3662
|
345
|
-
zrb/task/llm/history.py,sha256=
|
345
|
+
zrb/task/llm/history.py,sha256=dqCwJYRoMVrvyMHb4M6-KLcwAUF4tbDCP7qgD1h694s,8540
|
346
346
|
zrb/task/llm/history_summarization.py,sha256=V0G1BiISnxxmD8040PrvT0_dfqGE7zbLtk74KUpuqig,6050
|
347
347
|
zrb/task/llm/print_node.py,sha256=zocTKi9gZDxl2I6KNu095TmMc13Yip6SNuWYnswS680,4060
|
348
348
|
zrb/task/llm/prompt.py,sha256=qhR8qS8RgaQ23D3amaHSHnBNv_NOnFB_1uxaQNc8KFw,3417
|
@@ -393,7 +393,7 @@ zrb/util/todo.py,sha256=r9_KYF2-hLKMNjsp6AFK9zivykMrywd-kJ4bCwfdafI,19323
|
|
393
393
|
zrb/util/todo_model.py,sha256=0SJ8aLYfJAscDOk5JsH7pXP3h1rAG91VMCS20-c2Y6A,1576
|
394
394
|
zrb/xcom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
395
395
|
zrb/xcom/xcom.py,sha256=o79rxR9wphnShrcIushA0Qt71d_p3ZTxjNf7x9hJB78,1571
|
396
|
-
zrb-1.9.
|
397
|
-
zrb-1.9.
|
398
|
-
zrb-1.9.
|
399
|
-
zrb-1.9.
|
396
|
+
zrb-1.9.12.dist-info/METADATA,sha256=-DI8RzdASD_NeRQmc2UTza0e2DoLwD-CFQm4YqENtBk,9778
|
397
|
+
zrb-1.9.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
398
|
+
zrb-1.9.12.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
|
399
|
+
zrb-1.9.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|