feat: route upstream keys by model group

This commit is contained in:
wlx committed 2026-09-29 14:46:02 +08:00
1 parent ce0a718686
commit 0876dfe08e
9 files changed
+195 -41

No files matched your search

@@ -227,7 +227,7 @@ class GatewayDeploymentTest {
ApiException error = assertThrows(ApiException.class, () -> controller.chatCompletions("Bearer test-key", Map.of("model", "model-real"),null,new MockHttpServletResponse()));
assertEquals("PROVIDER_NOT_CONFIGURED", error.getCode());
assertEquals(503, error.getStatus());
verify(provider, never()).chat(anyString(), anyString(), anyMap());
verify(provider, never()).chat(anyString(), anyString(), anyString(), anyMap());
}
@Test
@@ -256,13 +256,13 @@ class GatewayDeploymentTest {
when(catalog.authenticateKey("test-key")).thenReturn(key);
when(catalog.activeModel("reasoning-route")).thenReturn(model);
when(catalog.keyCanInvoke(key, "reasoning-route")).thenReturn(true);
when(provider.isConfigured("provider-relay")).thenReturn(true);
when(provider.isConfigured("provider-relay", "reasoning-route", "reasoning-model")).thenReturn(true);
Map<String, Object> upstreamResponse = new java.util.LinkedHashMap<>(Map.of(
"id", "upstream-response",
"choices", List.of(Map.of("index", 0, "message", Map.of("role", "assistant", "content", "", "reasoning_content", "private reasoning"), "finish_reason", "length")),
"usage", Map.of("prompt_tokens", 2, "completion_tokens", 16, "total_tokens", 18)
));
when(provider.chat(eq("provider-relay"), eq("reasoning-model"), anyMap())).thenReturn(upstreamResponse);
when(provider.chat(eq("provider-relay"), eq("reasoning-model"), eq("reasoning-route"), anyMap())).thenReturn(upstreamResponse);
when(billing.reserve(anyMap(), anyMap(), any(), isNull())).thenReturn(new ChatBillingService.Ticket(UUID.randomUUID(), UUID.fromString(userId), ChatMeter.rates(null, true)));
when(billing.settle(any(), anyMap(), anyInt(), isNull())).thenReturn(java.math.BigDecimal.ZERO);
@@ -288,12 +288,12 @@ class GatewayDeploymentTest {
when(catalog.authenticateKey("test-key")).thenReturn(key);
when(catalog.activeModel("empty-route")).thenReturn(model);
when(catalog.keyCanInvoke(key, "empty-route")).thenReturn(true);
when(provider.isConfigured("provider-relay")).thenReturn(true);
when(provider.isConfigured("provider-relay", "empty-route", "empty-model")).thenReturn(true);
Map<String, Object> upstreamResponse = new java.util.LinkedHashMap<>(Map.of(
"id", "upstream-empty",
"choices", List.of(Map.of("index", 0, "message", Map.of("role", "assistant", "content", ""), "finish_reason", "stop"))
));
when(provider.chat(eq("provider-relay"), eq("empty-model"), anyMap())).thenReturn(upstreamResponse);
when(provider.chat(eq("provider-relay"), eq("empty-model"), eq("empty-route"), anyMap())).thenReturn(upstreamResponse);
when(billing.reserve(anyMap(), anyMap(), any(), isNull())).thenReturn(new ChatBillingService.Ticket(UUID.randomUUID(), UUID.fromString(userId), ChatMeter.rates(null, true)));
GatewayController controller = new GatewayController(catalog, provider, guard, billing, new ObjectMapper());