fix(workflow): persist citations in conversation message meta_data
This commit is contained in:
@@ -722,12 +722,18 @@ class WorkflowService:
|
|||||||
content=human_message,
|
content=human_message,
|
||||||
meta_data=human_meta
|
meta_data=human_meta
|
||||||
)
|
)
|
||||||
|
# 过滤 citations
|
||||||
|
citations = result.get("citations", [])
|
||||||
|
citation_cfg = feature_configs.get("citation", {})
|
||||||
|
filtered_citations = (
|
||||||
|
citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else []
|
||||||
|
)
|
||||||
self.conversation_service.add_message(
|
self.conversation_service.add_message(
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
conversation_id=conversation_id_uuid,
|
conversation_id=conversation_id_uuid,
|
||||||
role="assistant",
|
role="assistant",
|
||||||
content=assistant_message,
|
content=assistant_message,
|
||||||
meta_data={"usage": token_usage, "audio_url": None}
|
meta_data={"usage": token_usage, "audio_url": None, "citations": filtered_citations}
|
||||||
)
|
)
|
||||||
self.update_execution_status(
|
self.update_execution_status(
|
||||||
execution.execution_id,
|
execution.execution_id,
|
||||||
@@ -746,13 +752,7 @@ class WorkflowService:
|
|||||||
)
|
)
|
||||||
logger.error(f"Workflow Run Failed, execution_id: {execution.execution_id},"
|
logger.error(f"Workflow Run Failed, execution_id: {execution.execution_id},"
|
||||||
f" error: {result.get('error')}")
|
f" error: {result.get('error')}")
|
||||||
|
filtered_citations = []
|
||||||
# 过滤 citations
|
|
||||||
citations = result.get("citations", [])
|
|
||||||
citation_cfg = feature_configs.get("citation", {})
|
|
||||||
filtered_citations = (
|
|
||||||
citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else []
|
|
||||||
)
|
|
||||||
|
|
||||||
# 返回增强的响应结构
|
# 返回增强的响应结构
|
||||||
return {
|
return {
|
||||||
@@ -917,12 +917,18 @@ class WorkflowService:
|
|||||||
content=human_message,
|
content=human_message,
|
||||||
meta_data=human_meta
|
meta_data=human_meta
|
||||||
)
|
)
|
||||||
|
# 过滤 citations
|
||||||
|
citations = event.get("data", {}).get("citations", [])
|
||||||
|
citation_cfg = feature_configs.get("citation", {})
|
||||||
|
filtered_citations = (
|
||||||
|
citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else []
|
||||||
|
)
|
||||||
self.conversation_service.add_message(
|
self.conversation_service.add_message(
|
||||||
message_id=message_id,
|
message_id=message_id,
|
||||||
conversation_id=conversation_id_uuid,
|
conversation_id=conversation_id_uuid,
|
||||||
role="assistant",
|
role="assistant",
|
||||||
content=assistant_message,
|
content=assistant_message,
|
||||||
meta_data={"usage": token_usage, "audio_url": None}
|
meta_data={"usage": token_usage, "audio_url": None, "citations": filtered_citations}
|
||||||
)
|
)
|
||||||
self.update_execution_status(
|
self.update_execution_status(
|
||||||
execution.execution_id,
|
execution.execution_id,
|
||||||
@@ -930,12 +936,6 @@ class WorkflowService:
|
|||||||
output_data=event.get("data"),
|
output_data=event.get("data"),
|
||||||
token_usage=token_usage.get("total_tokens", None)
|
token_usage=token_usage.get("total_tokens", None)
|
||||||
)
|
)
|
||||||
# 注入 citations 到 workflow_end 事件
|
|
||||||
citations = event.get("data", {}).get("citations", [])
|
|
||||||
citation_cfg = feature_configs.get("citation", {})
|
|
||||||
filtered_citations = (
|
|
||||||
citations if isinstance(citation_cfg, dict) and citation_cfg.get("enabled") else []
|
|
||||||
)
|
|
||||||
event.setdefault("data", {})["citations"] = filtered_citations
|
event.setdefault("data", {})["citations"] = filtered_citations
|
||||||
logger.info(f"Workflow Run Success, "
|
logger.info(f"Workflow Run Success, "
|
||||||
f"execution_id: {execution.execution_id}, message count: {len(final_messages)}")
|
f"execution_id: {execution.execution_id}, message count: {len(final_messages)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user