Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/api/providers/fetchers/__tests__/openrouter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,36 @@ describe("OpenRouter API", () => {
expect(result.contextWindow).toBe(128000)
})

it("sets deepseek-chat-v3.1:free model to 163.8k context window", () => {
const mockModel = {
name: "DeepSeek Chat V3.1 Free",
description: "DeepSeek Chat V3.1 Free model",
context_length: 65536, // OpenRouter incorrectly reports 64k
max_completion_tokens: null,
pricing: {
prompt: "0",
completion: "0",
input_cache_write: undefined,
input_cache_read: undefined,
},
}

const result = parseOpenRouterModel({
id: "deepseek/deepseek-chat-v3.1:free",
model: mockModel,
inputModality: ["text"],
outputModality: ["text"],
maxTokens: null,
supportedParameters: ["temperature", "top_p", "max_tokens"],
})

// Should override the incorrect 64k context with 163.8k
expect(result.contextWindow).toBe(163840)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good test coverage! The test properly validates that the override works as expected, checking both the context window and the recalculated maxTokens.

// maxTokens should be recalculated based on corrected context
expect(result.maxTokens).toBe(Math.ceil(163840 * 0.2))
expect(result.description).toBe("DeepSeek Chat V3.1 Free model")
})

it("filters out image generation models", () => {
const mockImageModel = {
name: "Image Model",
Expand Down
8 changes: 8 additions & 0 deletions src/api/providers/fetchers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,13 @@ export const parseOpenRouterModel = ({
modelInfo.maxTokens = 32768
}

// Set deepseek-chat-v3.1:free model to correct context size
// OpenRouter reports 64k but the actual context is 163.8k tokens
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any documentation or issue tracker link we could reference about why OpenRouter reports incorrect values for this model? It would help future maintainers understand why this override exists.

if (id === "deepseek/deepseek-chat-v3.1:free") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we're adding another hardcoded override here, but the user feedback on issue #7952 specifically mentioned: "hard-coding this specific provider is not the solution. bad bot".

While this does fix the immediate problem, should we consider a more scalable approach? Perhaps:

  • A configuration file for model overrides that can be updated without code changes?
  • Fetching correct values from an upstream metadata service?
  • Working with OpenRouter to fix their API response?

The pattern of hardcoded overrides (we already have 5 others above) is accumulating technical debt.

modelInfo.contextWindow = 163840 // 163.8k tokens
// Recalculate maxTokens based on the corrected context window
modelInfo.maxTokens = maxTokens || Math.ceil(163840 * 0.2)
}

return modelInfo
}
Loading