feat: 更新模型获取逻辑,处理返回的模型数组并添加鉴权头
This commit is contained in:
@@ -158,7 +158,14 @@ export async function fetchProviderModels(
|
|||||||
endpoint,
|
endpoint,
|
||||||
})
|
})
|
||||||
const response = await fetchWithAuth(`/api/webui/models/list?${params}`)
|
const response = await fetchWithAuth(`/api/webui/models/list?${params}`)
|
||||||
return parseResponse<ModelListItem[]>(response)
|
// 后端返回 { success, models, provider, count },需要展开取出 models 数组
|
||||||
|
const parsed = await parseResponse<{ models?: ModelListItem[] } | ModelListItem[]>(response)
|
||||||
|
if (!parsed.success) {
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
const body = parsed.data
|
||||||
|
const models = Array.isArray(body) ? body : Array.isArray(body?.models) ? body.models : []
|
||||||
|
return { success: true, data: models }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -138,7 +138,11 @@ export function ProviderForm({
|
|||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<form onSubmit={(e) => { e.preventDefault(); handleSaveEdit(); }} autoComplete="off">
|
<form
|
||||||
|
onSubmit={(e) => { e.preventDefault(); handleSaveEdit(); }}
|
||||||
|
autoComplete="off"
|
||||||
|
className="contents"
|
||||||
|
>
|
||||||
<DialogBody>
|
<DialogBody>
|
||||||
<div className="grid gap-4 py-4">
|
<div className="grid gap-4 py-4">
|
||||||
<div className="grid gap-2" data-tour="provider-template-select">
|
<div className="grid gap-2" data-tour="provider-template-select">
|
||||||
|
|||||||
@@ -146,6 +146,11 @@ async def _fetch_models_from_provider(
|
|||||||
client_config = build_openai_compatible_client_config(provider)
|
client_config = build_openai_compatible_client_config(provider)
|
||||||
headers.update(client_config.default_headers)
|
headers.update(client_config.default_headers)
|
||||||
params.update(client_config.default_query)
|
params.update(client_config.default_query)
|
||||||
|
# build_openai_compatible_client_config 在“默认 Bearer”场景下,
|
||||||
|
# 会把 api_key 留在 client_config.api_key 中交给 OpenAI SDK 自行注入 Authorization 头,
|
||||||
|
# 而不会写入 default_headers。这里我们用 httpx 直接发请求,需要手动补上鉴权头/参数。
|
||||||
|
if client_config.api_key and "Authorization" not in headers:
|
||||||
|
headers["Authorization"] = f"Bearer {client_config.api_key}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||||
|
|||||||
Reference in New Issue
Block a user