Commit 4e40f39
.Net: Fix Gemini Auto Invoke when returned function is non-first part (#12174)
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required?
2. What problem does it solve?
3. What scenario does it contribute to?
4. If it fixes an open issue, please link to the issue here.
-->
Fixes #11651
- Currently Gemini Connectors will not Auto invoke functions when tool
calls are returned in the same message with text parts, which is common
with 2.5 Flash and Pro models:
```json
"content": {
"parts": [
{
"text": "Running the TimePlugin.Now function..."
},
{
"functionCall": {
"name": "TimePlugin.Now",
"args": {
"param1": "hello"
}
}
}
],
"role": "model"
}
```
This fixes this to now support auto kernel functions with this behavior
and adds unit tests with this data.
### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->
- Added unit test data for streaming responses with text & tool parts
- Changed `GetChatMessageContentFromCandidate` to return tools from all
candidate parts instead of only the first part
- Added extra check in `GenerateChatMessageAsync` for empty Tool results
- Fixed stream responses in auto invoke mode with texts & tool parts not
returned to the caller, added unit test
### 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 😄
---------
Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>1 parent e514120 commit 4e40f39
File tree
3 files changed
+49
-7
lines changed- dotnet/src/Connectors
- Connectors.Google.UnitTests
- Core/Gemini/Clients
- TestData
- Connectors.Google/Core/Gemini/Clients
3 files changed
+49
-7
lines changedLines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
275 | 304 | | |
276 | 305 | | |
277 | 306 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
Lines changed: 17 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
359 | 366 | | |
360 | 367 | | |
361 | 368 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | 369 | | |
366 | 370 | | |
367 | 371 | | |
| |||
604 | 608 | | |
605 | 609 | | |
606 | 610 | | |
607 | | - | |
608 | | - | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
609 | 619 | | |
610 | 620 | | |
611 | | - | |
| 621 | + | |
612 | 622 | | |
613 | 623 | | |
614 | 624 | | |
| |||
0 commit comments