vertex-ai

module
v0.0.0-...-a816ad1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2025 License: MIT

README

Google Vertex AI API Client

Prerequisites

Since the Vertex AI API does not allow API Keys, the API Client will automatically use the credentials from the environment to create an access token to be used in the request.

Access tokens are short-lived, so a new client should be created for each request.

Install
go get github.com/PixoVR/pixo-golang-clients/vertex-ai
Usage

Authenticate with user GCP credentials

gcloud auth application-default login
IAM
Example
package main

import (
	vertexai "github.com/PixoVR/pixo-golang-clients/vertex-ai/client"
	"log"
)

func main() {
	client, err := vertexai.NewClient(vertexai.ClientConfig{Debug: true})
	if err != nil {
		log.Printf("unable to create client client: %s", err.Error())
		return
	}

	// code model
	request := vertexai.ChatRequest{
		Debug:   true,
		ModelID: vertexai.BISON_CODE_MODEL_ID,
		Prompt:  "Who do most people consider to be the best basketball player of all time",
	}

	response, err := client.ChatResponse(request)
	if err != nil {
		log.Printf("unable to get client response: %s", err.Error())
	} else {
		log.Printf("Vertex Response: %s", response)
	}

	// text model
	request = vertexai.ChatRequest{
		Debug:   true,
		ModelID: vertexai.BISON_TEXT_MODEL_ID,
		Instances: []vertexai.Instance{
			{
				Content: "Who is the best basketball player of all time?",
			},
		},
	}

	response, err = client.ChatResponse(request)
	if err != nil {
		log.Printf("unable to get client response: %s", err.Error())
	} else {
		log.Printf("Vertex Response: %s", response)
	}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL