feat:将relation获取变为工具

This commit is contained in:
SengokuCola
2025-09-17 21:17:52 +08:00
parent ddf4fb1bce
commit a932ca695a
13 changed files with 103 additions and 44 deletions

View File

@@ -420,7 +420,7 @@ class Person:
except Exception as e:
logger.error(f"同步用户 {self.person_id} 信息到数据库时出错: {e}")
async def build_relationship(self,chat_content:str = ""):
async def build_relationship(self,chat_content:str = "",info_type = ""):
if not self.is_known:
return ""
# 构建points文本
@@ -446,8 +446,8 @@ class Person:
如果没有相关的分类,请输出<none>"""
response, _ = await relation_selection_model.generate_response_async(prompt)
print(prompt)
print(response)
# print(prompt)
# print(response)
category_list = extract_categories_from_response(response)
if "none" not in category_list:
for category in category_list:
@@ -456,7 +456,26 @@ class Person:
random_memory_str = "\n".join([get_memory_content_from_memory(memory) for memory in random_memory])
points_text = f"有关 {category} 的内容:{random_memory_str}"
break
elif info_type:
prompt = f"""你需要获取用户{self.person_name}的 **{info_type}** 信息。
现有信息类别列表:
{category_list}
**要求**:请你根据**{info_type}**,从以下分类中选择一个与**{info_type}**相关的分类,并用<>包裹输出,不要输出其他内容,不要输出引号或[],严格用<>包裹:
例如:
<分类1><分类2><分类3>......
如果没有相关的分类,请输出<none>"""
response, _ = await relation_selection_model.generate_response_async(prompt)
print(prompt)
print(response)
category_list = extract_categories_from_response(response)
if "none" not in category_list:
for category in category_list:
random_memory = self.get_random_memory_by_category(category, 3)
if random_memory:
random_memory_str = "\n".join([get_memory_content_from_memory(memory) for memory in random_memory])
points_text = f"有关 {category} 的内容:{random_memory_str}"
break
else:
for category in category_list: