Sample app showing how to access Gemini using the Vertex AI API.
-
Download and install Go, see https://go.dev/. To determine the version of Go that is available on your path run:
go version
-
[Optional] Install
gcloud
CLI, see https://cloud.google.com/sdk/docs/install.
-
Clone this repo.
git clone git@github.com:fredsa/hello-gemini-vertex-ai-api.git
-
Change into the project directory.
cd hello-gemini-vertex-ai-api
-
Install the
cloud.google.com/go/vertexai/genai
package.go get cloud.google.com/go/vertexai/genai
-
To use Application Default Credentials to authorize the app, run the following
gcloud
command:gcloud auth application-default login
Alternatively, you can authorize the app using an API key by modifying
main.go
to useoption.WithAPIKey
when creating the client:// New client, authorize using an API KEY. option := option.WithAPIKey("YOUR_API_KEY") client, err := genai.NewClient(ctx, project, location, option)
-
Compile and run.
go run main.go
The output should look something like this
>> Hello, who are you? I am a large language model, trained by Google.