-
Couldn't load subscription status.
- Fork 2.4k
fix: use max_completion_tokens for GPT-5 models in LiteLLM provider #6980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c04e019
3d576b1
f89b23c
822886b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,16 +107,26 @@ export class LiteLLMHandler extends RouterProvider implements SingleCompletionHa | |||||||||
| // Required by some providers; others default to max tokens allowed | ||||||||||
| let maxTokens: number | undefined = info.maxTokens ?? undefined | ||||||||||
|
|
||||||||||
| // Check if this is a GPT-5 model that requires max_completion_tokens instead of max_tokens | ||||||||||
| const isGPT5Model = modelId.toLowerCase().includes("gpt-5") || modelId.toLowerCase().includes("gpt5") | ||||||||||
|
||||||||||
| const isGPT5Model = modelId.toLowerCase().includes("gpt-5") || modelId.toLowerCase().includes("gpt5") | |
| // Check if this is a GPT-5 model that requires max_completion_tokens instead of max_tokens | |
| const modelLower = modelId.toLowerCase() | |
| const isGPT5Model = modelLower.startsWith("gpt-5") || modelLower.startsWith("gpt5") || modelLower === "gpt5" |
Outdated
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GPT-5 model detection logic is duplicated between the createMessage and completePrompt methods. Consider extracting this into a private helper method to improve maintainability and ensure consistency.
daniel-lxs marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to avoid using @ts-ignore here? Could we extend the OpenAI types or create a custom interface that includes max_completion_tokens to maintain type safety? For example:
interface GPT5RequestOptions extends Omit<OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming, 'max_tokens'> {
max_completion_tokens?: number
max_tokens?: never
}
Outdated
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using @ts-ignore to suppress TypeScript errors for max_completion_tokens is not ideal. Consider using type assertion with a more specific interface or extending the OpenAI types to include this property for better type safety.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This detection logic is duplicated from line 111. Would it be cleaner to extract this into a helper method to maintain DRY principles? Something like:
private isGPT5Model(modelId: string): boolean {
const modelLower = modelId.toLowerCase()
return modelLower.startsWith("gpt-5") || modelLower.startsWith("gpt5") || modelLower === "gpt5"
}
Outdated
Copilot
AI
Sep 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a duplicate of the previous @ts-ignore comment. The same type safety concerns apply here - consider using a consistent approach to handle the missing type definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! Consider adding edge cases like mixed case variations ("GpT-5", "gPt5") or models with additional suffixes ("gpt-5-32k", "gpt-5-vision") to ensure the detection works correctly for all possible GPT-5 model names.