|
92 | 92 | let firebaseAI = FirebaseAI.componentInstance(config) |
93 | 93 | let session = firebaseAI.generativeModelSession(model: ModelNames.gemini2_5_FlashLite) |
94 | 94 | let prompt = "Generate a Ragdoll kitten" |
| 95 | + let config = GenerationConfig( |
| 96 | + thinkingConfig: ThinkingConfig(thinkingBudget: -1, includeThoughts: true) |
| 97 | + ) |
95 | 98 |
|
96 | | - let response = try await session.respond(to: prompt, generating: CatProfile.self) |
| 99 | + let response = try await session.respond( |
| 100 | + to: prompt, |
| 101 | + generating: CatProfile.self, |
| 102 | + options: config |
| 103 | + ) |
97 | 104 |
|
98 | 105 | let catProfile = response.content |
99 | 106 | #expect(!catProfile.name.isEmpty) |
|
102 | 109 | #expect(!catProfile.profile.isEmpty) |
103 | 110 | #expect(response.rawContent.isComplete) |
104 | 111 | #expect(response.rawContent.generationID != nil) |
| 112 | + let thoughtSummary = try #require( |
| 113 | + response.rawResponse.thoughtSummary, "No thought summary was generated." |
| 114 | + ) |
| 115 | + #expect(!thoughtSummary.isEmpty) |
105 | 116 | } |
106 | 117 |
|
107 | 118 | @Generable |
|
438 | 449 | let firebaseAI = FirebaseAI.componentInstance(config) |
439 | 450 | let session = firebaseAI.generativeModelSession(model: ModelNames.gemini2_5_FlashLite) |
440 | 451 | let prompt = "Generate a Ragdoll kitten" |
| 452 | + let config = GenerationConfig( |
| 453 | + thinkingConfig: ThinkingConfig(thinkingBudget: -1, includeThoughts: true) |
| 454 | + ) |
441 | 455 |
|
442 | 456 | let stream = session.streamResponse( |
443 | 457 | to: prompt, |
444 | | - generating: CatProfile.self |
| 458 | + generating: CatProfile.self, |
| 459 | + options: config |
445 | 460 | ) |
446 | 461 |
|
447 | 462 | var generationID: FirebaseAI.GenerationID? |
448 | 463 | var id: FoundationModels.GenerationID? |
449 | 464 | var isComplete = false |
| 465 | + var thoughtSummary = "" |
450 | 466 | for try await snapshot in stream { |
451 | 467 | #expect(!isComplete, "Stream yielded more elements after a snapshot was marked complete.") |
452 | 468 | let partial = snapshot.content |
|
477 | 493 | } else { |
478 | 494 | id = snapshot.content.id |
479 | 495 | } |
| 496 | + if let partialThoughtSummary = snapshot.rawResponse.thoughtSummary { |
| 497 | + thoughtSummary += partialThoughtSummary |
| 498 | + } |
480 | 499 | isComplete = snapshot.rawContent.isComplete |
481 | 500 | } |
482 | 501 | #expect( |
483 | 502 | isComplete, "The stream finished, but the final snapshot was not marked as complete." |
484 | 503 | ) |
| 504 | + #expect( |
| 505 | + !thoughtSummary.isEmpty, "The stream finished, but no thought summary was generated." |
| 506 | + ) |
485 | 507 |
|
486 | 508 | let response = try await stream.collect() |
487 | 509 | #expect(response.rawContent.isComplete, "The final response was not marked as complete.") |
|
0 commit comments