hmm
This commit is contained in:
parent
9ba9093875
commit
1b0344899f
|
@ -0,0 +1,9 @@
|
|||
testgo: goimports
|
||||
# GO111MODULE=off go run aistudio.go
|
||||
go run -v aistudio.go
|
||||
|
||||
vet:
|
||||
GO111MODULE=off go vet
|
||||
|
||||
goimports:
|
||||
goimports -w *.go
|
|
@ -0,0 +1,60 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/google/generative-ai-go/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/"),
|
||||
},
|
||||
}
|
||||
|
||||
// Create user content
|
||||
userContent := &genai.Content{
|
||||
Parts: []genai.Part{
|
||||
genai.Text("what is the current version of forge on the webpage?"),
|
||||
},
|
||||
}
|
||||
|
||||
// Stream content generation
|
||||
iter := model.GenerateContentStream(ctx, []*genai.Content{userContent}...)
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue