fix(chutes): honor serving context limits (#119196)

This commit is contained in:
mushuiyu886
2026-08-05 10:42:54 +08:00
committed by GitHub
parent 5ffd2dfbc3
commit e8eb765ab7
2 changed files with 40 additions and 1 deletions
+35
View File
@@ -238,6 +238,41 @@ describe("chutes-models", () => {
});
});
it("selects Chutes context limits in provider precedence order", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
data: [
{
id: "provider/context-primary",
context_length: 131072,
max_model_len: 262144,
},
{ id: "provider/serving-fallback", max_model_len: 131072 },
{
id: "provider/invalid-primary",
context_length: -1,
max_model_len: 131072,
},
{
id: "provider/default-control",
context_length: 0,
max_model_len: 0,
},
],
}),
);
await withLiveChutesDiscovery(mockFetch, async () => {
const models = await discoverChutesModels("context-limit-precedence");
expect(models.map(({ id, contextWindow }) => ({ id, contextWindow }))).toEqual([
{ id: "provider/context-primary", contextWindow: 131072 },
{ id: "provider/serving-fallback", contextWindow: 131072 },
{ id: "provider/invalid-primary", contextWindow: 131072 },
{ id: "provider/default-control", contextWindow: 128000 },
]);
});
});
it("falls back from malformed live token metadata", async () => {
const mockFetch = vi.fn().mockResolvedValue(
jsonResponse({
+5 -1
View File
@@ -50,6 +50,7 @@ interface ChutesModelEntry {
supported_features?: string[];
input_modalities?: string[];
context_length?: number;
max_model_len?: number;
max_output_length?: number;
pricing?: {
prompt?: number;
@@ -93,7 +94,10 @@ function projectChutesModels(rows: readonly unknown[]): ModelDefinitionConfig[]
cacheRead: entry.pricing?.input_cache_read || 0,
cacheWrite: 0,
},
contextWindow: asPositiveSafeInteger(entry.context_length) ?? CHUTES_DEFAULT_CONTEXT_WINDOW,
contextWindow:
asPositiveSafeInteger(entry.context_length) ??
asPositiveSafeInteger(entry.max_model_len) ??
CHUTES_DEFAULT_CONTEXT_WINDOW,
maxTokens: asPositiveSafeInteger(entry.max_output_length) ?? CHUTES_DEFAULT_MAX_TOKENS,
compat: { supportsUsageInStreaming: false },
});