关系系统大致完善

This commit is contained in:
meng_xi_pan
2025-03-14 17:47:33 +08:00
parent 414340588d
commit a3927507dc
4 changed files with 76 additions and 53 deletions

View File

@@ -170,32 +170,48 @@ class ResponseGenerator:
}
)
async def _get_emotion_tags(self, content: str) -> List[str]:
"""提取情感标签"""
async def _get_emotion_tags(
self, content: str, processed_plain_text: str
) -> List[str]:
"""提取情感标签,结合立场和情绪"""
try:
prompt = f"""请从以下内容中,从"happy,angry,sad,surprised,disgusted,fearful,neutral"中选出最匹配的1个情感标签并输出
只输出标签就好,不要输出其他内容:
内容:{content}
输出:
# 构建提示词,结合回复内容、被回复的内容以及立场分析
prompt = f"""
请根据以下对话内容,完成以下任务:
1. 判断回复者的立场是"supportive"(支持)、"opposed"(反对)还是"neutrality"(中立)。
2. 从"happy,angry,sad,surprised,disgusted,fearful,neutral"中选出最匹配的1个情感标签。
3. 按照"立场-情绪"的格式输出结果,例如:"supportive-happy"
被回复的内容:
{processed_plain_text}
回复内容:
{content}
请分析回复者的立场和情感倾向,并输出结果:
"""
content, _ = await self.model_v25.generate_response(prompt)
content = content.strip()
if content in [
"happy",
"angry",
"sad",
"surprised",
"disgusted",
"fearful",
"neutral",
]:
return [content]
# 调用模型生成结果
result, _ = await self.model_v25.generate_response(prompt)
result = result.strip()
# 解析模型输出的结果
if "-" in result:
stance, emotion = result.split("-", 1)
valid_stances = ["supportive", "opposed", "neutrality"]
valid_emotions = [
"happy", "angry", "sad", "surprised", "disgusted", "fearful", "neutral"
]
if stance in valid_stances and emotion in valid_emotions:
return stance, emotion # 返回有效的立场-情绪组合
else:
return "neutrality", "neutral" # 默认返回中立-中性
else:
return ["neutral"]
return "neutrality", "neutral" # 格式错误时返回默认值
except Exception as e:
print(f"获取情感标签时出错: {e}")
return ["neutral"]
return "neutrality", "neutral" # 出错时返回默认值
async def _process_response(self, content: str) -> Tuple[List[str], List[str]]:
"""处理响应内容,返回处理后的内容和情感标签"""