blob: a9dd1b41e1a45d261b33dea215a17194dbea0aa4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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
}
|