insight key&value

This commit is contained in:
hs 2024-07-02 13:10:00 +08:00
parent d590f98abd
commit fcdb258bdd
5 changed files with 20 additions and 28 deletions

View file

@ -6,9 +6,7 @@ from memory_scope.constants.common_constants import (
NEW_INSIGHT_NODES,
DT,
NOT_REFLECTED_MERGE_NODES,
NEW_INSIGHT_KEYS,
INSIGHT_KEY,
INSIGHT_VALUE,
NEW_INSIGHT_KEYS
)
from memory_scope.enumeration.memory_status_enum import MemoryNodeStatus
from memory_scope.enumeration.memory_type_enum import MemoryTypeEnum
@ -21,16 +19,7 @@ class GetInsightWorker(MemoryBaseWorker):
def new_insight_node(self, insight_key: str, insight_value: str) -> MemoryNode:
created_dt = datetime.now()
obs_dt = time_to_formatted_str(time=created_dt)
# 组合meta_data
meta_data = {
INSIGHT_KEY: insight_key,
INSIGHT_VALUE: insight_value,
}
meta_data.update(
{k: str(v) for k, v in get_datetime_info_dict(created_dt).items()}
)
meta_data = {k: str(v) for k, v in get_datetime_info_dict(created_dt).items()}
content = self.prompt_handler.content_format.format(insight_key=insight_key, insight_value=insight_value)
return MemoryNode(
content=content,
@ -41,6 +30,8 @@ class GetInsightWorker(MemoryBaseWorker):
status=MemoryNodeStatus.ACTIVE.value,
obs_dt=obs_dt,
obs_updated=True,
insight_key=insight_key,
insight_value=insight_value,
)
def reflect_new_insight_key(
@ -147,8 +138,8 @@ class GetInsightWorker(MemoryBaseWorker):
if result:
new_insight_nodes.append(result)
assert isinstance(result, MemoryNode)
insight_key = result.meta_data.get(INSIGHT_KEY, "")
insight_value = result.meta_data.get(INSIGHT_VALUE, "")
insight_key = result.insight_key
insight_value = result.insight_value
self.logger.info(
f"after_get_insight insight_key={insight_key} insight_value={insight_value}"
)

View file

@ -5,7 +5,6 @@ from memory_scope.constants.common_constants import (
NEW_OBS_NODES,
NOT_REFLECTED_OBS_NODES,
INSIGHT_NODES,
INSIGHT_KEY,
NEW_INSIGHT_KEYS,
NOT_REFLECTED_MERGE_NODES,
)
@ -54,7 +53,7 @@ class GetReflectionWorker(MemoryBaseWorker):
insight_nodes: List[MemoryNode] = self.get_context(INSIGHT_NODES)
if insight_nodes:
insight_keys = [
n.meta_data.get(INSIGHT_KEY) for n in insight_nodes
n.insight_key for n in insight_nodes
]
insight_keys = [x.strip() for x in insight_keys if x]
exist_keys.extend(insight_keys)

View file

@ -3,9 +3,7 @@ from typing import List
from memory_scope.utils.response_text_parser import ResponseTextParser
from memory_scope.constants.common_constants import (
INSIGHT_NODES,
NEW_OBS_NODES,
INSIGHT_KEY,
INSIGHT_VALUE,
NEW_OBS_NODES
)
from memory_scope.utils.tool_functions import prompt_to_msg
from memory_scope.scheme.memory_node import MemoryNode
@ -21,8 +19,8 @@ class UpdateInsightWorker(MemoryBaseWorker):
max_score: float = 0
filtered_nodes: List[MemoryNode] = []
insight_key = insight_node.meta_data.get(INSIGHT_KEY, "")
insight_value = insight_node.meta_data.get(INSIGHT_VALUE, "")
insight_key = insight_node.insight_key
insight_value = insight_node.insight_value
if not insight_key or not insight_value:
self.logger.warning(
f"insight_key={insight_key} insight_value={insight_value} is empty!"
@ -60,8 +58,8 @@ class UpdateInsightWorker(MemoryBaseWorker):
self, insight_node: MemoryNode, filtered_nodes: List[MemoryNode]
) -> MemoryNode:
insight_key = insight_node.meta_data.get(INSIGHT_KEY, "")
insight_value = insight_node.meta_data.get(INSIGHT_VALUE, "")
insight_key = insight_node.insight_key
insight_value = insight_node.insight_value
self.logger.info(
f"update_insight insight_key={insight_key} insight_value={insight_value} "
f"doc.size={len(filtered_nodes)}"
@ -118,7 +116,7 @@ class UpdateInsightWorker(MemoryBaseWorker):
self.logger.info(f"insight_value={insight_value}, skip.")
return insight_node
insight_node.meta_data[INSIGHT_VALUE] = insight_value
insight_node.insight_value = insight_value
insight_node.obs_updated = True
return insight_node
@ -166,8 +164,8 @@ class UpdateInsightWorker(MemoryBaseWorker):
for result in self.join_threads():
if result:
insight_node: MemoryNode = result
insight_key = insight_node.meta_data.get(INSIGHT_KEY, "")
insight_value = insight_node.meta_data.get(INSIGHT_VALUE, "")
insight_key = insight_node.insight_key
insight_value = insight_node.insight_value
self.logger.info(
f"after_update_insight insight_key={insight_key} insight_value={insight_value}"
)

View file

@ -173,7 +173,7 @@ class UpdateProfileWorker(MemoryBaseWorker):
},
memory_type=MemoryTypeEnum.PROFILE,
status=1,
obs_profile_updated=true,
obs_profile_updated=True,
)
self.user_profile_dict[user_attr_key] = new_attr

View file

@ -39,6 +39,10 @@ class MemoryNode(BaseModel):
obs_keyword: str = Field("", description="keywords of the content")
insight_key: str = Field("", description="insight_key")
insight_value: str = Field("", description="insight_value")
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.gen_memory_id()