You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.Net: Feature/gemini function parts format (#13258)
### Motivation and Context
1. Why is this change required?
It appears that there's a quirk to how Gemini handles tool call results
in it's API. The tool responses need to be present in the same chat item
as the tool requests - rather than adding them individually as separate
chat history items.
2. What problem does it solve?
This _appears_ to fix (at least in my use case) the error whereby you
receive:
```
{
"error": {
"code": 400,
"message": "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn.",
"status": "INVALID_ARGUMENT"
}
}
```
4. Which appears to happen when an SK response auto invokes > 1 tool.
When it's a single tool result the API appears to handle the response
gracefully.
5. #12823
6. #12528
-->
### Description
Google Gemini expects the function responses to be grouped together in a
single message rather than split across multiple separate messages with
role "function". By adding a batch tool result overload to the
GeminiChatMessage we can correctly parse the multiple parts of the
function call into their respective function parts.
### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
FYI @stephentoub (As I see you're working in the Gemini connector
recently)
---------
Co-authored-by: Roger Barreto <[email protected]>
Copy file name to clipboardExpand all lines: dotnet/src/Connectors/Connectors.Google.UnitTests/Core/Gemini/Clients/GeminiChatGenerationFunctionCallingTests.cs
+64Lines changed: 64 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -376,6 +376,70 @@ public async Task IfAutoInvokeMaximumAutoInvokeAttemptsReachedShouldStopInvoking
376
376
cisGeminiChatMessageContentgm&&gm.Role==AuthorRole.Tool&&gm.CalledToolResultis not null);
0 commit comments