mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +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 config.logger import setup_logging
|
||||||
from openai import OpenAI
|
from ollama import Client
|
||||||
import json
|
import json
|
||||||
from core.providers.llm.base import LLMProviderBase
|
from core.providers.llm.base import LLMProviderBase
|
||||||
|
|
||||||
|
|
@ -13,12 +13,11 @@ class LLMProvider(LLMProviderBase):
|
||||||
self.base_url = config.get("base_url", "http://localhost:11434")
|
self.base_url = config.get("base_url", "http://localhost:11434")
|
||||||
# Initialize OpenAI client with Ollama base URL
|
# Initialize OpenAI client with Ollama base URL
|
||||||
# 如果没有v1,增加v1
|
# 如果没有v1,增加v1
|
||||||
if not self.base_url.endswith("/v1"):
|
# if not self.base_url.endswith("/v1"):
|
||||||
self.base_url = f"{self.base_url}/v1"
|
# self.base_url = f"{self.base_url}/v1"
|
||||||
|
|
||||||
self.client = OpenAI(
|
self.client = Client(
|
||||||
base_url=self.base_url,
|
host=self.base_url,
|
||||||
api_key="ollama" # Ollama doesn't need an API key but OpenAI client requires one
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 检查是否是qwen3模型
|
# 检查是否是qwen3模型
|
||||||
|
|
@ -41,8 +40,7 @@ class LLMProvider(LLMProviderBase):
|
||||||
|
|
||||||
# 使用修改后的对话
|
# 使用修改后的对话
|
||||||
dialogue = dialogue_copy
|
dialogue = dialogue_copy
|
||||||
|
responses = self.client.chat(
|
||||||
responses = self.client.chat.completions.create(
|
|
||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
messages=dialogue,
|
messages=dialogue,
|
||||||
stream=True
|
stream=True
|
||||||
|
|
@ -107,7 +105,7 @@ class LLMProvider(LLMProviderBase):
|
||||||
# 使用修改后的对话
|
# 使用修改后的对话
|
||||||
dialogue = dialogue_copy
|
dialogue = dialogue_copy
|
||||||
|
|
||||||
stream = self.client.chat.completions.create(
|
stream = self.client.chat(
|
||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
messages=dialogue,
|
messages=dialogue,
|
||||||
stream=True,
|
stream=True,
|
||||||
|
|
@ -31,3 +31,4 @@ chardet==5.2.0
|
||||||
aioconsole==0.8.1
|
aioconsole==0.8.1
|
||||||
markitdown==0.1.1
|
markitdown==0.1.1
|
||||||
mcp-proxy==0.6.0
|
mcp-proxy==0.6.0
|
||||||
|
ollama==0.4.8
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue