调整历史内容格式
This commit is contained in:
@@ -192,14 +192,24 @@ class DifyPlugin(MessagePluginInterface):
|
||||
"Accept": "text/event-stream" # 指定接受事件流
|
||||
}
|
||||
|
||||
# 准备历史记录
|
||||
history_text = ""
|
||||
if self.conversations[session_id]:
|
||||
# 将历史记录转换为字符串格式
|
||||
for msg in self.conversations[session_id]:
|
||||
role = "用户" if msg["role"] == "user" else "助手"
|
||||
history_text += f"{role}: {msg['content']}\n"
|
||||
history_text = history_text.strip()
|
||||
|
||||
# 准备输入参数
|
||||
inputs_params = {
|
||||
"query": query,
|
||||
"conversation_id": session_id
|
||||
}
|
||||
|
||||
# 添加历史记录
|
||||
if self.conversations[session_id]:
|
||||
inputs_params["history"] = self.conversations[session_id]
|
||||
# 如果有历史记录,添加到inputs_params中
|
||||
if history_text:
|
||||
inputs_params["history"] = history_text
|
||||
|
||||
# 准备请求数据
|
||||
data = {
|
||||
@@ -209,7 +219,7 @@ class DifyPlugin(MessagePluginInterface):
|
||||
"response_mode": "blocking" # 使用阻塞响应模式
|
||||
}
|
||||
|
||||
# 添加历史记录
|
||||
# 如果有历史记录,同时添加到conversation_history中
|
||||
if self.conversations[session_id]:
|
||||
data["conversation_history"] = self.conversations[session_id]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user