🐛 fix: 阿里百炼应用无法多轮会话

fixes: #1123
This commit is contained in:
Soulter
2025-04-05 16:21:41 +08:00
parent e031161fd4
commit 23579c1e4a
2 changed files with 19 additions and 11 deletions

View File

@@ -752,7 +752,7 @@ CONFIG_METADATA_2 = {
"rag_options": {
"description": "RAG 选项",
"type": "object",
"hint": "检索知识库设置, 非必填。仅 Agent 应用类型支持(智能体应用, 包括 RAG 应用)",
"hint": "检索知识库设置, 非必填。仅 Agent 应用类型支持(智能体应用, 包括 RAG 应用)。阿里云百炼应用开启此功能后将无法多轮对话。",
"items": {
"pipeline_ids": {
"description": "知识库 ID 列表",

View File

@@ -51,10 +51,14 @@ class ProviderDashscope(ProviderOpenAIOfficial):
self.timeout = int(self.timeout)
def has_rag_options(self):
if (
self.rag_options
and self.rag_options.get("pipeline_ids", None)
and self.rag_options.get("file_ids", None)
"""判断是否有 RAG 选项
Returns:
bool: 是否有 RAG 选项
"""
if self.rag_options and (
len(self.rag_options.get("pipeline_ids", [])) > 0
or len(self.rag_options.get("file_ids", [])) > 0
):
return True
return False
@@ -78,7 +82,7 @@ class ProviderDashscope(ProviderOpenAIOfficial):
if (
self.dashscope_app_type in ["agent", "dialog-workflow"]
and self.has_rag_options()
and not self.has_rag_options()
):
# 支持多轮对话的
new_record = {"role": "user", "content": prompt}
@@ -92,12 +96,15 @@ class ProviderDashscope(ProviderOpenAIOfficial):
if "_no_save" in part:
del part["_no_save"]
# 调用阿里云百炼 API
payload = {
"app_id": self.app_id,
"api_key": self.api_key,
"messages": context_query,
"biz_params": payload_vars or None,
}
partial = functools.partial(
Application.call,
app_id=self.app_id,
api_key=self.api_key,
messages=context_query,
biz_params=payload_vars or None,
**payload,
)
response = await asyncio.get_event_loop().run_in_executor(None, partial)
else:
@@ -134,7 +141,8 @@ class ProviderDashscope(ProviderOpenAIOfficial):
if self.output_reference and response.output.get("doc_references", None):
ref_str = ""
for ref in response.output.get("doc_references", []):
ref_str += f"{ref['index_id']}. {ref['title']}\n"
ref_title = ref.get("title", "") if ref.get("title") else ref.get("doc_name", "")
ref_str += f"{ref['index_id']}. {ref_title}\n"
output_text += f"\n\n回答来源:\n{ref_str}"
return LLMResponse(role="assistant", completion_text=output_text)