fix/various fixes
This commit is contained in:
@@ -204,12 +204,10 @@ class InterviewAgent:
|
||||
) -> List[str]:
|
||||
"""生成空对话开场白,不持久化(由 Orchestrator 负责)"""
|
||||
if not self.llm:
|
||||
return ["你好呀~ 有空聊聊你的人生故事吗?你小时候是在哪儿长大的?"]
|
||||
return ["你好呀~ 又见面了,今天有没有哪段回忆或近况想聊聊?"]
|
||||
try:
|
||||
empty_slots = memoir_state.empty_slots_for_current_stage()
|
||||
empty_slots_readable = [SLOT_NAME_MAP.get(s, s) for s in empty_slots]
|
||||
if not empty_slots_readable:
|
||||
empty_slots_readable = ["成长的地方", "难忘的事", "重要的人"]
|
||||
prompt = get_opening_prompt(
|
||||
current_stage=memoir_state.current_stage,
|
||||
empty_slots_readable=empty_slots_readable,
|
||||
@@ -226,4 +224,4 @@ class InterviewAgent:
|
||||
return messages[:2] if messages else [response_text]
|
||||
except Exception as e:
|
||||
logger.error("生成开场白失败: %s", e, exc_info=True)
|
||||
return ["你好呀~ 有空聊聊你的人生故事吗?你童年里印象最深的一件事是什么?"]
|
||||
return ["你好呀~ 又见面了,最近有没有什么事想跟我说说?"]
|
||||
|
||||
@@ -236,7 +236,12 @@ class ChatOrchestrator:
|
||||
memoir_state: MemoirStateSchema,
|
||||
user_profile_context: str = "",
|
||||
) -> List[str]:
|
||||
"""委托 InterviewAgent 生成开场白,并写入 Redis"""
|
||||
"""
|
||||
委托 InterviewAgent 生成访谈开场白,并写入 Redis。
|
||||
|
||||
调用方(如 WS)须在「空会话」分支前通过 ConversationService 从 DB 回填 Redis,
|
||||
避免与多 Agent 契约混淆:本编排器不读取 segments,只假定 Redis 已反映是否已有轮次。
|
||||
"""
|
||||
responses = await self.interview_agent.generate_opening_message(
|
||||
conversation_id=conversation_id,
|
||||
memoir_state=memoir_state,
|
||||
|
||||
@@ -8,15 +8,15 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from langchain_core.messages import AIMessage, HumanMessage
|
||||
|
||||
from app.core.dependencies import get_llm_provider
|
||||
from app.core.logging import get_logger
|
||||
|
||||
from app.agents.chat.helpers import format_history_string, get_history_messages
|
||||
from app.agents.chat.prompts_profile import (
|
||||
get_profile_extraction_prompt,
|
||||
get_profile_followup_prompt,
|
||||
get_profile_greeting_prompt,
|
||||
)
|
||||
from app.core.dependencies import get_llm_provider
|
||||
from app.core.langchain_llm import bind_json_object_mode
|
||||
from app.core.logging import get_logger
|
||||
from app.features.memoir.memoir_images.json_payload import extract_json_payload
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -62,10 +62,7 @@ class ProfileAgent:
|
||||
prompt = get_profile_extraction_prompt(
|
||||
user_message, missing_fields, recent_dialogue=recent_dialogue or None
|
||||
)
|
||||
json_llm = self.llm.bind(
|
||||
model_kwargs={"response_format": {"type": "json_object"}},
|
||||
max_tokens=512,
|
||||
)
|
||||
json_llm = bind_json_object_mode(self.llm, max_tokens=512)
|
||||
response = await json_llm.ainvoke(prompt)
|
||||
content = response.content.strip()
|
||||
parsed = json.loads(extract_json_payload(content))
|
||||
|
||||
@@ -185,22 +185,46 @@ def get_opening_prompt(
|
||||
"belief": "人生信念",
|
||||
}
|
||||
stage_name = stage_name_map.get(current_stage, current_stage)
|
||||
topics_str = (
|
||||
"、".join(empty_slots_readable)
|
||||
if empty_slots_readable
|
||||
else "人生故事、童年、经历等"
|
||||
)
|
||||
if empty_slots_readable:
|
||||
topics_str = "、".join(empty_slots_readable)
|
||||
topics_heading = (
|
||||
f"## 当前建议话题({stage_name})\n可以从中选一个来问:{topics_str}"
|
||||
)
|
||||
task_question = (
|
||||
"2. **必须问一个问题**:接着问一个**具体、好回答**的问题,引导用户开始分享;"
|
||||
"优先落在上述还未聊透的方向上。不要问太宽泛的「有什么想聊的」。"
|
||||
)
|
||||
style_examples = (
|
||||
"示例(仅供参考风格):\n"
|
||||
'"你好呀~ 有空的话想听听你的人生故事。你小时候是在哪儿长大的?那边有什么特别让你怀念的?"\n或\n'
|
||||
'"在的!今天想聊聊你。你童年里印象最深的一件事是什么?"'
|
||||
)
|
||||
else:
|
||||
topics_heading = (
|
||||
f"## 当前阶段({stage_name})\n"
|
||||
"访谈结构化槽位里,这一阶段的主要问题在素材侧**已有覆盖**。"
|
||||
"开场要像老朋友重逢:接近况、接续上次聊过的事、或任何用户可能想提起的新片段;"
|
||||
"**禁止**为了凑问题而默认再从「童年在哪长大」等已覆盖模板重头盘问。"
|
||||
)
|
||||
task_question = (
|
||||
"2. **问候 + 轻巧引子**:用一句温暖的话接上对话;若自然,可以问一个与近况、"
|
||||
"想续上的回忆、或新冒出来的小事有关的问题。若不适合追问,问候 + 一句开放式引子即可。"
|
||||
)
|
||||
style_examples = (
|
||||
"示例(仅供参考风格):\n"
|
||||
'"嘿,又见面啦~ 今天有没有哪件事突然从脑子里冒出来,想跟我说说?"\n或\n'
|
||||
'"在的!上次聊到那儿我还记着,你后来还有想起什么细节吗?"'
|
||||
)
|
||||
profile_section = (
|
||||
f"\n## 用户基本信息\n{user_profile_context}\n" if user_profile_context else ""
|
||||
)
|
||||
return f"""你是「岁月知己」,用户的老朋友。用户刚通过「打个招呼」进入空对话,**还没有发任何消息**,需要你先开口。
|
||||
{profile_section}
|
||||
## 当前建议话题({stage_name})
|
||||
可以从中选一个来问:{topics_str}
|
||||
{topics_heading}
|
||||
|
||||
## 你的任务
|
||||
1. **先开口**:用一两句亲切的问候开场(如「你好呀,有空聊聊你的故事吗」)。
|
||||
2. **必须问一个问题**:接着问一个**具体、好回答**的问题,引导用户开始分享(如童年、家乡、印象深的事等)。不要问太宽泛的「有什么想聊的」。
|
||||
1. **先开口**:用一两句亲切的问候开场。
|
||||
{task_question}
|
||||
3. 语气像老朋友,自然、温暖。
|
||||
|
||||
## 回复格式
|
||||
@@ -208,10 +232,7 @@ def get_opening_prompt(
|
||||
- **严禁**输出括号、注释、思考过程。
|
||||
- **严禁**模拟或虚构用户的回答。你只能输出「你的问候 + 你的问题」,不能替用户回答,不能自问自答。最多 2 段(问候 + 问题),禁止更多。
|
||||
|
||||
示例(仅供参考风格):
|
||||
"你好呀~ 有空的话想听听你的人生故事。你小时候是在哪儿长大的?那边有什么特别让你怀念的?"
|
||||
或
|
||||
"在的!今天想聊聊你。你童年里印象最深的一件事是什么?"
|
||||
{style_examples}
|
||||
|
||||
直接输出你要说的话(多条用 [SPLIT] 分隔):"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user