diff --git a/go/ai/gen.go b/go/ai/gen.go index 80a9d04e8c..6cebbaa024 100644 --- a/go/ai/gen.go +++ b/go/ai/gen.go @@ -60,6 +60,7 @@ const ( type GenerateResponse struct { Candidates []*Candidate `json:"candidates,omitempty"` Custom any `json:"custom,omitempty"` + Request *GenerateRequest `json:"request,omitempty"` Usage *GenerationUsage `json:"usage,omitempty"` } diff --git a/go/genkit/dotprompt/genkit.go b/go/genkit/dotprompt/genkit.go index 841c1acdb9..ecdb79b478 100644 --- a/go/genkit/dotprompt/genkit.go +++ b/go/genkit/dotprompt/genkit.go @@ -200,10 +200,5 @@ func (p *Prompt) Execute(ctx context.Context, input *ActionInput) (*ai.GenerateR return nil, err } - // TODO(ianlancetaylor): The TypeScript code stores genReq - // with each candidate in resp. The TypeScript code - // extends CandidateData with an optional request field. - // We don't have a natural way to do that in Go. - return resp, nil } diff --git a/go/genkit/dotprompt/genkit_test.go b/go/genkit/dotprompt/genkit_test.go index 190c32e6c2..4fd78a8542 100644 --- a/go/genkit/dotprompt/genkit_test.go +++ b/go/genkit/dotprompt/genkit_test.go @@ -39,6 +39,7 @@ func (testGenerator) Generate(ctx context.Context, req *ai.GenerateRequest, cb g }, }, }, + Request: req, } return r, nil } diff --git a/go/plugins/googleai/googleai.go b/go/plugins/googleai/googleai.go index 96109d8683..577c12841f 100644 --- a/go/plugins/googleai/googleai.go +++ b/go/plugins/googleai/googleai.go @@ -100,7 +100,9 @@ func (g *generator) Generate(ctx context.Context, input *ai.GenerateRequest, cb if err != nil { return nil, err } - return translateResponse(resp), nil + r := translateResponse(resp) + r.Request = input + return r, nil } // Streaming version. @@ -134,6 +136,7 @@ func (g *generator) Generate(ctx context.Context, input *ai.GenerateRequest, cb // to return an empty instead of nil result. r = &ai.GenerateResponse{} } + r.Request = input return r, nil } diff --git a/go/plugins/vertexai/vertexai.go b/go/plugins/vertexai/vertexai.go index 301832effc..12155b27f2 100644 --- a/go/plugins/vertexai/vertexai.go +++ b/go/plugins/vertexai/vertexai.go @@ -74,7 +74,9 @@ func (g *generator) Generate(ctx context.Context, input *ai.GenerateRequest, cb } // Translate from a genai.GenerateContentResponse to a ai.GenerateResponse. - r := &ai.GenerateResponse{} + r := &ai.GenerateResponse{ + Request: input, + } for _, cand := range resp.Candidates { c := &ai.Candidate{} c.Index = int(cand.Index)