blob: 3fda5ec604d1893beeaccb34788c8eb1d0e2aa8b (
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
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
|
package main
import (
"context"
"fmt"
"log"
"os"
// "github.com/google/generative-ai-go/genai"
"cloud.google.com/go/ai/vertexai/genai"
"google.golang.org/api/option"
)
func main() {
ctx := context.Background()
apiKey := os.Getenv("GEMINI_API_KEY")
if apiKey == "" {
log.Fatal("GEMINI_API_KEY environment variable not set")
}
client, err := genai.NewClient(ctx, option.WithAPIKey(apiKey))
if err != nil {
log.Fatalf("Failed to create genai client: %v", err)
}
defer client.Close()
model := client.GenerativeModel("gemini-2.5-pro-preview-03-25")
// Set system instruction
model.SystemInstruction = &genai.Content{
Parts: []genai.Part{
genai.Text("This is for working with the GO language files at http://go.wit.com/"),
},
}
// Stream content generation
iter := model.GenerateContentStream(ctx, genai.Text("what is the current version of forge on the webpage?"))
for {
resp, err := iter.Next()
if err != nil {
break
}
for _, part := range resp.Candidates {
if part.Content != nil {
for _, p := range part.Content.Parts {
if text, ok := p.(genai.Text); ok {
fmt.Print(string(text))
}
}
}
}
}
}
|