Skip to content

Commit 62e1b0b

Browse files
committed
fix(huggingface): bound context to every available route
1 parent 8a0f913 commit 62e1b0b

2 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎extensions/huggingface/models.test.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,44 @@ describe("huggingface models", () => {
6464
expect(models).toEqual([{ ...bundledModel, contextWindow: 64000 }]);
6565
});
6666

67+
it("limits discovered models to every available route regardless of provider order", async () => {
68+
const bundledModel = HUGGINGFACE_MODEL_CATALOG[0]!;
69+
vi.stubGlobal(
70+
"fetch",
71+
vi.fn(async () =>
72+
Response.json({
73+
data: [
74+
{
75+
id: "Qwen/Qwen3.8-2.4T-A95B",
76+
providers: [{ context_length: 1010000 }, { context_length: 262144 }],
77+
},
78+
{
79+
id: "test/reversed-provider-order",
80+
providers: [{ context_length: 262144 }, { context_length: 1010000 }],
81+
},
82+
{
83+
id: bundledModel.id,
84+
providers: [
85+
{ status: "error", context_length: 16000 },
86+
{ context_length: 96000 },
87+
{ context_length: 0 },
88+
{ context_length: 64000 },
89+
],
90+
},
91+
],
92+
}),
93+
),
94+
);
95+
96+
const models = await discoverHuggingfaceModels("hf_test_token");
97+
98+
expect(models.map(({ id, contextWindow }) => ({ id, contextWindow }))).toEqual([
99+
{ id: "Qwen/Qwen3.8-2.4T-A95B", contextWindow: 262144 },
100+
{ id: "test/reversed-provider-order", contextWindow: 262144 },
101+
{ id: bundledModel.id, contextWindow: 64000 },
102+
]);
103+
});
104+
67105
it("disables tools only when every available route explicitly rejects them", async () => {
68106
vi.stubGlobal(
69107
"fetch",
@@ -108,7 +146,7 @@ describe("huggingface models", () => {
108146
{
109147
id: "test/no-tools-vision",
110148
input: ["text", "image"],
111-
contextWindow: 96000,
149+
contextWindow: 64000,
112150
compat: { supportsTools: false },
113151
},
114152
{

‎extensions/huggingface/models.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ function projectHuggingfaceModels(rows: readonly unknown[]): ModelDefinitionConf
129129
const providers = Array.isArray(entry?.providers)
130130
? entry.providers.filter((provider) => provider?.status !== "error")
131131
: [];
132-
const providerWithContext = providers.find(
133-
(provider) => typeof provider?.context_length === "number" && provider.context_length > 0,
134-
);
132+
const providerContexts = providers
133+
.map((provider) => provider?.context_length)
134+
.filter((context): context is number => typeof context === "number" && context > 0);
135135
const model: ModelDefinitionConfig = catalogById.get(id) ?? {
136136
id,
137137
name: displayNameFromApiEntry(entry),
@@ -144,7 +144,8 @@ function projectHuggingfaceModels(rows: readonly unknown[]): ModelDefinitionConf
144144
};
145145
models.push({
146146
...model,
147-
contextWindow: providerWithContext?.context_length ?? model.contextWindow,
147+
contextWindow:
148+
providerContexts.length > 0 ? Math.min(...providerContexts) : model.contextWindow,
148149
...(providers.length > 0 && providers.every((provider) => provider?.supports_tools === false)
149150
? { compat: { ...model.compat, supportsTools: false } }
150151
: {}),

0 commit comments

Comments
 (0)