fix(responses): finalize stream on [DONE] without finish_reason#1087
fix(responses): finalize stream on [DONE] without finish_reason#1087taoluo wants to merge 1 commit intorouter-for-me:devfrom
Conversation
Summary of ChangesHello @taoluo, 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 robustness of streaming response handling by ensuring that the response stream is properly finalized when a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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.
Code Review
This pull request addresses an issue where streaming responses were not finalized correctly upon receiving a [DONE] message without a finish_reason. The fix involves refactoring the finalization logic into a new finalize function, which is now called in both scenarios. This is a good improvement for robustness. The PR also includes relevant test cases to verify the fix. My review focuses on improving code quality by suggesting the replacement of custom bubble sort implementations with the more efficient and idiomatic sort.Ints from Go's standard library.
| for i := 0; i < len(idxs); i++ { | ||
| for j := i + 1; j < len(idxs); j++ { | ||
| if idxs[j] < idxs[i] { | ||
| idxs[i], idxs[j] = idxs[j], idxs[i] | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This bubble sort implementation is not idiomatic Go. For sorting, it's better to use the standard library's sort.Ints function, which is more efficient (typically IntroSort) and improves code readability. This would require importing the sort package.
This same sorting logic is repeated in multiple places within this function. Applying this change consistently will improve the overall code quality.
sort.Ints(idxs)| for i := 0; i < len(idxs); i++ { | ||
| for j := i + 1; j < len(idxs); j++ { | ||
| if idxs[j] < idxs[i] { | ||
| idxs[i], idxs[j] = idxs[j], idxs[i] | ||
| } | ||
| } | ||
| } |
| for i := 0; i < len(midxs); i++ { | ||
| for j := i + 1; j < len(midxs); j++ { | ||
| if midxs[j] < midxs[i] { | ||
| midxs[i], midxs[j] = midxs[j], midxs[i] | ||
| } | ||
| } | ||
| } |
| for i := 0; i < len(idxs); i++ { | ||
| for j := i + 1; j < len(idxs); j++ { | ||
| if idxs[j] < idxs[i] { | ||
| idxs[i], idxs[j] = idxs[j], idxs[i] | ||
| } | ||
| } | ||
| } |
fix #1085
Caveat: the patch is generated solely by github copilot, please help review it.