问答 SSE - GenerateChatSseAnswer
功能介绍
问答SSE(Server-Sent Events)接口主要用于实现实时或近实时的数据推送。SSE是一种允许服务器向浏览器推送更新的技术,它使用HTTP协议,但与传统的请求-响应模式不同,SSE允许服务器主动向客户端发送数据,而不需要客户端频繁地发起请求。在问答系统中,SSE接口可以用来实现实时的问题回答更新。例如,当用户提交一个问题后,服务器可以通过SSE接口实时推送新的回答或更新,而不需要用户不断刷新页面来查看是否有新的回答。
URI
POST /v1/{project_id}/koochat/assistants/{assistant_id}/chat
请求参数
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
X-Auth-Token |
否 |
String |
参数解释: 用户鉴权信息。获取方法请参见认证鉴权。 约束限制: 不涉及 取值范围: 不涉及。 默认取值: 不涉及 |
|
参数 |
是否必选 |
参数类型 |
描述 |
|---|---|---|---|
|
question |
是 |
String |
参数解释: 用户问题。 约束限制: 不涉及 取值范围: 1~4096个字符。 默认取值: 不涉及 |
|
conversation_id |
否 |
String |
参数解释: 会话ID,不携带或携带错误会自动生成新的ID。 约束限制: 不涉及 取值范围: 只能由英文字母、数字及“-”、“_”组成,且长度为[1~36]个字符,建议使用UUID。 默认取值: 不涉及 |
|
conversation_conf |
否 |
ConversationConf object |
参数解释: 对话配置, 创建新会话时需要。 约束限制: 不涉及 |
|
source |
否 |
String |
参数解释: 问答来源。 约束限制: 不涉及 取值范围: 默认取值: 不涉及 |
|
debug |
否 |
Boolean |
参数解释: 是否需要进行调试。 约束限制: 不涉及 取值范围: 默认取值: false |
|
extra_info |
否 |
String |
参数解释: 对话额外信息,通过技能透传给FunctionGraph。 约束限制: 不涉及 取值范围: 不涉及 默认取值: 不涉及 |
|
user_id |
否 |
String |
参数解释: 记录用户侧的用户ID,支持用户自定义传入。 约束限制: 不涉及 取值范围: 0-36字符。 默认取值: 不涉及 |
|
stream |
否 |
Boolean |
参数解释: 大模型返回的结果是否通过流式方式输出,以实现打字机效果。 约束限制: 不涉及 取值范围: 默认取值: false |
响应参数
状态码:200
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
event-message |
AnswerMessage object |
参数解释: 流式对话回复,需要拼接获取最终答案。 |
|
event-resp |
RespMessage object |
参数解释: 对话的辅助信息,如意图、槽位等信息。 |
|
event-references |
ReferencesMessage object |
参数解释: 引用溯源。 |
|
event-faq_log |
FaqLogMessage object |
参数解释: FAQ日志。 |
|
event-intention_retrieve_log |
IntentionRetrieveLog object |
参数解释: 意图检索日志。 |
|
event-intention_distribute_log |
IntentionDistributeLog object |
参数解释: 意图分发日志。 |
|
event-rag_log |
RagLog object |
参数解释: RAG日志。 |
|
event-llm_request_log |
LlmRequestLog object |
参数解释: 大模型日志。 |
|
event-moderation |
String |
参数解释: 内容审核。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
answer |
String |
参数解释: 流式返回的答案片段。 取值范围: 不涉及 |
|
created |
Long |
参数解释: 创建事件。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
conversation_id |
String |
参数解释: 会话ID。 取值范围: 不涉及 |
|
created |
Long |
参数解释: 响应时间。 取值范围: 不涉及 |
|
answer |
String |
参数解释: 完整回复内容。 取值范围: 不涉及 |
|
request_id |
String |
参数解释: 请求ID。 取值范围: 不涉及 |
|
reply_type |
Integer |
参数解释: 回复类型。 取值范围: |
|
detail |
ChatResp object |
参数解释: 返回的详情。 |
|
rewritten_question |
String |
参数解释: Query改写的结果。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
log_id |
String |
参数解释: 对话ID。 取值范围: 不涉及 |
|
answer |
String |
参数解释: 引擎回复。 取值范围: 不涉及 |
|
cost |
Long |
参数解释: 耗时。 取值范围: 不涉及 |
|
resp_type |
Integer |
参数解释: 响应类型。 取值范围: |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
fusion_result |
Integer |
参数解释: 问答类型。仅当“resp_type”为“1”时才有值。 取值范围: |
|
skill_id |
String |
参数解释: 使用的技能ID。仅当“resp_type”为“1”时才有值。 取值范围: 不涉及 |
|
frame |
FrameDTO object |
参数解释: 技能Frame数据。仅当“resp_type”为“1”时才有值。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
history_global_variables |
Map<String,String> |
参数解释: 当前会话(可包含多轮对话)中,所有收集到的变量值,包含历史轮对话。Key为变量名称,Value为变量值。 |
|
current_variables |
Map<String,String> |
参数解释: 当前对话轮次中,收集到的变量值。Key为变量名称,Value为变量值。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
document_name |
Map<String,Object> |
参数解释: 具体文档名称。 |
|
type |
String |
参数解释: 具体文档类型。 取值范围: document:文档。 |
|
reference |
Boolean |
参数解释: 是否被引用。 取值范围: |
|
referenceIndex |
Integer |
参数解释: 索引。 取值范围: 不涉及 |
|
page_content |
String |
参数解释: 引用原文内容。 取值范围: 不涉及 |
|
metadata |
metadata object |
参数解释: 原始数据。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
title |
String |
参数解释: 文档标题。 取值范围: 不涉及 |
|
content |
String |
参数解释: 引用原文内容。 取值范围: 不涉及 |
|
doc_name |
String |
参数解释: 文档分片名称。 取值范围: 不涉及 |
|
_id |
String |
参数解释: 文档分片Id。 取值范围: 不涉及 |
|
_score |
String |
参数解释: 分数。 取值范围: 0~1 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
directory_ids |
Array of strings |
参数解释: 目录ID。 |
|
faqs |
Array of faqs objects |
参数解释: FAQ信息。 |
|
cost |
Integer |
参数解释: 耗时。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
id |
String |
参数解释: FAQ ID。 取值范围: 不涉及 |
|
questions |
Array of questions objects |
参数解释: 问题列表。 |
|
top_score |
Float |
参数解释: 最大匹配分数。 取值范围: 0~1 |
|
answers |
Array of answers objects |
参数解释: 答案列表。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
candidate_intentions |
Array of candidate_intentions objects |
参数解释: 候选意图。 |
|
cost |
Integer |
参数解释: 耗时。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
intention_id |
String |
参数解释: 意图ID。 取值范围: 不涉及 |
|
intention_name |
String |
参数解释: 意图名称。 取值范围: 不涉及 |
|
questions |
Array of questions objects |
参数解释: 问题列表。 |
|
assistant_id |
String |
参数解释: 助手ID。 取值范围: 不涉及 |
|
version |
String |
参数解释: 版本。 取值范围: 不涉及 |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
threshold |
Float |
参数解释: 采纳阈值。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
embedding |
Array of floats |
参数解释: Embedding列表。 |
|
question |
String |
参数解释: 问题。 取值范围: 不涉及 |
|
question_id |
String |
参数解释: 问题ID。 取值范围: 不涉及 |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
distributed_skill_id |
String |
参数解释: 分发技能ID。 取值范围: 不涉及 |
|
distributed_skill_name |
String |
参数解释: 分发技能名称。 取值范围: 不涉及 |
|
intention_recognized_result |
intention_recognized_result object |
参数解释: 意图识别结果。 |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
intention_id |
String |
参数解释: 意图ID。 取值范围: 不涉及 |
|
intention_name |
String |
参数解释: 意图名称。 取值范围: 不涉及 |
|
questions |
Array of questions objects |
参数解释: 问题列表。 |
|
assistant_id |
String |
参数解释: 助手ID。 取值范围: 不涉及 |
|
version |
String |
参数解释: 版本。 取值范围: 不涉及 |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
threshold |
Float |
参数解释: 采纳阈值。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
embedding |
Array of floats |
参数解释: Embedding列表。 |
|
question |
String |
参数解释: 问题内容。 取值范围: 不涉及 |
|
question_id |
String |
参数解释: 问题ID。 取值范围: 不涉及 |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
directory_ids |
Array of strings |
参数解释: 文档目录ID。 |
|
debug_info |
debug_info object |
参数解释: 调用RAG引擎关键信息。 |
|
cost |
Integer |
参数解释: 调用RAG引擎接口耗时。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
doc_search_response |
doc_search_response object |
参数解释: 搜索知识管理的结果。 |
|
websearch_response |
Array of strings |
参数解释: 公网搜索结果。 |
|
rag_knowledge |
Array of strings |
参数解释: 最终选取作为RAG的知识。 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
file_id |
String |
参数解释: 文件ID。 取值范围: 不涉及 |
|
title |
String |
参数解释: 文件Title。 取值范围: 不涉及 |
|
subtitle |
String |
参数解释: 文件子Title。 取值范围: 不涉及 |
|
content |
String |
参数解释: 内容。 取值范围: 不涉及 |
|
doc_type |
String |
参数解释: 文件类型。 取值范围: 不涉及 |
|
file_path |
String |
参数解释: 文件路径。 取值范围: 不涉及 |
|
update_date_time |
String |
参数解释: 文件更新时间。 取值范围: 不涉及 |
|
score |
Float |
参数解释: 分数。 取值范围: 0~1 |
|
extra_info |
String |
参数解释: 文档扩展信息。 取值范围: 不涉及 |
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
messages |
Array of messages objects |
参数解释: 大模型调用请求中的Massages列表。 |
|
conversationId |
String |
参数解释: 对话ID。 取值范围: 不涉及 |
请求示例
流式调用对话问答接口。
POST https://{endpoint}/v1/{project_id}/koochat/assistants/{assistant_id}/chat
{
"stream" : true,
"source" : "API",
"question" : "查询天气"
}
响应示例
状态码:200
请求成功。
对话接口 SSE 响应消息。
属性名 "event:{type}",“{type}” 为消息事件类型;属性值"data" 为 SSE 消息数据。
event:faq_log
retry:0
data:{"cost":125,"directory_ids":[]}
event:intention_retrieve_log
retry:0
data:{"cost":138,"candidate_intentions":[]}
event:intention_distribute_log
retry:0
data:{"score":null,"distributed_skill_id":null,"distributed_skill_name":null,"intention_recognized_result":null}
event:qaflow_log
retry:0
data:{"cost":561,"directories":[]}
event:rag_log
retry:0
data:{"cost":444,"directory_ids":["123"],"debug_info":{"intention":"无意图","doc_search_response":{"docs":[]},"rag_knowledge":[],"websearch_response":[],"error_info":[],"planning_queries":["你好"]}}
event:llm_request_log
retry:0
data:{"llm_chat_req":{"conversationId":"1769568381849004","customizedLlmConfig":{"region":"cn-southwest-2","url":"http://127.0.0.1:80/modelarts-maas/deepseek-v3/v1/chat/completions","service_type":2,"maas_model_name":"DeepSeek-V3","cloud_system_enable":true},"messages":[{"role":"system","content":"你是智能对话助手,用户消息为:\n你好"}],"stream":true}}
event:llm_response_log
retry:0
data:{"first_token_cost":1555}
event:e2e_log
retry:0
data:{"first_token_cost":3571}
event:message
retry:0
data:{"created":1769590001702,"answer":"你好","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001707,"answer":"!","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001714,"answer":"今天是","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001715,"answer":"2026","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001715,"answer":"年1","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001715,"answer":"月28","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001716,"answer":"日,","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001716,"answer":"星期三下午","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001717,"answer":"好","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001717,"answer":"。","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001718,"answer":"有什么","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001718,"answer":"可以","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001719,"answer":"帮您的","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001719,"answer":"吗?","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001719,"answer":"无论是问题","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001720,"answer":"解答、","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001720,"answer":"内容","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001720,"answer":"创作还是","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"技术支持","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":",","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"我","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"随时","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001721,"answer":"为您服务","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:message
retry:0
data:{"created":1769590001722,"answer":"。","conversation_id":"1769568381849004","request_id":"1769568381849004"}
event:reference
retry:0
data:[]
event:resp
retry:0
data:{"created":1769590001723,"answer":"你好!今天是2026年1月28日,星期三下午好。有什么可以帮您的吗?无论是问题解答、内容创作还是技术支持,我随时为您服务。","conversation_id":"1769568381849004","request_id":"1769568381849004","detail":{"answer":"你好!今天是2026年1月28日,星期三下午好。有什么可以帮您的吗?无论是问题解答、内容创作还是技术支持,我随时为您服务。","resp_type":1,"llm_generated":false}}
event:message
retry:0
data:[DONE]
状态码
|
状态码 |
描述 |
|---|---|
|
200 |
请求成功。 对话接口 SSE 响应消息。 属性名 "event:{type}",“{type}” 为消息事件类型;属性值"data" 为 SSE 消息数据。 |
错误码
请参见错误码。
