新增对话接口
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user