fix: report provider test upstream errors
This commit is contained in:
@@ -378,6 +378,15 @@ class QwenProvider(BaseLLMProvider):
|
||||
|
||||
async def fetch_models_from_api(self) -> List[Dict[str, Any]]:
|
||||
"""通过 DashScope 兼容的 /v1/models 端点在线拉取模型列表"""
|
||||
base_url = (self.api_base or self.DEFAULT_API_BASE).rstrip('/')
|
||||
try:
|
||||
return await self.fetch_models_from_api_strict()
|
||||
except Exception as e:
|
||||
logger.warning(f'在线拉取模型列表失败 ({base_url}): {e}')
|
||||
return []
|
||||
|
||||
async def fetch_models_from_api_strict(self) -> List[Dict[str, Any]]:
|
||||
"""通过 DashScope 兼容端点严格拉取模型列表,失败时保留上游异常"""
|
||||
import httpx
|
||||
|
||||
base_url = (self.api_base or self.DEFAULT_API_BASE).rstrip('/')
|
||||
@@ -385,62 +394,57 @@ class QwenProvider(BaseLLMProvider):
|
||||
if self.api_key:
|
||||
headers['Authorization'] = f'Bearer {self.api_key}'
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=15) as client:
|
||||
resp = await client.get(f'{base_url}/models', headers=headers)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
async with httpx.AsyncClient(timeout=15) as client:
|
||||
resp = await client.get(f'{base_url}/models', headers=headers)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
|
||||
model_list = data.get('data', [])
|
||||
if not model_list:
|
||||
return []
|
||||
|
||||
results = []
|
||||
for item in model_list:
|
||||
model_id = item.get('id', '')
|
||||
if not model_id:
|
||||
continue
|
||||
|
||||
model_lower = model_id.lower()
|
||||
|
||||
if any(kw in model_lower for kw in self._SKIP_KEYWORDS):
|
||||
continue
|
||||
|
||||
if any(kw in model_lower for kw in self._RERANK_KEYWORDS):
|
||||
model_type = 'rerank'
|
||||
elif any(kw in model_lower for kw in self._EMBEDDING_KEYWORDS):
|
||||
model_type = 'embedding'
|
||||
else:
|
||||
model_type = 'chat'
|
||||
|
||||
results.append({
|
||||
'model_name': model_id,
|
||||
'display_name': model_id,
|
||||
'model_type': model_type,
|
||||
'max_tokens': 4096,
|
||||
'context_window': 4096,
|
||||
'supports_vision': False,
|
||||
'supports_function_call': model_type == 'chat',
|
||||
'input_price': 0,
|
||||
'output_price': 0,
|
||||
})
|
||||
|
||||
# DashScope /v1/models 可能只返回 chat 模型,
|
||||
# 将默认列表中的 embedding/rerank 模型合并进去
|
||||
fetched_names = {m['model_name'] for m in results}
|
||||
for dm in self.__class__.get_default_models():
|
||||
if dm['model_type'] in ('embedding', 'rerank') and dm['model_name'] not in fetched_names:
|
||||
results.append(dm)
|
||||
|
||||
type_order = {'chat': 0, 'embedding': 1, 'rerank': 2}
|
||||
results.sort(key=lambda m: (type_order.get(m['model_type'], 9), m['model_name']))
|
||||
logger.info(f'从 {base_url} 拉取到 {len(results)} 个模型(含补充的 embedding/rerank)')
|
||||
return results
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f'在线拉取模型列表失败 ({base_url}): {e}')
|
||||
model_list = data.get('data', [])
|
||||
if not model_list:
|
||||
return []
|
||||
|
||||
results = []
|
||||
for item in model_list:
|
||||
model_id = item.get('id', '')
|
||||
if not model_id:
|
||||
continue
|
||||
|
||||
model_lower = model_id.lower()
|
||||
|
||||
if any(kw in model_lower for kw in self._SKIP_KEYWORDS):
|
||||
continue
|
||||
|
||||
if any(kw in model_lower for kw in self._RERANK_KEYWORDS):
|
||||
model_type = 'rerank'
|
||||
elif any(kw in model_lower for kw in self._EMBEDDING_KEYWORDS):
|
||||
model_type = 'embedding'
|
||||
else:
|
||||
model_type = 'chat'
|
||||
|
||||
results.append({
|
||||
'model_name': model_id,
|
||||
'display_name': model_id,
|
||||
'model_type': model_type,
|
||||
'max_tokens': 4096,
|
||||
'context_window': 4096,
|
||||
'supports_vision': False,
|
||||
'supports_function_call': model_type == 'chat',
|
||||
'input_price': 0,
|
||||
'output_price': 0,
|
||||
})
|
||||
|
||||
# DashScope /v1/models 可能只返回 chat 模型,
|
||||
# 将默认列表中的 embedding/rerank 模型合并进去
|
||||
fetched_names = {m['model_name'] for m in results}
|
||||
for dm in self.__class__.get_default_models():
|
||||
if dm['model_type'] in ('embedding', 'rerank') and dm['model_name'] not in fetched_names:
|
||||
results.append(dm)
|
||||
|
||||
type_order = {'chat': 0, 'embedding': 1, 'rerank': 2}
|
||||
results.sort(key=lambda m: (type_order.get(m['model_type'], 9), m['model_name']))
|
||||
logger.info(f'从 {base_url} 拉取到 {len(results)} 个模型(含补充的 embedding/rerank)')
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
def get_default_models(cls) -> List[Dict[str, Any]]:
|
||||
"""获取默认模型列表"""
|
||||
|
||||
Reference in New Issue
Block a user