29 lines
740 B
Go
29 lines
740 B
Go
package main
|
|
|
|
import (
|
|
"go.wit.com/lib/protobuf/chatpb"
|
|
"google.golang.org/genai"
|
|
)
|
|
|
|
// convertToGenai transforms the parsed JSON request into the genai.Content format.
|
|
func convertToGenai(req *chatpb.GeminiRequest) ([]*genai.Content, error) {
|
|
var contents []*genai.Content
|
|
for _, c := range req.Contents {
|
|
genaiParts := []*genai.Part{} // Create a slice of the interface type
|
|
for _, p := range c.Parts {
|
|
if p.Text != "" {
|
|
// genai.Text returns a Part interface, which is what we need
|
|
var tmp *genai.Part
|
|
tmp = new(genai.Part)
|
|
tmp.Text = p.Text
|
|
genaiParts = append(genaiParts, tmp)
|
|
}
|
|
}
|
|
contents = append(contents, &genai.Content{
|
|
Role: c.Role,
|
|
Parts: genaiParts,
|
|
})
|
|
}
|
|
return contents, nil
|
|
}
|