summaryrefslogtreecommitdiff
path: root/genai
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-04-12 08:51:39 -0500
committerJeff Carr <[email protected]>2025-04-12 08:51:39 -0500
commit1b0344899fd4794bd9417454e2d03fe2bcc98c24 (patch)
treea00ca0b77161d5e0bce08e8b401d465ca4195574 /genai
parent9ba90938751c5c50edbeedfdb6d0d4fe65f69fa3 (diff)
hmm
Diffstat (limited to 'genai')
-rw-r--r--genai/Makefile9
-rw-r--r--genai/aistudio.go60
2 files changed, 69 insertions, 0 deletions
diff --git a/genai/Makefile b/genai/Makefile
new file mode 100644
index 0000000..4ec151e
--- /dev/null
+++ b/genai/Makefile
@@ -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
diff --git a/genai/aistudio.go b/genai/aistudio.go
new file mode 100644
index 0000000..ab6ccf2
--- /dev/null
+++ b/genai/aistudio.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))
+ }
+ }
+ }
+ }
+ }
+}