-
Notifications
You must be signed in to change notification settings - Fork 59.8k
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
Fix issue #5964: Prevents character loss in gemini-2.0-flash-thinking-exp-1219 responses #5965
Conversation
@zmhuanf is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe pull request modifies the Changes
Possibly related PRs
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
app/client/platforms/google.ts (2)
63-70
: LGTM! Consider adding TypeScript types for better type safety.The new helper function effectively centralizes text extraction logic with proper null checks and empty string filtering. This abstraction should help prevent the initial character omission issue.
Consider adding explicit TypeScript types:
-const getTextFromParts = (parts: any[]) => { +interface Part { + text?: string; +} +const getTextFromParts = (parts: Part[]) => {
Line range hint
63-238
: Good architectural approach with room for improvement.The introduction of
getTextFromParts
is a good architectural decision that centralizes text extraction logic and adds proper null checks. However, to fully address the character omission issue:
- The streaming logic should be aligned with
getTextFromParts
to ensure consistent text extraction across all code paths.- Consider adding unit tests to verify text extraction behavior, especially for edge cases with empty or whitespace-only parts.
Would you like me to help create unit tests for the text extraction logic?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/client/platforms/google.ts
(2 hunks)
🔇 Additional comments (1)
app/client/platforms/google.ts (1)
73-74
: LGTM! Clean and consistent error handling.
The modified extraction logic properly handles different response structures while maintaining good fallback behavior.
return chunkJson?.candidates | ||
?.at(0) | ||
?.content.parts?.map((part: { text: string }) => part.text) | ||
.join("\n\n"); |
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.
Align streaming text extraction with getTextFromParts
for consistency.
The streaming response handling uses a different approach for text extraction compared to getTextFromParts
. This inconsistency could potentially lead to different handling of empty parts or whitespace.
Consider reusing the getTextFromParts
function here:
-return chunkJson?.candidates
- ?.at(0)
- ?.content.parts?.map((part: { text: string }) => part.text)
- .join("\n\n");
+return getTextFromParts(chunkJson?.candidates?.at(0)?.content?.parts || []);
Committable suggestion skipped: line range outside the PR's diff.
I'll merge the code later. Thanks! |
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
修复了在使用
gemini-2.0-flash-thinking-exp-1219
模型时,模型会意外吞掉一些正式回答开始时的字符的问题。该问题在 #5964 中被提出。This pull request addresses the bug reported in issue #5964, where the
gemini-2.0-flash-thinking-exp-1219
model would unexpectedly omit the initial characters of its formal responses.📝 补充信息 | Additional Information
Summary by CodeRabbit
New Features
Improvements