-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgemini.go
60 lines (52 loc) · 1.21 KB
/
gemini.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gemini
import (
"context"
"fmt"
"strings"
"github.com/google/generative-ai-go/genai"
"google.golang.org/api/option"
)
func AskForData(input, key string) ([]string, error) {
ctx := context.Background()
output := []string{}
client, err := genai.NewClient(ctx, option.WithAPIKey(key))
if err != nil {
return output, err
}
defer client.Close()
model := client.GenerativeModel("gemini-1.5-pro")
//model.
/*model.SetTemperature(0.8)
model.SetTopP(0.6)
model.SetTopK(5)
model.SetMaxOutputTokens(1000)
model.SetCandidateCount(1)*/
resp, err := model.GenerateContent(ctx, genai.Text(input))
if err != nil {
return output, err
}
output = printResponse(resp)
/*
for _, cand := range resp.Candidates {
if cand.Content != nil {
for _, part := range cand.Content.Parts {
output = append(output, fmt.Sprint(part))
}
}
}*/
return output, nil
}
func printResponse(resp *genai.GenerateContentResponse) []string {
var otp []string
for _, cand := range resp.Candidates {
if cand.Content != nil {
for _, part := range cand.Content.Parts {
fmt.Println(part)
otps := strings.Split(fmt.Sprint(part), "\n")
otp = append(otp, otps...)
}
}
}
fmt.Println("---")
return otp
}