40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"go.wit.com/lib/protobuf/chatpb"
|
|
"google.golang.org/genai"
|
|
)
|
|
|
|
func convertToPB(resp *genai.GenerateContentResponse) *chatpb.ChatEntry {
|
|
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
|
|
}
|