diff options
| author | Jeff Carr <[email protected]> | 2025-09-01 03:37:10 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-01 03:37:10 -0500 |
| commit | c84460eb65b1776c62119ad76c567dc128c2e5fd (patch) | |
| tree | a97b3cafbb7b5f1998db06da9939f9bfb754a6d5 | |
| parent | c65619154eb37912be8af563de113e028665633c (diff) | |
it builds
| -rw-r--r-- | convertToPB.go | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/convertToPB.go b/convertToPB.go index 3f87e34..e9399b6 100644 --- a/convertToPB.go +++ b/convertToPB.go @@ -1,12 +1,39 @@ package main import ( + "fmt" + "go.wit.com/lib/protobuf/chatpb" "google.golang.org/genai" ) func convertToPB(resp *genai.GenerateContentResponse) *chatpb.ChatEntry { - pb := new(chatpb.ChatEntry) - // TODO: add the code to convert the response to the protobuf - return pb + entry := &chatpb.ChatEntry{} + + if resp == nil || len(resp.Candidates) == 0 || resp.Candidates[0].Content == nil { + return entry + } + + content := resp.Candidates[0].Content + for _, part := range content.Parts { + if part.Text != "" { + entry.Parts = append(entry.Parts, &chatpb.Part{ + PartType: &chatpb.Part_Text{Text: part.Text}, + }) + } + if part.FunctionCall != nil { + fmt.Printf("Gemini API requested to execute command: %s\n", part.FunctionCall.Name) + // This is a simplified conversion of args. + // A more robust implementation would handle different value types. + entry.Parts = append(entry.Parts, &chatpb.Part{ + PartType: &chatpb.Part_FunctionCall{ + FunctionCall: &chatpb.FunctionCall{ + Name: part.FunctionCall.Name, + Args: &chatpb.ArgsInfo{}, // TODO: Properly map args if needed + }, + }, + }) + } + } + return entry } |
