27 lines
661 B
Go
27 lines
661 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.GetContents() {
|
|
var genaiParts []*genai.Part
|
|
for _, p := range c.GetParts() {
|
|
switch v := p.GetPartType().(type) {
|
|
case *chatpb.Part_Text:
|
|
part := &genai.Part{Text: v.Text}
|
|
genaiParts = append(genaiParts, part)
|
|
}
|
|
}
|
|
contents = append(contents, &genai.Content{
|
|
Role: c.GetRole(),
|
|
Parts: genaiParts,
|
|
})
|
|
}
|
|
return contents, nil
|
|
}
|