From 4778eef50e9692b6b4c1cfc3a49989f63f84daab Mon Sep 17 00:00:00 2001 From: aileenfun <105077614@qq.com> Date: Fri, 14 Mar 2025 10:53:31 +0800 Subject: [PATCH] =?UTF-8?q?ollama=E8=B0=83=E7=94=A8=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=8E=BB=E9=99=A4=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E4=B8=AD=E7=9A=84think=E5=AD=97=E6=AE=B5=EF=BC=88deepseek?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/providers/llm/ollama/ollama.py | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 main/xiaozhi-server/core/providers/llm/ollama/ollama.py diff --git a/main/xiaozhi-server/core/providers/llm/ollama/ollama.py b/main/xiaozhi-server/core/providers/llm/ollama/ollama.py deleted file mode 100644 index aa5184a4b..000000000 --- a/main/xiaozhi-server/core/providers/llm/ollama/ollama.py +++ /dev/null @@ -1,59 +0,0 @@ -from config.logger import setup_logging -from openai import OpenAI -import json -from core.providers.llm.base import LLMProviderBase - -TAG = __name__ -logger = setup_logging() - - -class LLMProvider(LLMProviderBase): - def __init__(self, config): - self.model_name = config.get("model_name") - self.base_url = config.get("base_url", "http://localhost:11434") - # Initialize OpenAI client with Ollama base URL - #如果没有v1,增加v1 - if not self.base_url.endswith("/v1"): - self.base_url = f"{self.base_url}/v1" - - self.client = OpenAI( - base_url=self.base_url, - api_key="ollama" # Ollama doesn't need an API key but OpenAI client requires one - ) - - def response(self, session_id, dialogue): - try: - responses = self.client.chat.completions.create( - model=self.model_name, - messages=dialogue, - stream=True - ) - - for chunk in responses: - try: - delta = chunk.choices[0].delta if getattr(chunk, 'choices', None) else None - content = delta.content if hasattr(delta, 'content') else '' - if content: - yield content - except Exception as e: - logger.bind(tag=TAG).error(f"Error processing chunk: {e}") - - except Exception as e: - logger.bind(tag=TAG).error(f"Error in Ollama response generation: {e}") - yield "【Ollama服务响应异常】" - - def response_with_functions(self, session_id, dialogue, functions=None): - try: - stream = self.client.chat.completions.create( - model=self.model_name, - messages=dialogue, - stream=True, - tools=functions, - ) - - for chunk in stream: - yield chunk.choices[0].delta.content, chunk.choices[0].delta.tool_calls - - except Exception as e: - logger.bind(tag=TAG).error(f"Error in Ollama function call: {e}") - yield {"type": "content", "content": f"【Ollama服务响应异常: {str(e)}】"} \ No newline at end of file