@@ -550,6 +550,24 @@ func GenerateText(ctx context.Context, r api.Registry, opts ...GenerateOption) (
550550 return res .Text (), nil
551551}
552552
553+ // GenerateData runs a generate request and returns strongly-typed output.
554+ func GenerateData [Out any ](ctx context.Context , r api.Registry , opts ... GenerateOption ) (* Out , * ModelResponse , error ) {
555+ var value Out
556+ opts = append (opts , WithOutputType (value ))
557+
558+ resp , err := Generate (ctx , r , opts ... )
559+ if err != nil {
560+ return nil , nil , err
561+ }
562+
563+ err = resp .Output (& value )
564+ if err != nil {
565+ return nil , nil , err
566+ }
567+
568+ return & value , resp , nil
569+ }
570+
553571// StreamValue is either a streamed chunk or the final response of a generate request.
554572type StreamValue [Out , Stream any ] struct {
555573 Done bool
@@ -599,24 +617,6 @@ func GenerateStream(ctx context.Context, r api.Registry, opts ...GenerateOption)
599617 }
600618}
601619
602- // GenerateData runs a generate request and returns strongly-typed output.
603- func GenerateData [Out any ](ctx context.Context , r api.Registry , opts ... GenerateOption ) (* Out , * ModelResponse , error ) {
604- var value Out
605- opts = append (opts , WithOutputType (value ))
606-
607- resp , err := Generate (ctx , r , opts ... )
608- if err != nil {
609- return nil , nil , err
610- }
611-
612- err = resp .Output (& value )
613- if err != nil {
614- return nil , nil , err
615- }
616-
617- return & value , resp , nil
618- }
619-
620620// GenerateDataStream generates a model response with streaming and returns strongly-typed output.
621621// It returns a function whose argument function (the "yield function") will be repeatedly
622622// called with the results.
0 commit comments