expose route metadata and remove stale route docs
This commit is contained in:
1 parent
8e9f0d52fd
commit
b2266d7e9d
3 files changed
+43
-3
No files matched your search
+9
-1
@@ -48,6 +48,14 @@ public class GatewayController {
|
||||
item.put("id", model.get("id"));
|
||||
item.put("object", "model");
|
||||
item.put("owned_by", model.get("providerId"));
|
||||
// Keep the OpenAI-compatible id as the exact catalog route UUID.
|
||||
// These descriptive fields let clients show the logical model and
|
||||
// source group without guessing that modelKey is a callable id.
|
||||
item.put("model_key", model.get("modelKey"));
|
||||
item.put("public_name", model.get("publicName"));
|
||||
item.put("vendor_name", model.get("vendorName"));
|
||||
item.put("source_label", model.get("sourceLabel"));
|
||||
item.put("upstream_model", model.get("upstreamModel"));
|
||||
item.put("type", model.get("type"));
|
||||
item.put("mode", model.get("mode"));
|
||||
return item;
|
||||
@@ -72,7 +80,7 @@ public class GatewayController {
|
||||
long startedAt = System.currentTimeMillis();
|
||||
String modelId = String.valueOf(input.getOrDefault("model", ""));
|
||||
Map<String, Object> model = catalogService.activeModel(modelId);
|
||||
if (model == null) throw new ApiException("MODEL_NOT_FOUND", "模型不存在或已下线", 404);
|
||||
if (model == null) throw new ApiException("MODEL_NOT_FOUND", "模型不存在或已下线;请使用当前 API Key 的 /v1/models 返回的渠道分组 ID", 404);
|
||||
if (!catalogService.keyCanInvoke(key, modelId)) throw new ApiException("MODEL_FORBIDDEN", "当前 Key 无权调用该模型", 403);
|
||||
if ("async".equals(model.get("mode"))) throw new ApiException("ASYNC_MODEL", "该模型需要使用异步任务接口", 400);
|
||||
String providerId=String.valueOf(model.get("providerId"));
|
||||
|
||||
+32
@@ -40,6 +40,38 @@ class GatewayDeploymentTest {
|
||||
verify(redis, atLeastOnce()).execute(any(RedisScript.class), eq(List.of("moyi:test:gateway:slots:key:" + keyId)), any(Object[].class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modelsKeepRouteIdAndExposeDisplayMetadata() {
|
||||
CatalogService catalog = mock(CatalogService.class);
|
||||
GatewayGuard guard = mock(GatewayGuard.class);
|
||||
Map<String, Object> key = Map.of("id", UUID.randomUUID().toString());
|
||||
Map<String, Object> route = Map.of(
|
||||
"id", "route-1",
|
||||
"providerId", "provider-apihub",
|
||||
"modelKey", "deepseek-v4-flash",
|
||||
"publicName", "DeepSeek V4 Flash",
|
||||
"vendorName", "DeepSeek",
|
||||
"sourceLabel", "ApiHub 国内",
|
||||
"upstreamModel", "deepseek-v4-flash",
|
||||
"type", "text",
|
||||
"mode", "sync"
|
||||
);
|
||||
when(catalog.authenticateKey("test-key")).thenReturn(key);
|
||||
when(catalog.listModels(false)).thenReturn(List.of(route));
|
||||
when(catalog.keyCanInvoke(key, "route-1")).thenReturn(true);
|
||||
GatewayController controller = new GatewayController(catalog, mock(OpenAiCompatibleProvider.class), guard, mock(ChatBillingService.class), new ObjectMapper());
|
||||
|
||||
Map<String, Object> response = controller.models("Bearer test-key");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> item = ((List<Map<String, Object>>) response.get("data")).getFirst();
|
||||
assertEquals("route-1", item.get("id"));
|
||||
assertEquals("deepseek-v4-flash", item.get("model_key"));
|
||||
assertEquals("DeepSeek V4 Flash", item.get("public_name"));
|
||||
assertEquals("DeepSeek", item.get("vendor_name"));
|
||||
assertEquals("ApiHub 国内", item.get("source_label"));
|
||||
assertEquals("deepseek-v4-flash", item.get("upstream_model"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidRedisPrefixIsRejected() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new GatewayGuard(mock(StringRedisTemplate.class), 60, 300, 4, ""));
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
- APIPro 已登录;公开模型广场显示 306 个模型,控制台确认聊天地址为 `https://api.apipro.ai/v1/chat/completions`,当前导航文档地址为 `https://apipro.apifox.cn/`。
|
||||
- V14 迁移会幂等登记 APIPro 306 项、ApiHub 25 项和 TokenFoundryX 首批 13 项模型;V22 补充 TokenFoundryX 页面新增的 7 项,合计 20 项并为每项创建对应来源分组。新增分组默认停用;没有明确价格或没有对应执行器的模型不会被宣称为可调用。
|
||||
- MOYI 已有用户创建的 `apihub` 渠道(名称“内测1”)和保存的凭据。本次已将协议从 HTTP 修正为 OpenAI 兼容,将 Base URL 补全为 `https://apihub.chem-cloud.cn/v1`,未读取或替换原凭据。
|
||||
- 已在现有 DeepSeek V4 Flash 下添加“ApiHub 国内”分组,关联“内测1”,路由 ID `3dc5d0f8-c7b5-4ff3-9ae8-9077e2e957a9`。
|
||||
- APIPro 渠道已保存,添加“APIPro · DeepSeek”分组,路由 ID `6680d434-538f-408a-bf9a-668801763b79`。2026-09-20 01:20:14 MOYI 返回 `OK`,输入 22、输出 31 Token,耗时 2.12 秒。
|
||||
- 已在现有 DeepSeek V4 Flash 下添加“ApiHub 国内”分组,关联“内测1”。调用时请以当前环境 `GET /v1/models` 返回的 `data[].id` 为准;路由 ID 在迁移或重新建组后可能变化,不要复制旧环境中的固定 UUID。
|
||||
- APIPro 渠道已保存,添加“APIPro · DeepSeek”分组。调用时请以当前 API Key 请求 `GET /v1/models` 返回的 `data[].id` 为准;数据库迁移或重新建组会生成新的路由 UUID。2026-09-20 01:20:14 的旧环境联调曾返回 `OK`,不代表该历史 ID 在当前部署仍有效。
|
||||
- 两次均为旧版服务器上的同步调用,平台费用显示未记录;只验证渠道和模型路由,不代表新版流式/计费已部署验收。两个 MOYI 临时联调 Key 均已停用,调用记录保留。
|
||||
|
||||
## 渠道管理填写
|
||||
|
||||
Reference in new issue
Block a user