This commit is contained in:
Andrew Chen 2026-11-27 01:00:43 +08:00 committed by GitHub
commit d2aafd374f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View file

@ -10,7 +10,9 @@ 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:9997") self.base_url = (
str(config.get("base_url") or "").strip() or "http://localhost:9997"
).rstrip("/")
# Initialize OpenAI client with Xinference base URL # Initialize OpenAI client with Xinference base URL
# 如果没有v1,增加v1 # 如果没有v1,增加v1
if not self.base_url.endswith("/v1"): if not self.base_url.endswith("/v1"):

View 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/"