-
-
Notifications
You must be signed in to change notification settings - Fork 286
fix(codex): estimate reasoning tokens from accumulated content when u… #357
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?
fix(codex): estimate reasoning tokens from accumulated content when u… #357
Conversation
…pstream omits them 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary of ChangesHello @nestharus, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Codex response translation logic by introducing a robust mechanism to handle cases where upstream services do not provide explicit Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a fallback mechanism to estimate reasoning tokens for both streaming and non-streaming Codex responses when the upstream service does not provide them. The implementation is logical and correctly handles the estimation. My review includes suggestions to improve code quality by replacing a magic number with a named constant and addressing code duplication for the token estimation logic. These changes will enhance the code's readability and maintainability.
| // Estimate reasoning tokens from accumulated content (approx 4 chars per token) | ||
| estimatedTokens := int64((*param).(*ConvertCliToOpenAIParams).AccumulatedReasoningLen / 4) | ||
| if estimatedTokens == 0 { | ||
| estimatedTokens = 1 | ||
| } |
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 magic number 4 is used for token estimation. It's better to define this as a constant, like const defaultCharsPerToken = 4, to improve readability and maintainability. Also, this token estimation logic is duplicated in the non-streaming function (ConvertCodexResponseToOpenAINonStream). You might consider extracting it into a helper function to avoid code duplication and ensure consistency.
| // Estimate reasoning tokens from accumulated content (approx 4 chars per token) | |
| estimatedTokens := int64((*param).(*ConvertCliToOpenAIParams).AccumulatedReasoningLen / 4) | |
| if estimatedTokens == 0 { | |
| estimatedTokens = 1 | |
| } | |
| // Estimate reasoning tokens from accumulated content (approx 4 chars per token) | |
| const defaultCharsPerToken = 4 | |
| estimatedTokens := int64((*param).(*ConvertCliToOpenAIParams).AccumulatedReasoningLen / defaultCharsPerToken) | |
| if estimatedTokens == 0 { | |
| estimatedTokens = 1 | |
| } |
| // Estimate from reasoning content (approx 4 chars per token) | ||
| reasoningTokens = int64(len(reasoningText) / 4) | ||
| if reasoningTokens == 0 { | ||
| reasoningTokens = 1 | ||
| } |
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 magic number 4 is used here for token estimation, similar to the streaming implementation. To improve maintainability and ensure consistency, this should be a shared constant. As this logic is duplicated, consider creating a common helper function for token estimation.
// Estimate from reasoning content (approx 4 chars per token)
const defaultCharsPerToken = 4
reasoningTokens = int64(len(reasoningText) / defaultCharsPerToken)
if reasoningTokens == 0 {
reasoningTokens = 1
}
#356
PR details:
Summary
AccumulatedReasoningLenfield to track reasoning content length during streamingoutput_tokens_details.reasoning_tokensTest plan