-
Notifications
You must be signed in to change notification settings - Fork 1
Scope completion truncation to active provider #49
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
base: dev
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -114,7 +114,8 @@ public ResponseCreateParams buildCompletionRequest( | |
| String prompt, double temperature, RateLimitService.ApiProvider provider) { | ||
| boolean useGitHubModels = provider == RateLimitService.ApiProvider.GITHUB_MODELS; | ||
| String modelId = normalizedModelId(useGitHubModels); | ||
| return buildResponseParams(prompt, temperature, modelId); | ||
| String truncatedPrompt = truncatePromptForCompletion(prompt, modelId); | ||
| return buildResponseParams(truncatedPrompt, temperature, modelId); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -124,16 +125,29 @@ public ResponseCreateParams buildCompletionRequest( | |
| * @return original prompt when no truncation is required, otherwise a notice-prefixed prompt | ||
| */ | ||
| public String truncatePromptForCompletion(String prompt) { | ||
| return truncatePromptForCompletion(prompt, RateLimitService.ApiProvider.OPENAI); | ||
| } | ||
|
|
||
| /** | ||
| * Truncates completion prompts to token limits for the selected provider's model. | ||
| * | ||
| * @param prompt full completion prompt | ||
| * @param provider provider chosen for this request attempt | ||
| * @return original prompt when no truncation is required, otherwise a notice-prefixed prompt | ||
| */ | ||
| public String truncatePromptForCompletion(String prompt, RateLimitService.ApiProvider provider) { | ||
| boolean useGitHubModels = provider == RateLimitService.ApiProvider.GITHUB_MODELS; | ||
| String modelId = normalizedModelId(useGitHubModels); | ||
| return truncatePromptForCompletion(prompt, modelId); | ||
| } | ||
|
|
||
| private String truncatePromptForCompletion(String prompt, String modelId) { | ||
| if (prompt == null || prompt.isEmpty()) { | ||
| return prompt; | ||
| } | ||
|
|
||
| String openaiModelId = normalizedModelId(false); | ||
| String githubModelId = normalizedModelId(true); | ||
| boolean gpt5Family = isGpt5Family(openaiModelId) || isGpt5Family(githubModelId); | ||
| boolean reasoningModel = gpt5Family | ||
| || canonicalModelName(openaiModelId).startsWith("o") | ||
| || canonicalModelName(githubModelId).startsWith("o"); | ||
| boolean gpt5Family = isGpt5Family(modelId); | ||
| boolean reasoningModel = gpt5Family || canonicalModelName(modelId).startsWith("o"); | ||
|
|
||
| int tokenLimit = reasoningModel ? MAX_TOKENS_GPT5_INPUT : MAX_TOKENS_DEFAULT_INPUT; | ||
|
Comment on lines
+149
to
152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/main/java/com/williamcallahan/javachat/service/OpenAiRequestFactory.java
Line: 149-152
Comment:
**`o`-series models receive GPT-5's 7K token limit regardless of context window**
`canonicalModelName(modelId).startsWith("o")` captures `o1`, `o3`, `o3-mini`, etc. and routes them to `MAX_TOKENS_GPT5_INPUT` (7 000 tokens). Many o-series models expose far larger context windows and this mismatch silently truncates prompts that would fit. This was also true before the PR, but the refactor now makes this path the single authoritative one for both providers, so the blast radius is wider. At minimum the assumption should be documented; at best, o-series models should have their own named constant and explicit limit.
How can I resolve this? If you propose a fix, please make it concise. |
||
| String truncatedPrompt = chunker.keepLastTokens(prompt, tokenLimit); | ||
|
|
||
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 no-arg
truncatePromptForCompletion(String prompt)no longer has any production caller — its only call site inOpenAIStreamingService.complete()was removed by this PR, andbuildCompletionRequestnow invokes the privatetruncatePromptForCompletion(String, String)directly. Keeping the method conflicts with [AB1d] ("Delete unused code instead of keeping it 'just in case'") and [RC1b] ("No compatibility shims that hide defects"). The same applies to the new two-arg public overload at line 138, which is also reachable only from tests —buildCompletionRequestbypasses it and calls the private method itself.Consider removing both public overloads and testing via
buildCompletionRequestdirectly, which exercises the full provider-to-model-id path, or make the provider-arg overload the single public entry point.Context Used: AGENTS.md (source)
Prompt To Fix With AI