fredsa / hello-gemini-vertex-ai-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello, Gemini using Vertex AI API.

Sample app showing how to access Gemini using the Vertex AI API.

Prerequisites

  1. Download and install Go, see https://go.dev/. To determine the version of Go that is available on your path run:

    go version
  2. [Optional] Install gcloud CLI, see https://cloud.google.com/sdk/docs/install.

Prepare sample project

  1. Clone this repo.

    git clone git@github.com:fredsa/hello-gemini-vertex-ai-api.git
  2. Change into the project directory.

    cd hello-gemini-vertex-ai-api
  3. Install the cloud.google.com/go/vertexai/genai package.

    go get cloud.google.com/go/vertexai/genai

Authorize the app

  1. 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 use option.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)

Run the sample

  1. 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.
    

About

License:Apache License 2.0


Languages

Language:Go 100.0%