Documentation
¶
Overview ¶
openai implements an API client for OpenAI https://platform.openai.com/docs/api-reference
Index ¶
- func OptOrganization(value string) client.ClientOpt
- type Chat
- type Client
- func (c *Client) Chat(messages []*Message, opts ...Opt) (Chat, error)
- func (c *Client) CreateEmbedding(content any, opts ...Opt) (Embeddings, error)
- func (c *Client) CreateImages(prompt string, opts ...Opt) ([]*Image, error)
- func (c *Client) DeleteModel(model string) error
- func (c *Client) GetModel(model string) (Model, error)
- func (c *Client) ListModels() ([]Model, error)
- func (c *Client) WriteImage(w io.Writer, image *Image) (int, error)
- type Embedding
- type Embeddings
- type Image
- type Message
- type MessageChoice
- type MessageContent
- type MessageContentArray
- type MessageContentImageFile
- type MessageContentImageUrl
- type Model
- type Opt
- func OptCount(value int) Opt
- func OptFrequencyPenalty(value float64) Opt
- func OptFunction(name, description string, parameters ...ToolParameter) Opt
- func OptMaxTokens(value int) Opt
- func OptModel(value string) Opt
- func OptPresencePenalty(value float64) Opt
- func OptQuality(value string) Opt
- func OptResponseFormat(value string) Opt
- func OptSeed(value int) Opt
- func OptSize(w, h uint) Opt
- func OptStream(value bool) Opt
- func OptStyle(style string) Opt
- func OptTemperature(value float64) Opt
- type Request
- type Tool
- type ToolFunction
- type ToolParameter
- type ToolParameters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OptOrganization ¶
Set an organization where the user has access to multiple organizations
Types ¶
type Chat ¶
type Chat struct {
Id string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
SystemFingerprint string `json:"system_fingerprint,omitempty"`
Choices []*MessageChoice `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
A chat completion object
type Client ¶
func (*Client) CreateEmbedding ¶
func (c *Client) CreateEmbedding(content any, opts ...Opt) (Embeddings, error)
CreateEmbedding creates an embedding from a string or array of strings
func (*Client) CreateImages ¶
CreateImage generates one or more images from a prompt
func (*Client) DeleteModel ¶
Delete a fine-tuned model. You must have the Owner role in your organization to delete a model.
func (*Client) ListModels ¶
ListModels returns all the models
type Embeddings ¶
type Embeddings struct {
Data []Embedding `json:"data"`
Model string `json:"model"`
Usage struct {
PromptTokerns int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
An set of created embeddings
type Image ¶
type Image struct {
Url string `json:"url,omitempty"`
Data string `json:"b64_json,omitempty"`
RevisedPrompt string `json:"revised_prompt,omitempty"`
}
An image
type Message ¶
type Message struct {
Role string `json:"role"`
Content MessageContentArray `json:"content,omitempty"`
Name string `json:"name,omitempty"`
ToolCalls []struct {
Id string `json:"id"`
Type string `json:"type"`
Function struct {
Name string `json:"name"`
Arguments string `json:"arguments"`
} `json:"function"`
} `json:"tool_calls,omitempty"`
ToolCallId string `json:"tool_call_id,omitempty"`
}
A message choice object
func NewMessage ¶
func (*Message) AppendImageFile ¶
func (*Message) AppendImageUrl ¶
func (*Message) AppendText ¶
type MessageChoice ¶
type MessageChoice struct {
Index int `json:"index"`
FinishReason string `json:"finish_reason,omitempty"`
Message *Message `json:"message,omitempty"`
}
A message choice object
type MessageContent ¶
type MessageContent struct {
Type string `json:"type"`
Text *string `json:"text,omitempty"`
ImageFile *MessageContentImageFile `json:"image_file,omitempty"`
ImageUrl *MessageContentImageUrl `json:"image_url,omitempty"`
}
Message content
type MessageContentArray ¶
type MessageContentArray []MessageContent
A message content array
func (MessageContentArray) Flatten ¶
func (arr MessageContentArray) Flatten() string
Return the text of the message
func (*MessageContentArray) UnmarshalJSON ¶
func (c *MessageContentArray) UnmarshalJSON(data []byte) error
type MessageContentImageFile ¶
type MessageContentImageFile struct {
File string `json:"file_id"`
}
Message content image file
type MessageContentImageUrl ¶
type MessageContentImageUrl struct {
Url string `json:"url"`
}
Message content image url
type Model ¶
type Model struct {
Id string `json:"id"`
Created int64 `json:"created"`
Owner string `json:"owned_by"`
}
A model object
type Opt ¶
type ChatCompletionOpt func(*chatRequest) error type ImageOpt func(*imageRequest) error
func OptFrequencyPenalty ¶
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
func OptFunction ¶
func OptFunction(name, description string, parameters ...ToolParameter) Opt
When set, system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.
func OptMaxTokens ¶
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
func OptPresencePenalty ¶
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
func OptQuality ¶
The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image. This param is only supported for dall-e-3.
func OptResponseFormat ¶
Format of the returned response, use "json_format" to enable JSON mode, which guarantees the message the model generates is valid JSON. Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message.
func OptSeed ¶
When set, system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.
func OptSize ¶
The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2. Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models.
func OptStream ¶
Partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE]
func OptStyle ¶
The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3.
func OptTemperature ¶
When set, system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.
type Request ¶
type Request interface {
// contains filtered or unexported methods
}
An abstract request object
type Tool ¶
type Tool struct {
Type string `json:"type"`
Function *ToolFunction `json:"function,omitempty"`
}
A tool
type ToolFunction ¶
type ToolFunction struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters *ToolParameters `json:"parameters"`
}
A tool function
type ToolParameter ¶
type ToolParameter struct {
Name string `json:"-"`
Type string `json:"type"`
Enum []string `json:"enum,omitempty"`
Description string `json:"description"`
Required bool `json:"-"`
}
Tool function call parameter
type ToolParameters ¶
type ToolParameters struct {
Type string `json:"type"`
Properties map[string]ToolParameter `json:"properties"`
Required []string `json:"required"`
}
Tool function parameters