diff --git a/dsLightRag/Util/GoApiUtil.py b/dsLightRag/Util/GoApiUtil.py index 63bee6bc..ed6a0fda 100644 --- a/dsLightRag/Util/GoApiUtil.py +++ b/dsLightRag/Util/GoApiUtil.py @@ -11,7 +11,7 @@ class ModelInteractor: "Authorization": f"Bearer {self.api_key}" } - def stream_request(self, model, prompt, temperature=0.7): + def stream_request(self, model, prompt, temperature=0.7, chat_history=None): """ 发送流式请求到模型API @@ -23,12 +23,20 @@ class ModelInteractor: 返回: - 无返回值,直接打印流式响应 """ + # 构建消息列表 + messages = [] + # 添加对话历史 + if chat_history: + messages.extend(chat_history) + # 添加当前prompt + messages.append({ + "role": "user", + "content": prompt + }) + payload = { "model": model, - "messages": [{ - "role": "user", - "content": prompt - }], + "messages": messages, "temperature": temperature, "stream": True } diff --git a/dsLightRag/Util/__pycache__/GoApiUtil.cpython-310.pyc b/dsLightRag/Util/__pycache__/GoApiUtil.cpython-310.pyc index bc90e46d..f46f98fb 100644 Binary files a/dsLightRag/Util/__pycache__/GoApiUtil.cpython-310.pyc and b/dsLightRag/Util/__pycache__/GoApiUtil.cpython-310.pyc differ