Skip to content

Commit 5b31476

Browse files
committed
fix: normalize openai embedding base url and add hint key
1 parent 64ae120 commit 5b31476

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

astrbot/core/config/default.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,7 @@ class ChatProviderTemplate(TypedDict):
17711771
"embedding_api_base": {
17721772
"description": "API Base URL",
17731773
"type": "string",
1774+
"hint": "provider_group.provider.embedding_api_base.hint",
17741775
},
17751776
"volcengine_cluster": {
17761777
"type": "string",

astrbot/core/provider/sources/openai_embedding_source.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ def __init__(self, provider_config: dict, provider_settings: dict) -> None:
2323
if proxy:
2424
logger.info(f"[OpenAI Embedding] 使用代理: {proxy}")
2525
http_client = httpx.AsyncClient(proxy=proxy)
26+
api_base = provider_config.get("embedding_api_base", "").strip()
27+
if not api_base:
28+
api_base = "https://api.openai.com/v1"
29+
else:
30+
api_base = api_base.removesuffix("/")
31+
if not api_base.endswith("/v1"):
32+
api_base = f"{api_base}/v1"
2633
self.client = AsyncOpenAI(
2734
api_key=provider_config.get("embedding_api_key"),
28-
base_url=provider_config.get(
29-
"embedding_api_base",
30-
"https://api.openai.com/v1",
31-
),
35+
base_url=api_base,
3236
timeout=int(provider_config.get("timeout", 20)),
3337
http_client=http_client,
3438
)

0 commit comments

Comments
 (0)