summaryrefslogtreecommitdiff
path: root/convertToGenai.go
blob: c65d29b5353620bec8c8406d0b1dccc32a3457fa (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
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
}