mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
refactor(llm): 重构Ollama LLM 提供者并更新依赖
- 将 ollama.py 重命名为 _ollama.py - 替换 OpenAI 客户端为 Ollama 客户端 - 更新 requirements.txt,添加 ollama 依赖
This commit is contained in:
parent
d934e0a69d
commit
30081baf03
2 changed files with 8 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from config.logger import setup_logging
|
||||
from openai import OpenAI
|
||||
from ollama import Client
|
||||
import json
|
||||
from core.providers.llm.base import LLMProviderBase
|
||||
|
||||
|
|
@ -13,12 +13,11 @@ class LLMProvider(LLMProviderBase):
|
|||
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"
|
||||
# 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
|
||||
self.client = Client(
|
||||
host=self.base_url,
|
||||
)
|
||||
|
||||
# 检查是否是qwen3模型
|
||||
|
|
@ -41,8 +40,7 @@ class LLMProvider(LLMProviderBase):
|
|||
|
||||
# 使用修改后的对话
|
||||
dialogue = dialogue_copy
|
||||
|
||||
responses = self.client.chat.completions.create(
|
||||
responses = self.client.chat(
|
||||
model=self.model_name,
|
||||
messages=dialogue,
|
||||
stream=True
|
||||
|
|
@ -107,7 +105,7 @@ class LLMProvider(LLMProviderBase):
|
|||
# 使用修改后的对话
|
||||
dialogue = dialogue_copy
|
||||
|
||||
stream = self.client.chat.completions.create(
|
||||
stream = self.client.chat(
|
||||
model=self.model_name,
|
||||
messages=dialogue,
|
||||
stream=True,
|
||||
|
|
@ -31,3 +31,4 @@ chardet==5.2.0
|
|||
aioconsole==0.8.1
|
||||
markitdown==0.1.1
|
||||
mcp-proxy==0.6.0
|
||||
ollama==0.4.8
|
||||
|
|
|
|||
Loading…
Reference in a new issue