Commit e047146d by ccran

feat: llm add extra session support;

parent c7bc7aac
...@@ -28,8 +28,8 @@ class LLMTool(ToolBase): ...@@ -28,8 +28,8 @@ class LLMTool(ToolBase):
else: else:
return [{"role": "user", "content": user_content}] return [{"role": "user", "content": user_content}]
async def chat_async(self, messages: List[Dict[str, str]]): async def chat_async(self, messages: List[Dict[str, str]],**extra) -> str:
return await self.llm.chat(messages) return await self.llm.chat(messages, **extra)
async def chat_batch_async(self, messages_list: List[List[Dict[str, str]]]): async def chat_batch_async(self, messages_list: List[List[Dict[str, str]]]):
return await self.llm.mul_chat(messages_list) return await self.llm.mul_chat(messages_list)
...@@ -53,5 +53,7 @@ class LLMTool(ToolBase): ...@@ -53,5 +53,7 @@ class LLMTool(ToolBase):
if __name__ == "__main__": if __name__ == "__main__":
tool = LLMTool(llm_key="nanobot_llm") tool = LLMTool(llm_key="nanobot_llm")
results = asyncio.run(tool.chat_async(tool.build_messages("列出工作目录"))) results = asyncio.run(tool.chat_async(tool.build_messages("列出工作目录"),**{
"session_id": "test_session",
}))
print(results) print(results)
\ No newline at end of file
...@@ -16,7 +16,7 @@ class OpenAITool: ...@@ -16,7 +16,7 @@ class OpenAITool:
) )
@retry(stop=stop_after_delay(600) | stop_after_attempt(3), wait=wait_fixed(1)) @retry(stop=stop_after_delay(600) | stop_after_attempt(3), wait=wait_fixed(1))
async def chat(self, msg, tools=None): async def chat(self, msg, tools=None,**extra):
if tools is None: if tools is None:
extra_body = {} extra_body = {}
# fastgpt专用:如果第一个消息是system角色,则将其内容放入extra_body.variables.system,并从消息列表中移除 # fastgpt专用:如果第一个消息是system角色,则将其内容放入extra_body.variables.system,并从消息列表中移除
...@@ -27,6 +27,8 @@ class OpenAITool: ...@@ -27,6 +27,8 @@ class OpenAITool:
# deepseek专用关闭思考 # deepseek专用关闭思考
extra_body["thinking"] = {"type": "disabled"} extra_body["thinking"] = {"type": "disabled"}
extra_body["chat_template_kwargs"] = {"enable_thinking": False} extra_body["chat_template_kwargs"] = {"enable_thinking": False}
if extra:
extra_body.update(extra)
try: try:
response = await self.client.chat.completions.create( response = await self.client.chat.completions.create(
model=self.llm_config.model, messages=msg, extra_body=extra_body model=self.llm_config.model, messages=msg, extra_body=extra_body
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment