mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
fix(ollama): support custom api_key and normalize base_url (closes #3517)
This commit is contained in:
parent
8c5330f742
commit
e20ff7b048
1 changed files with 5 additions and 2 deletions
|
|
@ -10,7 +10,10 @@ logger = setup_logging()
|
||||||
class LLMProvider(LLMProviderBase):
|
class LLMProvider(LLMProviderBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.model_name = config.get("model_name")
|
self.model_name = config.get("model_name")
|
||||||
self.base_url = config.get("base_url", "http://localhost:11434")
|
self.base_url = (config.get("base_url") or "http://localhost:11434").strip().rstrip("/")
|
||||||
|
# 兼容处理用户输入完整端点的情况
|
||||||
|
if self.base_url.endswith("/chat/completions"):
|
||||||
|
self.base_url = self.base_url[:-len("/chat/completions")].rstrip("/")
|
||||||
# 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"):
|
||||||
|
|
@ -18,7 +21,7 @@ class LLMProvider(LLMProviderBase):
|
||||||
|
|
||||||
self.client = OpenAI(
|
self.client = OpenAI(
|
||||||
base_url=self.base_url,
|
base_url=self.base_url,
|
||||||
api_key="ollama", # Ollama doesn't need an API key but OpenAI client requires one
|
api_key=config.get("api_key") or "ollama",
|
||||||
)
|
)
|
||||||
|
|
||||||
# 检查是否是qwen3模型
|
# 检查是否是qwen3模型
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue