|
1 | | -import { UnboundHandler } from "../unbound" |
| 1 | +import { UnboundHandler, getUnboundModels } from "../unbound" |
2 | 2 | import { ApiHandlerOptions } from "../../../shared/api" |
3 | 3 | import { Anthropic } from "@anthropic-ai/sdk" |
| 4 | +import axios from "axios" |
4 | 5 |
|
5 | 6 | // Mock OpenAI client |
6 | 7 | const mockCreate = jest.fn() |
@@ -299,3 +300,49 @@ describe("UnboundHandler", () => { |
299 | 300 | }) |
300 | 301 | }) |
301 | 302 | }) |
| 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 | +}) |
0 commit comments