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, ""));
|
||||
|
||||
Reference in new issue
Block a user