vertexai

package module
v0.0.0-...-d423e00 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Go Vertex AI

A Go Library for Google's Large Language Models on Vertex AI Platform

Google launched its latest Large Language Model(LLM) - PaLM 2, at Google I/O 2023. PaLM 2 powers Google's Bard chat tool, its competitor to OpenAI's ChatGPT. PaLM 2 is available to developers through Google's Vertex AI Platform. Their platform lets developers test, customize, and deploy instances of Google's PaLM2 LLMs.

Uber started using Google's PaLM2 LLM and realized that Google doesn't provide a Go library to access the LLM. After searching for a Go implementation, we found no good choices. So we built our own and are releasing it for everyone else to use.

We built this library to connect our Go Applications with Google's LLMs and supports only the features that we needed - Text Generation Multi-Turn Chat Generation Text Embedding

Usage

  1. Download the library
go get github.com/uber/go-vertex-ai
  1. Import the library into your project
import vertexai "github.com/uber/go-vertex-ai"
  1. Call the library functions
  client, err := vertexai.New(key) // key of your project from Google Cloud Console

	resp, err := client.TextGeneration(context.Background(), vertexai.TextGenerationRequest{
		ProjectID:      examples.ProjectID,
		EndpointID:     "text-bison@001",
		Content:        "Hello, Google! What can you do?",
	})

Methods we implemented

TextGeneration

Documentation | Code

text-bison is the name of the PaLM 2 for text large language model that understands and generates language. It is fine-tuned to follow natural language instructions and is suitable for various language tasks, such as classification, extraction, summarization, and content generation.

ChatGeneration

Documentation | Code

chat-bison is a large language model that excels at language understanding, generation, and conversations. This chat model is fine-tuned to conduct natural multi-turn conversations. The PaLM 2 for chat is ideal for text tasks that require back-and-forth interactions. For text tasks that can be completed with one API response (without the need for continuous conversation), use the PaLM 2 for text.

TextEmbedding

Documentation | Code

Text embedding is an NLP technique that converts textual data into numerical vectors that can be processed by machine learning algorithms, especially large models. These vector representations are designed to capture the semantic meaning and context of the words they represent.

Running Examples from Library

  1. Download a Key for your Google Cloud Project and enable Vertex AI product for your project at Google Cloud Console
  2. Paste the absolute path of the key file (downloaded above) in (constants.go)[./examples/constants.go] file
  3. Replace your Google Project ID in (constants.go)[./examples/constants.go] file
TextGeneration
go run ./examples/text-generation/text_generation.go
ChatGeneration
go run ./examples/chat-generation/chat_generation.go
TextEmbedding
go run ./examples/text-embedding/text_embedding.go

Contributing

To propose a new feature or report a bug, please open an issue with the tag #FeatureRequest or #Bug.

For Pull Requests: please raise an issue before submitting a PR to discuss your proposed changes and check with the team. Then assign the issue to yourself and create a pull request. The team reviews PRs every three weeks, but holidays or work schedules may delay us occasionally.

License

Vertex AI for GO is copyright 2023 by Uber Technologies, Inc, licensed under the Apache 2.0 license. See the LICENSE and NOTICE files for more information.

Documentation

Index

Constants

View Source
const (
	TextBison    string = "text-bison"
	TextBison001 string = "text-bison@001"
	CodeBison001 string = "code-bison@001" // Code Generation
	CodeGecko001 string = "code-gecko@001" // Code Completion
)

standard models supported by TextGeneration endpoint

View Source
const (
	ChatBison        string = "chat-bison"
	ChatBison001     string = "chat-bison@001"
	CodeChatBison001 string = "codechat-bison@001" // Code Generation
)

standard models supported by ChatGeneration endpoint

View Source
const (
	TextEmbeddingGecko001 string = "textembedding-gecko@001"
)

standard models supported by TextEmbedding endpoint

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatGenerationRequest

type ChatGenerationRequest struct {
	ProjectID      string
	EndpointID     string
	Context        string
	ChatMessages   []ChatMessage
	Examples       []Example
	Temperature    *float64
	MaxDecodeSteps *int
	TopK           *int
	TopP           *float64
}

ChatGenerationRequest is the request for the ChatGeneration method

type ChatGenerationResponse

type ChatGenerationResponse struct {
	ChatPredictions  []ChatPrediction `json:"predictions"`
	DeployedModelID  string           `json:"deployedModelId"`
	Model            string           `json:"model"`
	ModelDisplayName string           `json:"modelDisplayName"`
	ModelVersionID   string           `json:"modelVersionId"`
}

ChatGenerationResponse is the response for the ChatGeneration method

type ChatMessage

type ChatMessage struct {
	Author  string `json:"author"`
	Content string `json:"content"`
}

ChatMessage is a chat prompt

type ChatPrediction

type ChatPrediction struct {
	ChatMessages     []ChatMessage      `json:"candidates"`
	SafetyAttributes []SafetyAttributes `json:"safetyAttributes"`
}

ChatPrediction is the generated response

type Client

type Client interface {
	TextGeneration(ctx context.Context, req TextGenerationRequest) (*TextGenerationResponse, error)
	ChatGeneration(ctx context.Context, req ChatGenerationRequest) (*ChatGenerationResponse, error)
	TextEmbedding(ctx context.Context, req TextEmbeddingRequest) (*TextEmbeddingResponse, error)
}

Client is the interface for the Vertex AI client for PaLM

func New

func New(key string) (Client, error)

New creates a new client for the Vertex AI client for PaLM key is the oauth key of the Google Service account for authentication

type Embedding

type Embedding struct {
	Values     []float64      `json:"values"`
	Statistics EmbeddingStats `json:"statistics"`
}

Embedding is the embedding for text

type EmbeddingStats

type EmbeddingStats struct {
	TokenCount int  `json:"token_count"`
	Truncated  bool `json:"truncated"`
}

EmbeddingStats define the statistics for a text embedding

type Example

type Example struct {
	Input  ChatMessage `json:"input"`
	Output ChatMessage `json:"output"`
}

Example represents a example passed for few shot learning in multi turn chat conversations

type Predictions

type Predictions struct {
	Embedding Embedding `json:"embeddings"`
}

Predictions is the generated response

type SafetyAttributes

type SafetyAttributes struct {
	Blocked    bool      `json:"blocked"`
	Scores     []float64 `json:"scores"`
	Categories []string  `json:"categories"`
}

SafetyAttributes is the safety attributes for a prediction

type TextCandidate

type TextCandidate struct {
	Content          string           `json:"content"`
	SafetyAttributes SafetyAttributes `json:"safetyAttributes"`
}

TextCandidate is the generated response

type TextEmbeddingRequest

type TextEmbeddingRequest struct {
	ProjectID  string
	EndpointID string
	/*
		Content is Deprecated. Use Inputs instead
	*/
	Content string
	Inputs  []string
}

TextEmbeddingRequest is the request for the TextEmbedding method

type TextEmbeddingResponse

type TextEmbeddingResponse struct {
	Predictions []Predictions `json:"predictions"`
}

TextEmbeddingResponse is the response for the TextEmbedding method

type TextGenerationRequest

type TextGenerationRequest struct {
	ProjectID      string
	EndpointID     string
	Content        string
	Temperature    *float64
	MaxDecodeSteps *int
	TopK           *int
	TopP           *float64
}

TextGenerationRequest is the request for the TextGeneration method

type TextGenerationResponse

type TextGenerationResponse struct {
	Candidates       []TextCandidate `json:"predictions"`
	DeployedModelID  string          `json:"deployedModelId"`
	Model            string          `json:"model"`
	ModelDisplayName string          `json:"modelDisplayName"`
	ModelVersionID   string          `json:"modelVersionId"`
}

TextGenerationResponse is the response for the TextGeneration method

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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