@@ -491,6 +491,45 @@ func TestGoogleAILive(t *testing.T) {
491491 t .Fatalf ("thoughts tokens should not be zero or greater than 100, got: %d" , resp .Usage .ThoughtsTokens )
492492 }
493493 })
494+ t .Run ("thinking stream with structured output" , func (t * testing.T ) {
495+ type Output struct {
496+ Text string `json:"text"`
497+ }
498+
499+ m := googlegenai .GoogleAIModel (g , "gemini-2.5-flash" )
500+ resp , err := genkit .Generate (ctx , g ,
501+ ai .WithConfig (genai.GenerateContentConfig {
502+ Temperature : genai.Ptr [float32 ](0.4 ),
503+ ThinkingConfig : & genai.ThinkingConfig {
504+ IncludeThoughts : true ,
505+ ThinkingBudget : genai.Ptr [int32 ](1024 ),
506+ },
507+ }),
508+ ai .WithModel (m ),
509+ ai .WithOutputType (Output {}),
510+ ai .WithPrompt ("Analogize photosynthesis and growing up." ),
511+ ai .WithStreaming (func (ctx context.Context , chunk * ai.ModelResponseChunk ) error {
512+ return nil
513+ }),
514+ )
515+ if err != nil {
516+ t .Fatal (err )
517+ }
518+ if resp == nil {
519+ t .Fatal ("nil response obtanied" )
520+ }
521+ var out Output
522+ err = resp .Output (& out )
523+ if err != nil {
524+ t .Fatalf ("unable to unmarshal response: %v" , err )
525+ }
526+ if resp .Usage .ThoughtsTokens == 0 || resp .Usage .ThoughtsTokens > 1024 {
527+ t .Fatalf ("thoughts tokens should not be zero or greater than 1024, got: %d" , resp .Usage .ThoughtsTokens )
528+ }
529+ if resp .Reasoning () == "" {
530+ t .Fatalf ("no reasoning found" )
531+ }
532+ })
494533 t .Run ("thinking disabled" , func (t * testing.T ) {
495534 m := googlegenai .GoogleAIModel (g , "gemini-2.5-flash" )
496535 resp , err := genkit .Generate (ctx , g ,
0 commit comments