Documentation ¶
Overview ¶
Package ai21 provides a client for interacting with the ai21 text completion API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SupportedModels = []string{"j2-light", "j2-mid", "j2-ultra"}
SupportedModels is a list of supported AI21 models.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for interacting with the ai21 API.
func (*Client) CreateCompletion ¶
func (c *Client) CreateCompletion(ctx context.Context, model string, req *CompleteRequest) (*CompleteResponse, error)
CreateCompletion sends a text completion request to the ai21 API and returns the response.
type CompleteRequest ¶
type CompleteRequest struct { Prompt string `json:"prompt"` NumResults int `json:"numResults,omitempty"` MaxTokens int `json:"maxTokens,omitempty"` MinTokens int `json:"minTokens,omitempty"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"topP,omitempty"` StopSequences []string `json:"stopSequences,omitempty"` TopKReturn int `json:"topKReturn,omitempty"` FrequencyPenalty Penalty `json:"frequencyPenalty,omitempty"` PresencePenalty Penalty `json:"presencePenalty,omitempty"` CountPenalty Penalty `json:"countPenalty,omitempty"` }
CompleteRequest represents a request for text completion.
type CompleteResponse ¶
type CompleteResponse struct { ID string `json:"id"` Prompt Prompt `json:"prompt"` Completions []Completion `json:"completions"` }
CompleteResponse represents the response from a text completion request.
type Completion ¶
type Completion struct { Data Data `json:"data"` FinishReason FinishReason `json:"finishReason"` }
Completion represents a completion result.
type FinishReason ¶
FinishReason represents the reason and length for completion finishing.
type GeneratedToken ¶
type GeneratedToken struct { Token string `json:"token"` Logprob float64 `json:"logprob"` RawLogprob float64 `json:"raw_logprob"` }
GeneratedToken represents a generated token with log probabilities.
type HTTPClient ¶
HTTPClient is an interface for making HTTP requests.
type Options ¶
type Options struct { // The base URL of the ai21 API. APIUrl string // The HTTP client to use for making API requests. HTTPClient HTTPClient }
Options represents configuration options for the ai21 client.
type Penalty ¶
type Penalty struct { Scale int `json:"scale"` ApplyToNumbers bool `json:"applyToNumbers"` ApplyToPunctuations bool `json:"applyToPunctuations"` ApplyToStopwords bool `json:"applyToStopwords"` ApplyToWhitespaces bool `json:"applyToWhitespaces"` ApplyToEmojis bool `json:"applyToEmojis"` }
Penalty represents penalty options for text completion.
type Tokens ¶
type Tokens struct { GeneratedToken GeneratedToken `json:"generatedToken"` TopTokens interface{} `json:"topTokens"` TextRange TextRange `json:"textRange"` }
Tokens represents generated tokens and top tokens.