Registry / cloud / google-generative-ai-go

google-generative-ai-go

JSON →
library0.20.1gogounverified

Go client library for Google's Generative AI models, including Gemini.

go get github.com/google/generative-ai-go
INSTALL
IMPORT
SIG · GOOGLE-GENERATIVE-
G
google-generative-ai-go
cloudgov0.20.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generativeai
github.com/google/generative-ai-go

Initializes a Gemini client and generates content from a prompt.

package main import ( "context" "fmt" "log" "github.com/google/generative-ai-go/genai" "google.golang.org/api/option" ) func main() { ctx := context.Background() client, err := genai.NewClient(ctx, option.WithAPIKey("YOUR_API_KEY")) if err != nil { log.Fatal(err) } defer client.Close() model := client.GenerativeModel("gemini-pro") resp, err := model.GenerateContent(ctx, genai.Text("Hello")) if err != nil { log.Fatal(err) } fmt.Println(resp.Candidates[0].Content.Parts[0]) }
Debug
Known issues
gotchaRequires a valid Google Cloud API key or service account credentials.
fix
Set the GOOGLE_API_KEY environment variable or pass credentials via option.WithAPIKey.
affects: all
Upgrade
Version history
0.20.1latest on pkg.go.dev
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
2
Resources
google-generative-ai-go — go get google-generative-ai-go · libregistry