-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex.go
50 lines (40 loc) · 1.11 KB
/
vertex.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
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"cloud.google.com/go/vertexai/genai"
)
func runVertexAI(model string, prompt string, file string, fileMime string) {
ctx := context.Background()
projectId := os.Getenv("GOOGLE_PROJECT_ID")
region := os.Getenv("GOOGLE_REGION")
client, err := genai.NewClient(ctx, projectId, region)
if err != nil {
log.Fatal("client connect error", err)
}
defer client.Close()
fd, err := os.ReadFile(file)
if err != nil {
log.Fatal("read file error", err)
}
parts := []genai.Part{
// genai.FileData{MIMEType: fileMime, FileURI: fileURI},
genai.Blob{MIMEType: fileMime, Data: fd},
genai.Text(prompt),
}
m := client.GenerativeModel(model) // "gemini-1.5-pro-preview-0409"
m.SetTemperature(0.0)
m.SetTopP(0.95)
resp, err := m.GenerateContent(ctx, parts...)
if err != nil {
log.Fatal("generate content error", err)
}
bs, _ := json.MarshalIndent(resp, "", " ")
// out := append([]byte(fmt.Sprintf("INSTRUCTION:\"%s\"\n", instruction)), bs...)
// os.WriteFile(page+".out", out, 0644)
fmt.Println("Vertex AI response:")
fmt.Println(string(bs))
}