fix(cody-gateway): Improve prompt and request validation for gemini#63258
fix(cody-gateway): Improve prompt and request validation for gemini#63258
Conversation
- Validate that the input messages are not empty - Ensure the first message is a non-empty assistant message - Skip empty assistant messages at the end of the prompt - Disallow consistent speaker role between consecutive messages - Add tests for the various validation cases
- Moved the google-specific types from google.go to a new google_types.go file - Reorganized the types to improve readability and maintainability - Removed unused fields and methods from the types - Aligned the types with the latest Google API documentation
There was a problem hiding this comment.
All the types are moved to a separate file for clarity.
There was a problem hiding this comment.
This was the cause of the issue where we originally has it as Stream bool json:"stream,omitempty"``
Now it'll not be marshaled into JSON to ensure the unsupported stream field will not be sent to Google
b741413 to
2abb0a1
Compare
2abb0a1 to
d6983b1
Compare
chrsmith
left a comment
There was a problem hiding this comment.
Some nitpicks and suggestions, but this overall looks good. I appreciate you adding unit tests for the new validation logic. Though it would be nice to have even more tests to verify the other change that was made. (Ensuring that we don't serialize the Stream field into JSON.)
| SafetySettings []googleSafetySettings `json:"safetySettings,omitempty"` | ||
| SymtemInstruction string `json:"systemInstruction,omitempty"` | ||
|
|
||
| // Internal field to store the original Stream value |
There was a problem hiding this comment.
Can you elaborate on these comments to clarify? This is definitely going to confuse future people who come across the code.
Would it be correct to say:
// Stream is used for our internal routing of the Google Request, and is not part
// of the Google API shape. So we make sure to not include it when marshaling into JSON.Is that right? Also, I believe it will be the case that unexported fields do not get serialized to JSON by default. So you might be able to "fix" this by renaming the field to stream. But I think having a comment calling out the details here is far preferable.
There was a problem hiding this comment.
Go noob here so i might misunderstand the issue ✋
We currently have the field as stream so i thought the fix is to remove it here. Your comment makes more sense though, updating to use yours instead!
Co-authored-by: Chris Smith <chrsmith@users.noreply.github.com>
|
Going to test the latest commit again. UpdateConfirmed the calls worked from the latest commit build.
|
This PR aims to fix the issue where Cody Gateway is returning error regarding the unsupported
Streamfield showing up in the request:Changes included:
Also fix an issue with google provider for byok customers about last assistant message being empty, which is the default format sent from clients (e.g. VS Code):
This PR addresses this issue by removing the last assistant message if it's empty during the prompt building step to make it more robust:
Test plan
Update Site Config to connect to google API directly in your local instance, and then log into your local instance in VS Code. Verify the responses are correct with no errors.
Changelog