新增对话接口
This commit is contained in:
@@ -175,8 +175,7 @@ async def chat_stream(request: ChatRequest):
|
||||
await main_agent.aupdate_state(current_config, combined_values)
|
||||
|
||||
async def event_generator() -> AsyncGenerator[str, None]:
|
||||
yield f"data: {json.dumps({'thread_id': target_thread_id, 'is_branch': is_branching, 'status': 'start'}, ensure_ascii=False)}\n\n"
|
||||
|
||||
is_first = True
|
||||
new_messages = initial_messages[:] if not source_thread_id else []
|
||||
new_messages.append(HumanMessage(content=request.message))
|
||||
|
||||
@@ -189,6 +188,10 @@ async def chat_stream(request: ChatRequest):
|
||||
stream_mode=["updates", "messages", "custom"],
|
||||
subgraphs=True
|
||||
):
|
||||
if is_first:
|
||||
checkpoint_id = main_agent.get_state(current_config).config.get("configurable").get("checkpoint_id")
|
||||
yield f"data: {json.dumps({'thread_id': target_thread_id, 'is_branch': is_branching, 'status': 'start', "checkpoint_id": checkpoint_id}, ensure_ascii=False)}\n\n"
|
||||
is_first = False
|
||||
_, mode, chunks = stream
|
||||
if mode == "updates": # 只做记录 不做事件返回
|
||||
print(f"[updates] {chunks}")
|
||||
@@ -304,7 +307,7 @@ async def chat_stream(request: ChatRequest):
|
||||
yield f"data: {json.dumps(payload_out, ensure_ascii=False)}\n\n"
|
||||
|
||||
if request.need_suggestion > 0 and random.random() < request.need_suggestion:
|
||||
suggested_questions = generate_suggested_questions(main_agent, target_thread_id)
|
||||
suggested_questions = await generate_suggested_questions(main_agent, target_thread_id)
|
||||
yield f"data: {json.dumps({'suggested_questions': suggested_questions}, ensure_ascii=False)}\n\n"
|
||||
yield f"data: {json.dumps({'status': 'end'}, ensure_ascii=False)}\n\n"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from src.server.deep_agent.tools.structured_retrieval_tool import structured_ret
|
||||
from src.server.deep_agent.tools.user_persona_tool import query_report_profile
|
||||
|
||||
research_subagent = {
|
||||
"name": "research-agent",
|
||||
"name": "research_subagent",
|
||||
"description": "通过网络搜索对家具设计开展深度研究并整合结论",
|
||||
"system_prompt": build_researcher_prompt(),
|
||||
"tools": [
|
||||
|
||||
@@ -65,30 +65,9 @@ async def generate_furniture(prompt: str) -> str:
|
||||
# 4. 构造访问链接 (如果是私有 bucket,需使用 presigned_get_object)
|
||||
# 这里简单示例为直接访问地址
|
||||
image_url = f"{bucket}/{object_name}"
|
||||
return json.dumps(
|
||||
{
|
||||
"tool_name": "generate_furniture",
|
||||
"data": image_url,
|
||||
"tool_status": "success"
|
||||
},
|
||||
ensure_ascii=False
|
||||
)
|
||||
return image_url
|
||||
else:
|
||||
return json.dumps(
|
||||
{
|
||||
"tool_name": "generate_furniture",
|
||||
"data": "图片生成成功,但上传至存储服务器失败。",
|
||||
"tool_status": "error"
|
||||
},
|
||||
ensure_ascii=False
|
||||
)
|
||||
return "图片生成成功,但上传至存储服务器失败。"
|
||||
except Exception as e:
|
||||
logger.warning(e)
|
||||
return json.dumps(
|
||||
{
|
||||
"tool_name": "generate_furniture",
|
||||
"data": f"绘图流程异常",
|
||||
"tool_status": "error"
|
||||
},
|
||||
ensure_ascii=False
|
||||
)
|
||||
return "绘图流程异常"
|
||||
|
||||
Reference in New Issue
Block a user