Skip to content

Commit 90ef2d4

Browse files
authored
Merge pull request #187 from arraycto/master
添加支持Minimax模型厂商api测试适配
2 parents d18c216 + 622963c commit 90ef2d4

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

services/aimodel_service.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,48 @@ async def check_llm_status(data: dict) -> dict:
220220
resp.raise_for_status()
221221
return {"success": True, "message": "连接成功"}
222222

223+
# MiniMax 特殊处理
224+
elif supplier == 10: # MiniMax
225+
# MiniMax 使用兼容OpenAI的API,但可能有特定的端点要求
226+
domain = api_domain
227+
228+
# 根据搜索结果,MiniMax的API端点可能不是标准的/models
229+
# 尝试使用更简单的连接测试方法
230+
url = f"{domain}/models"
231+
headers = {"Content-Type": "application/json"}
232+
if api_key:
233+
headers["Authorization"] = f"Bearer {api_key}"
234+
235+
try:
236+
async with httpx.AsyncClient() as client:
237+
resp = await client.get(url, headers=headers, timeout=10)
238+
resp.raise_for_status()
239+
return {"success": True, "message": "连接成功"}
240+
except httpx.HTTPStatusError as e:
241+
if e.response.status_code == 404:
242+
# 对于MiniMax,如果/models端点不存在,尝试直接测试连接
243+
# 使用一个简单的HEAD请求来测试网络连接
244+
try:
245+
async with httpx.AsyncClient() as client:
246+
# 尝试对基础域名进行连接测试
247+
base_domain = domain.replace('/v1', '')
248+
resp = await client.head(base_domain, timeout=5)
249+
# 如果能连接到域名,说明配置基本正确
250+
return {"success": True, "message": "连接成功"}
251+
except:
252+
return {"success": False, "message": "无法连接到API域名,请检查网络和域名配置"}
253+
elif e.response.status_code == 401:
254+
return {"success": False, "message": "API Key 无效或未授权"}
255+
else:
256+
return {"success": False, "message": f"连接失败: HTTP {e.response.status_code}"}
257+
except httpx.TimeoutException:
258+
return {"success": False, "message": "连接超时,请检查网络或API域名"}
259+
except httpx.ConnectError:
260+
return {"success": False, "message": "无法连接到服务器,请检查API域名"}
261+
except Exception as e:
262+
logger.error(f"MiniMax连接测试失败: {e}")
263+
return {"success": False, "message": f"连接失败: {str(e)}"}
264+
223265
# 其他供应商(DeepSeek, Qwen, Moonshot, ZhipuAI 等)
224266
else:
225267
# 尝试使用 OpenAI 兼容协议测试
@@ -237,6 +279,9 @@ async def check_llm_status(data: dict) -> dict:
237279
if e.response.status_code == 401:
238280
return {"success": False, "message": "API Key 无效或未授权"}
239281
elif e.response.status_code == 404:
282+
# 对于MiniMax等供应商,可能需要特殊处理
283+
if supplier == 10: # MiniMax
284+
return {"success": False, "message": "API 端点不存在,请检查 API 域名。MiniMax 可能需要使用完整的模型列表端点"}
240285
return {"success": False, "message": "API 端点不存在,请检查 API 域名"}
241286
else:
242287
return {"success": False, "message": f"连接失败: HTTP {e.response.status_code}"}
@@ -309,6 +354,30 @@ async def fetch_base_models(supplier: int, api_key: str = None, api_domain: str
309354
models = [m['id'] for m in data.get('data', [])]
310355
return sorted(models)
311356

357+
# MiniMax
358+
elif supplier == 10:
359+
if not api_key:
360+
return []
361+
domain = api_domain or "https://api.minimaxi.com/v1"
362+
url = f"{domain}/models"
363+
headers = {"Authorization": f"Bearer {api_key}"}
364+
365+
try:
366+
async with httpx.AsyncClient() as client:
367+
resp = await client.get(url, headers=headers, timeout=10)
368+
resp.raise_for_status()
369+
data = resp.json()
370+
# 根据OpenAI兼容API格式提取模型列表
371+
if 'data' in data:
372+
models = [m['id'] for m in data.get('data', [])]
373+
else:
374+
# 如果没有data字段,尝试其他格式
375+
models = [m['id'] for m in data] if isinstance(data, list) else []
376+
return sorted(models)
377+
except:
378+
# 如果获取模型列表失败,返回一些常见的MiniMax模型名称
379+
return ["MiniMax-M2.1", "abab6.5s-chat", "abab5.5-chat"]
380+
312381
# Fallback or other providers: Return empty list or hardcoded common ones?
313382
# For now return empty, frontend can allow manual entry
314383
return []

web/src/components/llm/llm-form.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const supplierOptions = [
3939
{ label: 'Qwen', value: 6 },
4040
{ label: 'Moonshot', value: 7 },
4141
{ label: 'ZhipuAI', value: 8 },
42+
{ label: 'MiniMax', value: 10 },
4243
{ label: 'Other', value: 9 },
4344
]
4445
@@ -90,6 +91,11 @@ watch(() => formData.supplier, (val) => {
9091
formData.api_domain = 'https://open.bigmodel.cn/api/paas/v4/'
9192
}
9293
formData.protocol = 1
94+
} else if (val === 10) { // MiniMax
95+
if (!formData.api_domain) {
96+
formData.api_domain = 'https://api.minimaxi.com/v1'
97+
}
98+
formData.protocol = 1
9399
}
94100
})
95101

web/src/views/system/config/llm-config.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const getSupplierName = (supplier: number) => {
8888
6: 'Qwen',
8989
7: 'Moonshot',
9090
8: 'ZhipuAI',
91+
10: 'MiniMax',
9192
9: 'Other',
9293
}
9394
return map[supplier] || 'Unknown'

0 commit comments

Comments
 (0)