feat: route upstream keys by model group
This commit is contained in:
1 parent
ce0a718686
commit
0876dfe08e
9 files changed
+195
-41
No files matched your search
+19
-1
@@ -28,11 +28,12 @@ class OpenAiCompatibleProviderHttpTest {
|
||||
private final ObjectMapper json = new ObjectMapper();
|
||||
private HttpServer server;
|
||||
private OpenAiCompatibleProvider provider;
|
||||
private MockEnvironment environment;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
var environment = new MockEnvironment()
|
||||
environment = new MockEnvironment()
|
||||
.withProperty("moyi.providers.deepseek.api-key", "local-fake-key")
|
||||
.withProperty("moyi.providers.deepseek.base-url", "http://127.0.0.1:" + server.getAddress().getPort() + "/v1")
|
||||
.withProperty("moyi.gateway.upstream-timeout-seconds", "5");
|
||||
@@ -93,6 +94,23 @@ class OpenAiCompatibleProviderHttpTest {
|
||||
assertEquals(512, input.get("max_tokens"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void prefersRouteKeyThenModelKeyBeforeProviderKey() throws Exception {
|
||||
var authorization = new ArrayList<String>();
|
||||
server.createContext("/v1/chat/completions", exchange -> {
|
||||
authorization.add(exchange.getRequestHeaders().getFirst("Authorization"));
|
||||
write(exchange, 200, "{\"id\":\"ok\",\"choices\":[{\"message\":{\"role\":\"assistant\",\"content\":\"OK\"}}],\"usage\":{\"prompt_tokens\":1,\"completion_tokens\":1,\"total_tokens\":2}}");
|
||||
});
|
||||
server.start();
|
||||
environment.withProperty("MOYI_UPSTREAM_API_KEYS_ROUTE_ROUTE_A", "route-key")
|
||||
.withProperty("MOYI_UPSTREAM_API_KEYS_MODEL_GPT_5", "model-key");
|
||||
|
||||
provider.chat("provider-deepseek", "gpt-5", "route-a", textInput(128));
|
||||
provider.chat("provider-deepseek", "gpt-5", "route-b", textInput(128));
|
||||
|
||||
assertEquals(List.of("Bearer route-key", "Bearer model-key"), authorization);
|
||||
}
|
||||
|
||||
private Map<String, Object> textInput(int maxTokens) {
|
||||
var input = new LinkedHashMap<String, Object>();
|
||||
input.put("messages", List.of(Map.of("role", "user", "content", "Reply with OK.")));
|
||||
|
||||
Reference in new issue
Block a user