Skip to content

Commit 13b2304

Browse files
committed
Limits output tokens to 8192 for all models on Unbound
1 parent 3c75b81 commit 13b2304

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

src/api/providers/__tests__/unbound.test.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { UnboundHandler } from "../unbound"
1+
import { UnboundHandler, getUnboundModels } from "../unbound"
22
import { ApiHandlerOptions } from "../../../shared/api"
33
import { Anthropic } from "@anthropic-ai/sdk"
4+
import axios from "axios"
45

56
// Mock OpenAI client
67
const mockCreate = jest.fn()
@@ -299,3 +300,49 @@ describe("UnboundHandler", () => {
299300
})
300301
})
301302
})
303+
304+
describe("getUnboundModels", () => {
305+
beforeEach(() => {
306+
jest.clearAllMocks()
307+
})
308+
309+
it("should restrict maxTokens to 8192 if it's greater", async () => {
310+
// Mock axios.get to return a model with maxTokens > 8192
311+
jest.spyOn(axios, "get").mockResolvedValueOnce({
312+
data: {
313+
"anthropic/claude-3-opus": {
314+
maxTokens: "10000",
315+
contextWindow: "200000",
316+
supportsPromptCaching: true,
317+
inputTokenPrice: "0.01",
318+
outputTokenPrice: "0.02",
319+
},
320+
},
321+
})
322+
323+
const models = await getUnboundModels()
324+
325+
expect(models["anthropic/claude-3-opus"]).toBeDefined()
326+
expect(models["anthropic/claude-3-opus"].maxTokens).toBe(8192) // Should be restricted to 8192
327+
})
328+
329+
it("should keep maxTokens unchanged if it's 4096 or less", async () => {
330+
// Mock axios.get to return a model with maxTokens = 4096
331+
jest.spyOn(axios, "get").mockResolvedValueOnce({
332+
data: {
333+
"anthropic/claude-3-haiku": {
334+
maxTokens: "4096",
335+
contextWindow: "200000",
336+
supportsPromptCaching: true,
337+
inputTokenPrice: "0.01",
338+
outputTokenPrice: "0.02",
339+
},
340+
},
341+
})
342+
343+
const models = await getUnboundModels()
344+
345+
expect(models["anthropic/claude-3-haiku"]).toBeDefined()
346+
expect(models["anthropic/claude-3-haiku"].maxTokens).toBe(4096) // Should remain unchanged
347+
})
348+
})

src/api/providers/unbound.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,9 @@ export async function getUnboundModels() {
210210
cacheReadsPrice: model?.cacheReadPrice ? parseFloat(model.cacheReadPrice) : undefined,
211211
}
212212

213-
switch (true) {
214-
case modelId.startsWith("anthropic/"):
215-
// Set max tokens to 8192 for supported Anthropic models
216-
if (modelInfo.maxTokens !== 4096) {
217-
modelInfo.maxTokens = 8192
218-
}
219-
break
220-
default:
221-
break
213+
// Restrict max tokens to 8192 for all models
214+
if (modelInfo.maxTokens && modelInfo.maxTokens > 8192) {
215+
modelInfo.maxTokens = 8192
222216
}
223217

224218
models[modelId] = modelInfo

0 commit comments

Comments
 (0)