text

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ModelVersion = "text-bison@001"

ModelVersion is the currently used model version for text generation used by the prediction API calls.

Variables

View Source
var DefaultParameters = Parameters{
	Temperature:    0.2,
	TopP:           0.8,
	TopK:           40,
	MaxTokens:      1024,
	CandidateCount: 1,
}

DefaultParameters are the parameters used by default in the Vertex Generative AI Studio.

View Source
var MoreCreative = Parameters{
	Temperature:    1.0,
	TopK:           40,
	TopP:           1.0,
	MaxTokens:      1024,
	CandidateCount: 1,
}

MoreCreative are suggested parameters to experiment with. According to the documentation, they may generate results that are more creative.

Warning: these are just suggestions and not a specific recommendation from Google. Addapt these to your use case.

View Source
var MoreDeterministic = Parameters{
	Temperature:    0.0,
	TopK:           1,
	TopP:           0.8,
	MaxTokens:      1024,
	CandidateCount: 1,
}

MoreDeterministic are suggested parameters to experiment with. According to the documentation, they may generate results that are more deterministic.

Warning: these are just suggestions and not a specific recommendation from Google. Addapt these to your use case.

Functions

This section is empty.

Types

type Citation added in v0.1.3

type Citation struct {
	StartIndex      int    `json:"startIndex,omitempty"`
	EndIndex        int    `json:"endIndex,omitempty"`
	URL             string `json:"url,omitempty"`
	Title           string `json:"title,omitempty"`
	License         string `json:"license,omitempty"`
	PublicationDate string `json:"publicationDate,omitempty"`
}

Citation describes a citation reference when the model detects that one is needed.

type CitationMetadata added in v0.1.3

type CitationMetadata struct {
	Citations []Citation `json:"citations,omitempty"`
}

CitationMetadata holds the list of citations if any.

type Parameters

type Parameters struct {
	Temperature    float64
	TopP           float64
	TopK           int
	MaxTokens      int
	CandidateCount int
}

Parameters are model parameters that can be used by the Generative AI models on Vertex AI.

type Prediction

type Prediction struct {
	Content          string           `json:"content"`
	CitationMetadata CitationMetadata `json:"citationMetadata,omitempty"`
	SafetyAttributes SafetyAttributes `json:"safetyAttributes,omitempty"`
}

Prediction represents the returned prediction content and metadata from the Generative AI model on Vertex AI.

type Response

type Response struct {
	Predictions []Prediction  `json:"predictions,omitempty"`
	Metadata    TokenMetadata `json:"tokenMetadata,omitempty"`
}

Response contains the returned response by the API call of a Generative AI model.

func (Response) String

func (r Response) String() string

type SafetyAttributes added in v0.1.3

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

SafetyAttributes holds the detailed information of safety attributes returned by the model, as part of the Responsible AI actions taken by Google to signal if the output is harmful.

type TextClient

type TextClient struct {
	// contains filtered or unexported fields
}

TextClient is a helper to setup a Generative AI client for text generation.

func NewClient

func NewClient(projectID string) *TextClient

NewClient initializes a new TextClient using the provided projectID.

func (*TextClient) Debug added in v0.1.4

func (t *TextClient) Debug(enable bool)

EnableDebug activates extra messages printed to stderr for debugging.

func (*TextClient) GenerateText

func (t *TextClient) GenerateText(ctx context.Context, promptContext, prompt string, params Parameters) (response *Response, err error)

GenerateText calls the Vertex AI text-bison model to generate a new text.

`promptContext` is used as a template for fmt.Sprintf togheter with `prompt`, allowing one to define the structured prompt only once. It can be an empty string, and if it has no '%s' formatting, it will be a prefix added before prompt.

`params` are the parameters that will be passed to the model, like the temperature, top-k or top-p. Note that the default struct values for them are not always what you want: it is a good idea to set all parameters explicitly.

The returned Response will contain the list of predictions as well as any metadata returned by the call.

type TokenCountMetadata

type TokenCountMetadata struct {
	TotalBillableCharacters int `json:"totalBillableCharacters"`
	TotalTokens             int `json:"totalTokens"`
}

TokenCountMetadata is a helper struct to encode the resulting metadata about billable characters and tokens in the API call.

type TokenMetadata

type TokenMetadata struct {
	InputTokenCount  TokenCountMetadata `json:"inputTokenCount"`
	OutputTokenCount TokenCountMetadata `json:"outputTokenCount"`
}

TokenMetadata is a helper struct to encode the resulting metadata about the input/output tokens. {"tokenMetadata":{"inputTokenCount":{"totalBillableCharacters":15,"totalTokens":5},"outputTokenCount":{"totalBillableCharacters":191,"totalTokens":52}}}

Jump to

Keyboard shortcuts

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