mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
fix(llm): strip trailing slash from Xinference base_url
A base_url ending in "/" became "//v1" or "/v1//v1" and every request returned 404; a null base_url raised AttributeError. Normalize it the way #3518 did for the Ollama provider.
This commit is contained in:
parent
242a701984
commit
10e2c0ab97
3 changed files with 27 additions and 1 deletions
|
|
@ -10,7 +10,9 @@ 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:9997")
|
||||
self.base_url = (
|
||||
str(config.get("base_url") or "").strip() or "http://localhost:9997"
|
||||
).rstrip("/")
|
||||
# Initialize OpenAI client with Xinference base URL
|
||||
# 如果没有v1,增加v1
|
||||
if not self.base_url.endswith("/v1"):
|
||||
|
|
|
|||
0
main/xiaozhi-server/tests/core/providers/llm/__init__.py
Normal file
0
main/xiaozhi-server/tests/core/providers/llm/__init__.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import pytest
|
||||
|
||||
from core.providers.llm.xinference.xinference import LLMProvider
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"base_url",
|
||||
[
|
||||
"http://localhost:9997",
|
||||
"http://localhost:9997/",
|
||||
"http://localhost:9997/v1",
|
||||
"http://localhost:9997/v1/",
|
||||
" http://localhost:9997/v1 ",
|
||||
],
|
||||
)
|
||||
def test_base_url_points_at_v1(base_url):
|
||||
provider = LLMProvider({"model_name": "qwen", "base_url": base_url})
|
||||
assert str(provider.client.base_url) == "http://localhost:9997/v1/"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("base_url", [None, ""])
|
||||
def test_missing_base_url_uses_default(base_url):
|
||||
provider = LLMProvider({"model_name": "qwen", "base_url": base_url})
|
||||
assert str(provider.client.base_url) == "http://localhost:9997/v1/"
|
||||
Loading…
Reference in a new issue