feat:增加了工作记忆
This commit is contained in:
41
src/chat/focus_chat/info/self_info.py
Normal file
41
src/chat/focus_chat/info/self_info.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from typing import Dict, Any
|
||||
from dataclasses import dataclass, field
|
||||
from .info_base import InfoBase
|
||||
|
||||
|
||||
@dataclass
|
||||
class SelfInfo(InfoBase):
|
||||
"""思维信息类
|
||||
|
||||
用于存储和管理当前思维状态的信息。
|
||||
|
||||
Attributes:
|
||||
type (str): 信息类型标识符,默认为 "mind"
|
||||
data (Dict[str, Any]): 包含 current_mind 的数据字典
|
||||
"""
|
||||
|
||||
type: str = "self"
|
||||
|
||||
def get_self_info(self) -> str:
|
||||
"""获取当前思维状态
|
||||
|
||||
Returns:
|
||||
str: 当前思维状态
|
||||
"""
|
||||
return self.get_info("self_info") or ""
|
||||
|
||||
def set_self_info(self, self_info: str) -> None:
|
||||
"""设置当前思维状态
|
||||
|
||||
Args:
|
||||
self_info: 要设置的思维状态
|
||||
"""
|
||||
self.data["self_info"] = self_info
|
||||
|
||||
def get_processed_info(self) -> str:
|
||||
"""获取处理后的信息
|
||||
|
||||
Returns:
|
||||
str: 处理后的信息
|
||||
"""
|
||||
return self.get_self_info()
|
||||
90
src/chat/focus_chat/info/workingmemory_info.py
Normal file
90
src/chat/focus_chat/info/workingmemory_info.py
Normal file
@@ -0,0 +1,90 @@
|
||||
from typing import Dict, Optional, List
|
||||
from dataclasses import dataclass
|
||||
from .info_base import InfoBase
|
||||
|
||||
|
||||
@dataclass
|
||||
class WorkingMemoryInfo(InfoBase):
|
||||
|
||||
type: str = "workingmemory"
|
||||
|
||||
processed_info:str = ""
|
||||
|
||||
def set_talking_message(self, message: str) -> None:
|
||||
"""设置说话消息
|
||||
|
||||
Args:
|
||||
message (str): 说话消息内容
|
||||
"""
|
||||
self.data["talking_message"] = message
|
||||
|
||||
def set_working_memory(self, working_memory: List[str]) -> None:
|
||||
"""设置工作记忆
|
||||
|
||||
Args:
|
||||
working_memory (str): 工作记忆内容
|
||||
"""
|
||||
self.data["working_memory"] = working_memory
|
||||
|
||||
def add_working_memory(self, working_memory: str) -> None:
|
||||
"""添加工作记忆
|
||||
|
||||
Args:
|
||||
working_memory (str): 工作记忆内容
|
||||
"""
|
||||
working_memory_list = self.data.get("working_memory", [])
|
||||
# print(f"working_memory_list: {working_memory_list}")
|
||||
working_memory_list.append(working_memory)
|
||||
# print(f"working_memory_list: {working_memory_list}")
|
||||
self.data["working_memory"] = working_memory_list
|
||||
|
||||
def get_working_memory(self) -> List[str]:
|
||||
"""获取工作记忆
|
||||
|
||||
Returns:
|
||||
List[str]: 工作记忆内容
|
||||
"""
|
||||
return self.data.get("working_memory", [])
|
||||
|
||||
def get_type(self) -> str:
|
||||
"""获取信息类型
|
||||
|
||||
Returns:
|
||||
str: 当前信息对象的类型标识符
|
||||
"""
|
||||
return self.type
|
||||
|
||||
def get_data(self) -> Dict[str, str]:
|
||||
"""获取所有信息数据
|
||||
|
||||
Returns:
|
||||
Dict[str, str]: 包含所有信息数据的字典
|
||||
"""
|
||||
return self.data
|
||||
|
||||
def get_info(self, key: str) -> Optional[str]:
|
||||
"""获取特定属性的信息
|
||||
|
||||
Args:
|
||||
key: 要获取的属性键名
|
||||
|
||||
Returns:
|
||||
Optional[str]: 属性值,如果键不存在则返回 None
|
||||
"""
|
||||
return self.data.get(key)
|
||||
|
||||
def get_processed_info(self) -> Dict[str, str]:
|
||||
"""获取处理后的信息
|
||||
|
||||
Returns:
|
||||
Dict[str, str]: 处理后的信息数据
|
||||
"""
|
||||
all_memory = self.get_working_memory()
|
||||
# print(f"all_memory: {all_memory}")
|
||||
memory_str = ""
|
||||
for memory in all_memory:
|
||||
memory_str += f"{memory}\n"
|
||||
|
||||
self.processed_info = memory_str
|
||||
|
||||
return self.processed_info
|
||||
Reference in New Issue
Block a user