Documentation ¶
Overview ¶
openai implements an API client for OpenAI https://platform.openai.com/docs/api-reference
Index ¶
- func OptOrganization(value string) client.ClientOpt
- type Callback
- type Client
- func (c *Client) Chat(ctx context.Context, messages []*schema.Message, opts ...Opt) ([]*schema.Content, error)
- func (c *Client) CreateEmbedding(ctx context.Context, content any, opts ...Opt) (schema.Embeddings, error)
- func (c *Client) CreateImages(ctx context.Context, prompt string, opts ...Opt) ([]*Image, error)
- func (c *Client) DeleteModel(model string) error
- func (c *Client) GetModel(model string) (schema.Model, error)
- func (c *Client) ListModels() ([]schema.Model, error)
- func (c *Client) Moderations(ctx context.Context, text []string, opts ...Opt) ([]Moderation, error)
- func (c *Client) TextToSpeech(ctx context.Context, w io.Writer, voice, text string, opts ...Opt) (int64, error)
- func (c *Client) Transcribe(ctx context.Context, r io.Reader, opts ...Opt) (*Transcription, error)
- func (c *Client) Translate(ctx context.Context, r io.Reader, opts ...Opt) (*Transcription, error)
- func (c *Client) WriteImage(w io.Writer, image *Image) (int, error)
- type Image
- type Moderation
- type Opt
- func OptCount(value int) Opt
- func OptFrequencyPenalty(value float32) Opt
- func OptLanguage(value string) Opt
- func OptMaxTokens(value int) Opt
- func OptModel(value string) Opt
- func OptPresencePenalty(value float32) Opt
- func OptPrompt(value string) Opt
- func OptQuality(value string) Opt
- func OptResponseFormat(value string) Opt
- func OptSeed(value int) Opt
- func OptSize(value string) Opt
- func OptSpeed(v float32) Opt
- func OptStop(value ...string) Opt
- func OptStream(fn Callback) Opt
- func OptStyle(value string) Opt
- func OptTemperature(v float32) Opt
- func OptTool(value ...*schema.Tool) Opt
- func OptUser(value string) Opt
- type Transcription
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 Callback ¶ added in v1.0.5
type Callback func(schema.MessageChoice)
Callback when new stream data is received
type Client ¶
type Client struct {
*client.Client
}
func (*Client) Chat ¶
func (c *Client) Chat(ctx context.Context, messages []*schema.Message, opts ...Opt) ([]*schema.Content, error)
Chat creates a model response for the given chat conversation.
func (*Client) CreateEmbedding ¶
func (c *Client) CreateEmbedding(ctx context.Context, content any, opts ...Opt) (schema.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
func (*Client) Moderations ¶ added in v1.0.4
Classifies if text is potentially harmful
func (*Client) TextToSpeech ¶ added in v1.0.4
func (c *Client) TextToSpeech(ctx context.Context, w io.Writer, voice, text string, opts ...Opt) (int64, error)
Creates audio for the given text, outputs to the writer and returns the number of bytes written
func (*Client) Transcribe ¶ added in v0.0.3
Transcribes audio from audio data
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 Moderation ¶ added in v1.0.4
type Moderation struct { Flagged bool `json:"flagged"` Categories struct { Sexual bool `json:"sexual,omitempty"` Hate bool `json:"hate,omitempty"` Harassment bool `json:"harassment,omitempty"` SelfHarm bool `json:"self-harm,omitempty"` SexualMinors bool `json:"sexual/minors,omitempty"` HateThreatening bool `json:"hate/threatening,omitempty"` ViolenceGraphic bool `json:"violence/graphic,omitempty"` SelfHarmIntent bool `json:"self-harm/intent,omitempty"` HarasssmentThreatening bool `json:"harassment/threatening,omitempty"` Violence bool `json:"violence,omitempty"` } `json:"categories,omitempty" writer:",wrap"` CategoryScores struct { Sexual float32 `json:"sexual,omitempty"` Hate float32 `json:"hate,omitempty"` Harassment float32 `json:"harassment,omitempty"` SelfHarm float32 `json:"self-harm,omitempty"` SexualMinors float32 `json:"sexual/minors,omitempty"` HateThreatening float32 `json:"hate/threatening,omitempty"` ViolenceGraphic float32 `json:"violence/graphic,omitempty"` SelfHarmIntent float32 `json:"self-harm/intent,omitempty"` HarasssmentThreatening float32 `json:"harassment/threatening,omitempty"` Violence float32 `json:"violence,omitempty"` } `json:"category_scores,omitempty" writer:",wrap"` }
Moderation represents the moderation of a text, including whether it is flagged
type Opt ¶
type Opt func(*options) error
Opt is a function which can be used to set options on a request
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 OptLanguage ¶ added in v0.0.3
The language of the input audio. Supplying the input language in ISO-639-1 format will improve accuracy and latency.
func OptMaxTokens ¶
Maximum number of tokens to generate in the reply
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 OptPrompt ¶ added in v0.0.3
An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.
func OptQuality ¶
The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image.
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 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.
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 Transcription ¶ added in v0.0.3
type Transcription struct { Task string `json:"task,omitempty"` Language string `json:"language,omitempty"` // The language of the input audio. Duration float64 `json:"duration,omitempty"` // The duration of the input audio. Text string `json:"text" writer:",wrap,width:40"` Words []struct { Word string `json:"word"` // The text content of the word. Start float64 `json:"start"` // Start time of the word in seconds. End float64 `json:"end"` // End time of the word in seconds. } `json:"words,omitempty"` // Extracted words and their corresponding timestamps. Segments []struct { Id uint `json:"id"` Seek uint `json:"seek"` Start float64 `json:"start"` End float64 `json:"end"` Text string `json:"text"` Tokens []uint `json:"tokens"` // Array of token IDs for the text content. Temperature float64 `json:"temperature,omitempty"` // Temperature parameter used for generating the segment. AvgLogProbability float64 `json:"avg_logprob,omitempty"` // Average logprob of the segment. If the value is lower than -1, consider the logprobs failed. CompressionRatio float64 `json:"compression_ratio,omitempty"` // Compression ratio of the segment. If the value is greater than 2.4, consider the compression failed. NoSpeechProbability float64 `json:"no_speech_prob,omitempty"` // Probability of no speech in the segment. If the value is higher than 1.0 and the avg_logprob is below -1, consider this segment silent. } `json:"segments,omitempty" writer:",wrap"` }
Represents a transcription response returned by model, based on the provided input.