Documentation
¶
Index ¶
- Constants
- Variables
- type AudioTranscriptionRequest
- type AudioTranscriptionResponse
- type AudioTranslationRequest
- type AudioTranslationResponse
- type ChatCompletionChoices
- type ChatCompletionMessage
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionUsage
- type Client
- func (c *Client) APIKey() string
- func (c *Client) AudioTranscription(r *AudioTranscriptionRequest) (*AudioTranscriptionResponse, error)
- func (c *Client) AudioTranslation(r *AudioTranslationRequest) (*AudioTranslationResponse, error)
- func (c *Client) ChatCompletion(r *ChatCompletionRequest) (*ChatCompletionResponse, error)
- func (c *Client) Completion(r *CompletionRequest) (*CompletionResponse, error)
- func (c *Client) Configure(config *Config)
- func (c *Client) Context() context.Context
- func (c *Client) Edit(r *EditRequest) (*EditResponse, error)
- func (c *Client) Embedding(r *EmbeddingRequest) (*EmbeddingResponse, error)
- func (c *Client) Endpoint(p ...string) string
- func (c *Client) Error() error
- func (c *Client) FileContent(file string) (string, error)
- func (c *Client) FileDelete(file string) (*FileDeleteResponse, error)
- func (c *Client) FileUpload(r *FileUploadRequest) (*FileUploadResponse, error)
- func (c *Client) Files(files ...string) (FilesData, error)
- func (c *Client) FineTune(r *FineTuneRequest) (*FineTuneResponse, error)
- func (c *Client) FineTuneCancel(fineTune string) (*FineTuneResponse, error)
- func (c *Client) FineTuneEvents(fineTune string) (FineTuneEventsData, error)
- func (c *Client) FineTunes(fineTunes ...string) (FineTunesData, error)
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) HTTPHeaders() http.Header
- func (c *Client) ImageEdit(r *ImageEditRequest) (*ImageEditResponse, error)
- func (c *Client) ImageGeneration(r *ImageGenerationRequest) (*ImageGenerationResponse, error)
- func (c *Client) ImageVariation(r *ImageVariationRequest) (*ImageVariationResponse, error)
- func (c *Client) ModelDelete(model string) (*ModelDeleteResponse, error)
- func (c *Client) Models(models ...string) (ModelsData, error)
- func (c *Client) Moderation(r *ModerationRequest) (*ModerationResponse, error)
- func (c *Client) OrgID() string
- func (c *Client) ParallelTasks() int
- type Clienter
- type CompletionChoice
- type CompletionRequest
- type CompletionResponse
- type CompletionUsage
- type Config
- type EditChoice
- type EditRequest
- type EditResponse
- type EditUsage
- type Embedding
- type EmbeddingRequest
- type EmbeddingResponse
- type EmbeddingUsage
- type Error
- type ErrorResponse
- type FileDeleteResponse
- type FileDetails
- type FileResponse
- type FileUploadRequest
- type FileUploadResponse
- type FilesData
- type FineTuneEvent
- type FineTuneEventListResponse
- type FineTuneEventsData
- type FineTuneListResponse
- type FineTuneRequest
- type FineTuneResponse
- type FineTunesData
- type Hyperparameters
- type ImageEditData
- type ImageEditRequest
- type ImageEditResponse
- type ImageGenerationData
- type ImageGenerationRequest
- type ImageGenerationResponse
- type ImageVariationData
- type ImageVariationRequest
- type ImageVariationResponse
- type ModelDeleteResponse
- type ModelDetails
- type ModelPermission
- type ModelResponse
- type ModelsData
- type ModerationRequest
- type ModerationResponse
- type ModerationResult
- type Requester
- type TrainingFile
Constants ¶
const DefaultRole = "user"
Variables ¶
var ( ErrNoAPIKey = errors.New("no API key") ErrNoAPIBaseURL = errors.New("no API base URL") ErrNoHTTPClient = errors.New("no HTTP client") ErrNoContext = errors.New("no context") ErrRequestTimedOut = errors.New("request timed out") ErrPromptRequired = errors.New("prompt is required") ErrMessageRequired = errors.New("message is required") ErrInputRequired = errors.New("input is required") ErrModelRequired = errors.New("model is required") ErrImageRequired = errors.New("image is required") ErrInvalidResponseFormat = errors.New("invalid response format") ErrInvalidSize = errors.New("invalid size") ErrInvalidRole = errors.New("invalid role") ErrInstructionRequired = errors.New("instruction is required") ErrFileRequired = errors.New("file is required") ErrPurposeRequired = errors.New("purpose is required") )
Functions ¶
This section is empty.
Types ¶
type AudioTranscriptionRequest ¶
type AudioTranscriptionRequest struct { // The audio file to transcribe, in one of the following formats: // mp3, mp4, mpeg, mpga, m4a, wav, or webm. This is required. File *os.File `json:"file"` // The model ID to use for the request. Model string `json:"model"` // An optional text to guide the model's style or continue a previous // audio segment. The prompt should match the audio language. Prompt string `json:"prompt,omitempty"` // The format of the transcript output. Options include: json, text, srt, // verbose_json, or vtt. Defaults to json if not specified. ResponseFormat string `json:"response_format,omitempty"` // The sampling temperature, between 0 and 1. Higher values like 0.8 // will make the output more random, while lower values like 0.2 will // make it more focused and deterministic. If set to 0, the model will // use log probability to automatically increase the temperature until // certain thresholds are hit. Temperature float64 `json:"temperature,omitempty"` // The language of the input audio. Supplying the input language // in ISO-639-1 format will improve accuracy and latency. Language string `json:"language,omitempty"` }
AudioTranscriptionRequest represents a request to the OpenAI Transcription API.
func (*AudioTranscriptionRequest) CloseAudioFile ¶
func (r *AudioTranscriptionRequest) CloseAudioFile()
CloseAudioFile closes the audio file associated with the request.
func (*AudioTranscriptionRequest) Error ¶
func (r *AudioTranscriptionRequest) Error() error
Error returns an error if the request is invalid.
func (*AudioTranscriptionRequest) Flush ¶
func (r *AudioTranscriptionRequest) Flush()
Flush closes the files descriptors associated with the request.
func (*AudioTranscriptionRequest) OpenAudioFile ¶
func (r *AudioTranscriptionRequest) OpenAudioFile(path string) error
OpenAudioFile reads an audio file from the provided path and assigns the *os.File value to the File field of the request.
type AudioTranscriptionResponse ¶
type AudioTranscriptionResponse struct { // The text transcription of the audio file. Text string `json:"text"` }
AudioTranscriptionResponse represents a response from the OpenAI Transcription API.
type AudioTranslationRequest ¶
type AudioTranslationRequest struct { // The audio file to translate, in one of these formats: mp3, mp4, // mpeg, mpga, m4a, wav, or webm. This is required. File *os.File `json:"file"` // The model ID to use for the request. Only whisper-1 is currently // available. This is required. Model string `json:"model"` // An optional text to guide the model's style or continue a previous // audio segment. The prompt should be in English. Prompt string `json:"prompt,omitempty"` // The format of the transcript output. Options include: json, text, // srt, verbose_json, or vtt. Defaults to json if not specified. ResponseFormat string `json:"response_format,omitempty"` // The sampling temperature, between 0 and 1. Higher values like 0.8 // will make the output more random, while lower values like 0.2 will // make it more focused and deterministic. If set to 0, the model will // use log probability to automatically increase the temperature until // certain thresholds are hit. Temperature float64 `json:"temperature,omitempty"` }
AudioTranslationRequest represents a request to the OpenAI Translation API.
func (*AudioTranslationRequest) CloseAudioFile ¶
func (r *AudioTranslationRequest) CloseAudioFile()
CloseAudioFile closes the audio file associated with the request.
func (*AudioTranslationRequest) Error ¶
func (r *AudioTranslationRequest) Error() error
Error returns an error if the request is invalid.
func (*AudioTranslationRequest) Flush ¶
func (r *AudioTranslationRequest) Flush()
Flush closes the files descriptors associated with the request.
func (*AudioTranslationRequest) OpenAudioFile ¶
func (r *AudioTranslationRequest) OpenAudioFile(path string) error
OpenAudioFile reads an audio file from the provided path and assigns the *os.File value to the File field of the request.
type AudioTranslationResponse ¶
type AudioTranslationResponse struct { // The translated text. Text string `json:"text"` }
AudioTranslationResponse represents the response from the OpenAI Translation API.
type ChatCompletionChoices ¶
type ChatCompletionChoices struct { Index int `json:"index"` Message ChatCompletionMessage `json:"message"` FinishReason string `json:"finish_reason"` }
type ChatCompletionMessage ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct { Messages []ChatCompletionMessage `json:"messages"` Model string `json:"model"` MaxTokens int `json:"max_tokens,omitempty"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` PresencePenalty float64 `json:"presence_penalty,omitempty"` LogitBias map[string]float64 `json:"logit_bias,omitempty"` }
ChatCompletionRequest is the request to the completions API.
func (*ChatCompletionRequest) Error ¶
func (r *ChatCompletionRequest) Error() error
Error returns an error if the request is invalid.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Choices []ChatCompletionChoices `json:"choices"` Usage ChatCompletionUsage `json:"usage"` }
func (*ChatCompletionResponse) Text ¶
func (r *ChatCompletionResponse) Text() string
Text returns the text of the first choice.
type ChatCompletionUsage ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the OpenAI API client.
The client has the same fields as the config, but we don't imitate Config because we store private fields, we also don't make a pointer to Config so that it is not possible to change the behavior of the Client by changing the original Config. The Config fields are copied to the Client settings, and some empty fields can take default values.
func (*Client) AudioTranscription ¶
func (c *Client) AudioTranscription( r *AudioTranscriptionRequest, ) (*AudioTranscriptionResponse, error)
func (*Client) AudioTranslation ¶
func (c *Client) AudioTranslation( r *AudioTranslationRequest, ) (*AudioTranslationResponse, error)
func (*Client) ChatCompletion ¶
func (c *Client) ChatCompletion( r *ChatCompletionRequest, ) (*ChatCompletionResponse, error)
func (*Client) Completion ¶
func (c *Client) Completion( r *CompletionRequest, ) (*CompletionResponse, error)
Completion returns a list of completions.
func (*Client) Edit ¶
func (c *Client) Edit( r *EditRequest, ) (*EditResponse, error)
func (*Client) Embedding ¶
func (c *Client) Embedding( r *EmbeddingRequest, ) (*EmbeddingResponse, error)
func (*Client) FileDelete ¶
func (c *Client) FileDelete(file string) (*FileDeleteResponse, error)
FileDelete removes a file.
func (*Client) FileUpload ¶
func (c *Client) FileUpload( r *FileUploadRequest, ) (*FileUploadResponse, error)
func (*Client) FineTune ¶
func (c *Client) FineTune( r *FineTuneRequest, ) (*FineTuneResponse, error)
func (*Client) FineTuneCancel ¶
func (c *Client) FineTuneCancel(fineTune string) (*FineTuneResponse, error)
func (*Client) FineTuneEvents ¶
func (c *Client) FineTuneEvents(fineTune string) (FineTuneEventsData, error)
func (*Client) HTTPClient ¶
func (*Client) HTTPHeaders ¶
func (*Client) ImageEdit ¶
func (c *Client) ImageEdit( r *ImageEditRequest, ) (*ImageEditResponse, error)
func (*Client) ImageGeneration ¶
func (c *Client) ImageGeneration( r *ImageGenerationRequest, ) (*ImageGenerationResponse, error)
func (*Client) ImageVariation ¶
func (c *Client) ImageVariation( r *ImageVariationRequest, ) (*ImageVariationResponse, error)
func (*Client) ModelDelete ¶
func (c *Client) ModelDelete(model string) (*ModelDeleteResponse, error)
ModelDelete removes a model.
func (*Client) Moderation ¶
func (c *Client) Moderation( r *ModerationRequest, ) (*ModerationResponse, error)
func (*Client) ParallelTasks ¶
type CompletionChoice ¶
type CompletionChoice struct { Text string `json:"text"` Index int `json:"index"` Logprobs *int `json:"logprobs"` // can be null FinishReason string `json:"finish_reason"` }
CompletionChoice is a single completion choice.
type CompletionRequest ¶
type CompletionRequest struct { // The prompt(s) to generate completions for, encoded as a string, // array of strings, array of tokens, or array of token arrays. Prompt interface{} `json:"prompt,omitempty"` // Model specifies the ID of the model to use for text generation. Model string `json:"model"` // Suffix specifies the text to attach at the end of the completion. Suffix string `json:"suffix,omitempty"` // MaxTokens controls the maximum number of tokens in the generated text. MaxTokens int `json:"max_tokens,omitempty"` // Temperature affects the randomness of the completion. Temperature float64 `json:"temperature,omitempty"` // TopP is used for nucleus sampling, influencing the randomness // by truncating the token distribution. TopP float64 `json:"top_p,omitempty"` // N specifies the number of completions to generate. N int `json:"n,omitempty"` // Stream, when true, returns the results as a stream. Stream bool `json:"stream,omitempty"` // Logprobs specifies the number of most probable tokens // to return with their probabilities. Logprobs int `json:"logprobs,omitempty"` // Echo, when true, repeats the prompt in the API response. Echo bool `json:"echo,omitempty"` // Stop defines the sequence where the API will stop // generating further tokens. Stop interface{} `json:"stop,omitempty"` // PresencePenalty penalizes new tokens based on // their existing presence in the text. PresencePenalty float64 `json:"presence_penalty,omitempty"` // FrequencyPenalty penalizes tokens based on their frequency in the text. FrequencyPenalty float64 `json:"frequency_penalty,omitempty"` // BestOf generates multiple completions and selects the best one. BestOf int `json:"best_of,omitempty"` // LogitBias allows modifying the likelihood of specified // tokens appearing in the completion. LogitBias map[string]float64 `json:"logit_bias,omitempty"` // User allows to specify a user ID for tracking purposes. User string `json:"user,omitempty"` }
CompletionRequest is the request to the completions API.
func (*CompletionRequest) Error ¶
func (r *CompletionRequest) Error() error
Error returns an error if the request is invalid.
func (*CompletionRequest) Flush ¶
func (r *CompletionRequest) Flush()
Flush does nothing. This is here to satisfy the Requester interface.
type CompletionResponse ¶
type CompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Model string `json:"model"` Choices []CompletionChoice `json:"choices"` Usage CompletionUsage `json:"usage"` }
CompletionResponse is the response from the completions API.
func (*CompletionResponse) Text ¶
func (r *CompletionResponse) Text() string
Text returns the generated text.
type CompletionUsage ¶
type CompletionUsage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` }
CompletionUsage is the usage statistics for the completions API.
type Config ¶
type Config struct { APIKey string // secret key for authorization OrgID string // unique identifier of the organization APIBaseURL string // base URL of OpenAI API ParallelTasks int // number of parallel requests RequestTimeout time.Duration // maximum duration time for a request Context context.Context // context for requests HTTPHeaders http.Header // additional HTTP headers for requests HTTPClient *http.Client // http client for sending requests }
Config represents the OpenAI API configuration.
type EditChoice ¶
type EditRequest ¶
type EditRequest struct { Instruction string `json:"instruction"` Input string `json:"input,omitempty"` Model string `json:"model"` Temperature float64 `json:"temperature,omitempty"` TopP float64 `json:"top_p,omitempty"` }
func (*EditRequest) Error ¶
func (r *EditRequest) Error() error
Error returns an error if the request is invalid.
func (*EditRequest) Flush ¶
func (r *EditRequest) Flush()
Flush does nothing. This is here to satisfy the Requester interface.
type EditResponse ¶
type EditResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Choices []EditChoice `json:"choices"` Usage EditUsage `json:"usage"` }
func (*EditResponse) Text ¶
func (r *EditResponse) Text() string
type Embedding ¶
type Embedding struct { // The object type, which will be "embedding". Object string `json:"object"` // The actual embedding, represented as an array of floats. Embedding []float64 `json:"embedding"` // The index of this embedding in the response. Index int `json:"index"` }
Embedding represents an individual embedding in the response from the OpenAI Embedding API.
type EmbeddingRequest ¶
type EmbeddingRequest struct { // The model ID to use for the request. This is required. Model string `json:"model"` // The input text to generate embeddings for. This can either be a string // or an array of tokens. To generate embeddings for multiple inputs in // a single request, pass an array of strings or an array of token arrays. // Each input must not exceed 8192 tokens in length. This is required. Input interface{} `json:"input"` // A unique identifier representing the end-user. This can help OpenAI to // monitor and detect abuse. This is optional. User string `json:"user,omitempty"` }
EmbeddingRequest represents a request to the OpenAI Embedding API.
func (*EmbeddingRequest) Error ¶
func (r *EmbeddingRequest) Error() error
Error returns an error if the request is invalid.
func (*EmbeddingRequest) Flush ¶
func (r *EmbeddingRequest) Flush()
Flush does nothing. This is here to satisfy the Requester interface.
type EmbeddingResponse ¶
type EmbeddingResponse struct { // The object type, which will be "list". Object string `json:"object"` // The list of embeddings in the response. Data []Embedding `json:"data"` // The model ID that was used. Model string `json:"model"` // Usage information. Usage EmbeddingUsage `json:"usage"` }
EmbeddingResponse represents a response from the OpenAI Embedding API.
type EmbeddingUsage ¶
type EmbeddingUsage struct { // The number of tokens in the prompt. PromptTokens int `json:"prompt_tokens"` // The total number of tokens. TotalTokens int `json:"total_tokens"` }
EmbeddingUsage represents usage information in the response from the OpenAI Embedding API.
type Error ¶
type Error struct { Message string `json:"message"` // human-readable text about the error Type string `json:"type"` // high level error category Param string `json:"param"` // which parameter the error is related to Code string `json:"code"` // error code }
Error describes an error data that can be returned by the OpenAI API server.
type ErrorResponse ¶
type ErrorResponse struct {
Error Error `json:"error"` // error details
}
ErrorResponse is the error response that can be returned by the OpenAI API server.
type FileDeleteResponse ¶
type FileDeleteResponse struct { // The unique identifier of the file that was deleted. ID string `json:"id"` // Object type - always "file" for this data type. Object string `json:"object"` // Indicates whether the file was successfully deleted. Deleted bool `json:"deleted"` }
FileDeleteResponse represents the response from the OpenAI File API when a file deletion request is made.
type FileDetails ¶
type FileDetails struct { // The unique identifier of the file. ID string `json:"id"` // Object type - always "file" for this data type. Object string `json:"object"` // The size of the file in bytes. Bytes int `json:"bytes"` // The time when the file was created, in Unix time. CreatedAt int `json:"created_at"` // The filename of the uploaded file. Filename string `json:"filename"` // The purpose of the file. Purpose string `json:"purpose"` }
FileDetails represents a single file's data in the response.
type FileResponse ¶
type FileResponse struct { // List of files belonging to the user's organization. Data FilesData `json:"data"` // Object type - always "list" for this type of response. Object string `json:"object"` }
FileResponse represents the response from the OpenAI File API.
type FileUploadRequest ¶
type FileUploadRequest struct { // Name of the JSON Lines file to be uploaded. This is a required field. File *os.File `json:"file"` // The intended purpose of the uploaded documents. // This is a required field. "fine-tune" is used for Fine-tuning. Purpose string `json:"purpose"` }
FileUploadRequest represents a request to the OpenAI File API for uploading a file. This structure is used to provide the file and the purpose of the file to the API.
func (*FileUploadRequest) CloseFile ¶
func (r *FileUploadRequest) CloseFile()
CloseFile closes the file associated with the request.
func (*FileUploadRequest) Error ¶
func (fr *FileUploadRequest) Error() error
func (*FileUploadRequest) Flush ¶
func (r *FileUploadRequest) Flush()
Flush closes the files descriptors associated with the request.
func (*FileUploadRequest) OpenFile ¶
func (r *FileUploadRequest) OpenFile(path string) error
OpenFile reads an any file from the provided path and assigns the *os.File value to the File field of the request.
type FileUploadResponse ¶
type FileUploadResponse struct { // The unique identifier of the uploaded file. ID string `json:"id"` // Object type - always "file" for this data type. Object string `json:"object"` // The size of the uploaded file in bytes. Bytes int `json:"bytes"` // The Unix timestamp (seconds since the epoch) at // which the file was created. CreatedAt int `json:"created_at"` // The name of the uploaded file. Filename string `json:"filename"` // The intended purpose of the uploaded file. "fine-tune" // is used for Fine-tuning. Purpose string `json:"purpose"` }
FileUploadResponse represents the response from the OpenAI File API when a file upload request is made. It provides information about the uploaded file.
type FilesData ¶
type FilesData []*FileDetails
type FineTuneEvent ¶
type FineTuneEvent struct { Object string `json:"object"` // Object type (should be "fine-tune-event") CreatedAt int64 `json:"created_at"` // Timestamp of the event creation Level string `json:"level"` // Level of the event (for example, "info") Message string `json:"message"` // Message associated with the event }
FineTuneEvent represents an event of a fine-tuning job.
type FineTuneEventListResponse ¶
type FineTuneEventListResponse struct { Object string `json:"object"` // Type of the object (list) Data FineTuneEventsData `json:"data"` // List of fine-tuning job events }
FineTuneEventListResponse represents the response from the OpenAI API when requesting fine-tuning job events. It contains a list of fine-tuning job events.
type FineTuneEventsData ¶
type FineTuneEventsData []*FineTuneEvent
type FineTuneListResponse ¶
type FineTuneListResponse struct { Object string `json:"object"` // Object type (should be "list") Data FineTunesData `json:"data"` // List of fine-tuning jobs }
FineTuneListResponse represents a list of fine-tuning jobs.
type FineTuneRequest ¶
type FineTuneRequest struct { TrainingFile string `json:"training_file"` // ID of uploaded file with training data ValidationFile string `json:"validation_file,omitempty"` // ID of uploaded file with validation data Model string `json:"model,omitempty"` // Base model to fine-tune NEpochs int `json:"n_epochs,omitempty"` // Number of epochs for training BatchSize int `json:"batch_size,omitempty"` // Batch size for training LearningRateMultiplier float64 `json:"learning_rate_multiplier,omitempty"` // Multiplier for the learning rate PromptLossWeight float64 `json:"prompt_loss_weight,omitempty"` // Weight for loss on prompt tokens ComputeClassificationMetrics bool `json:"compute_classification_metrics,omitempty"` // If true, calculates classification-specific metrics ClassificationNClasses int `json:"classification_n_classes,omitempty"` // Number of classes in a classification task ClassificationPositiveClass string `json:"classification_positive_class,omitempty"` // Positive class in binary classification ClassificationBetas []float64 `json:"classification_betas,omitempty"` // F-beta scores at the specified beta values Suffix string `json:"suffix,omitempty"` // Suffix for the fine-tuned model name }
FineTuneRequest represents the request for a fine-tuning job.
func (*FineTuneRequest) Error ¶
func (ftr *FineTuneRequest) Error() error
Error returns an error if the request is invalid.
func (*FineTuneRequest) Flush ¶
func (ftr *FineTuneRequest) Flush()
Flush does nothing. It here to implement the Requester interface.
type FineTuneResponse ¶
type FineTuneResponse struct { ID string `json:"id"` // ID of the fine-tune task Object string `json:"object"` // Object type (should be "fine-tune") Model string `json:"model"` // Base model used for fine-tuning CreatedAt int64 `json:"created_at"` // Timestamp of the task creation Events []FineTuneEvent `json:"events"` // Events associated with the task FineTunedModel *string `json:"fine_tuned_model"` // Fine-tuned model name (null if not yet completed) Hyperparams Hyperparameters `json:"hyperparams"` // Hyperparameters used for fine-tuning OrganizationID string `json:"organization_id"` // ID of the organization performing the fine-tuning ResultFiles []interface{} `json:"result_files"` // Files with the results (empty if not yet completed) Status string `json:"status"` // Status of the fine-tuning task ValidationFiles []interface{} `json:"validation_files"` // Validation files (empty if not provided) TrainingFiles []TrainingFile `json:"training_files"` // Training files UpdatedAt int64 `json:"updated_at"` // Timestamp of the last update }
FineTuneResponse represents the response for a fine-tuning job.
type FineTunesData ¶
type FineTunesData []*FineTuneResponse
type Hyperparameters ¶
type Hyperparameters struct { BatchSize int `json:"batch_size"` // Batch size used for training LearningRateMultiplier float64 `json:"learning_rate_multiplier"` // Multiplier for the learning rate NEpochs int `json:"n_epochs"` // Number of epochs for training PromptLossWeight float64 `json:"prompt_loss_weight"` // Weight for loss on prompt tokens }
Hyperparameters represents the hyperparameters used for fine-tuning.
type ImageEditData ¶
type ImageEditRequest ¶
type ImageEditRequest struct { Image *os.File `json:"image"` // Base64-encoded PNG file, less than 4MB, and square. Mask *os.File `json:"mask,omitempty"` // Optional Base64-encoded PNG mask file. Prompt string `json:"prompt"` // Text description of the desired image(s). N int `json:"n,omitempty"` // Number of images to generate. Default 1. Size string `json:"size,omitempty"` // Size of the generated images. Default 1024x1024. ResponseFormat string `json:"response_format,omitempty"` // Format in which the images are returned. Default url. User string `json:"user,omitempty"` // Unique identifier representing the end-user. }
ImageEditRequest represents a request to the OpenAI Image API.
func (*ImageEditRequest) CloseImageFile ¶
func (r *ImageEditRequest) CloseImageFile()
CloseImageFile closes the Image file descriptor associated with the request.
func (*ImageEditRequest) CloseMaskFile ¶
func (r *ImageEditRequest) CloseMaskFile()
CloseMaskFile closes the Mask file descriptor associated with the request.
func (*ImageEditRequest) Error ¶
func (r *ImageEditRequest) Error() error
func (*ImageEditRequest) Flush ¶
func (r *ImageEditRequest) Flush()
Flush closes the files descriptors associated with the request.
func (*ImageEditRequest) OpenImageFile ¶
func (r *ImageEditRequest) OpenImageFile(path string) error
OpenImageFile reads an image from a file and assigns the *os.File value to the Image field of the request.
func (*ImageEditRequest) OpenMaskFile ¶
func (r *ImageEditRequest) OpenMaskFile(path string) error
OpenMaskFile reads an image from a file and assigns the *os.File value to the Mask field of the request.
type ImageEditResponse ¶
type ImageEditResponse struct { // The time the request was created, in Unix time. Created int64 `json:"created"` // An array containing the generated images. Data []ImageEditData `json:"data"` // contains filtered or unexported fields }
ImageEditResponse represents a response from the OpenAI Image API.
func (*ImageEditResponse) Save ¶
func (r *ImageEditResponse) Save(path string) error
type ImageGenerationData ¶
type ImageGenerationData struct { // URL is the address where the generated image can be accessed. URL string `json:"url,omitempty"` // B64 is the base64 encoded image data. Base64 string `json:"b64_json,omitempty"` }
ImageGenerationData represents the structure of an image in the response data.
type ImageGenerationRequest ¶
type ImageGenerationRequest struct { // Prompt is a text description of the desired image(s). Prompt string `json:"prompt"` // N is the number of images to generate. Optional. N int `json:"n,omitempty"` // Size of the generated images. Optional. Size string `json:"size,omitempty"` // ResponseFormat is the format in which the generated images // are returned. Optional. ResponseFormat string `json:"response_format,omitempty"` // User is a unique identifier representing the end-user. Optional. User string `json:"user,omitempty"` }
ImageGenerationRequest represents the structure of a request to the OpenAI API.
func (*ImageGenerationRequest) Error ¶
func (r *ImageGenerationRequest) Error() error
Error returns an error if the request is invalid.
func (*ImageGenerationRequest) Flush ¶
func (r *ImageGenerationRequest) Flush()
Flush does nothing. It is here to satisfy the Requester interface.
type ImageGenerationResponse ¶
type ImageGenerationResponse struct { // Created is the timestamp when the image(s) was generated. Created int `json:"created"` // Data is an array of generated image data. Data []ImageGenerationData `json:"data"` // contains filtered or unexported fields }
ImageGenerationResponse represents the structure of a response from the OpenAI API.
func (*ImageGenerationResponse) Save ¶
func (r *ImageGenerationResponse) Save(path string) error
type ImageVariationData ¶
type ImageVariationRequest ¶
type ImageVariationRequest struct { Image *os.File `json:"image"` // Base64-encoded PNG file N int `json:"n,omitempty"` // Number of images to generate Size string `json:"size,omitempty"` // Size of the generated images ResponseFormat string `json:"response_format,omitempty"` // Format of the returned images User string `json:"user,omitempty"` // Unique identifier of the end-user }
ImageVariationRequest represents a request to the OpenAI Image Variation API. The image field is required and must be a valid PNG file, less than 4MB, and square. The optional fields include n (number of images to generate, default is 1), size (the size of the generated images, default is 1024x1024), response_format (the format in which the images are returned, default is url), and user (a unique identifier representing your end-user).
func (*ImageVariationRequest) CloseImageFile ¶
func (r *ImageVariationRequest) CloseImageFile()
CloseImageFile closes the Image file descriptor associated with the request.
func (*ImageVariationRequest) Error ¶
func (r *ImageVariationRequest) Error() error
func (*ImageVariationRequest) Flush ¶
func (r *ImageVariationRequest) Flush()
Flush closes the files descriptors associated with the request.
func (*ImageVariationRequest) OpenImageFile ¶
func (r *ImageVariationRequest) OpenImageFile(path string) error
OpenImageFile reads an image from a file and assigns the *os.File value to the Image field of the request.
type ImageVariationResponse ¶
type ImageVariationResponse struct { Created int64 `json:"created"` // timestamp of creation Data []ImageVariationData `json:"data"` // generated image data // contains filtered or unexported fields }
ImageVariationResponse represents a response from the OpenAI Image Variation API. The created field represents the timestamp of creation, and the data field includes the generated image data.
func (*ImageVariationResponse) Save ¶
func (r *ImageVariationResponse) Save(path string) error
type ModelDeleteResponse ¶
type ModelDeleteResponse struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` }
ModelDeleteResponse represents the response from the delete model endpoint.
type ModelDetails ¶
type ModelDetails struct { // A unique identifier for the model. ID string `json:"id"` // The type of the object, in this case, "model". Object string `json:"object"` // The UNIX timestamp representing when the model was created. Created int64 `json:"created"` // The owner of the model. OwnedBy string `json:"owned_by"` // A list of permissions associated with the model. Permission []ModelPermission `json:"permission"` // The root model from which the current model is derived. Root string `json:"root"` // The immediate parent model, if any, // from which the current model is derived. Parent interface{} `json:"parent"` }
ModelDetails represents a model object.
func (*ModelDetails) Name ¶
func (ms *ModelDetails) Name() string
Name returns the name of the model.
type ModelPermission ¶
type ModelPermission struct { // A unique identifier for the permission. ID string `json:"id"` // The type of the object, in this case, "model_permission". Object string `json:"object"` // The UNIX timestamp representing when the permission was created. Created int64 `json:"created"` // A boolean indicating if creating a new engine is allowed. AllowCreateEngine bool `json:"allow_create_engine"` // A boolean indicating if sampling is allowed. AllowSampling bool `json:"allow_sampling"` // A boolean indicating if log probabilities can be accessed. AllowLogprobs bool `json:"allow_logprobs"` // A boolean indicating if search indices can be used. AllowSearchIndices bool `json:"allow_search_indices"` // A boolean indicating if the model can be viewed. AllowView bool `json:"allow_view"` // A boolean indicating if the model can be fine-tuned. AllowFineTuning bool `json:"allow_fine_tuning"` // The organization to which the permission applies. Organization string `json:"organization"` // The group within the organization to which the permission applies. Group interface{} `json:"group"` // A boolean indicating if the permission is blocking. IsBlocking bool `json:"is_blocking"` }
ModelPermission represents a permission object.
type ModelResponse ¶
type ModelResponse struct { // The type of the object, in this case, "list". Object string `json:"object"` // A list of Model objects, representing the available models. Data ModelsData `json:"data"` }
ModelResponse represents the response from the models endpoint.
type ModelsData ¶
type ModelsData []*ModelDetails
ModelsData represents a list of models.
func (*ModelsData) Len ¶
func (data *ModelsData) Len() int
Len returns the length of the models list.
func (*ModelsData) Names ¶
func (data *ModelsData) Names() []string
Names returns a list of the names of the models.
func (*ModelsData) Range ¶
func (data *ModelsData) Range() ModelsData
Range returns the models list.
type ModerationRequest ¶
type ModerationRequest struct { // The input text to classify. This is required. Input string `json:"input"` // The model to use for the request. Two content moderations models are // available: text-moderation-stable and text-moderation-latest. // Defaults to text-moderation-latest. Model string `json:"model,omitempty"` }
ModerationRequest represents a request to the OpenAI Moderation API.
func (*ModerationRequest) Error ¶
func (r *ModerationRequest) Error() error
Error returns an error if the request is invalid.
func (*ModerationRequest) Flush ¶
func (r *ModerationRequest) Flush()
Flush does nothing. This is here to satisfy the Requester interface.
type ModerationResponse ¶
type ModerationResponse struct { // The unique ID of the moderation request. ID string `json:"id"` // The model that was used for the moderation. Model string `json:"model"` // The results from the moderation. Results []ModerationResult `json:"results"` }
ModerationResponse represents the response from the OpenAI Moderation API.
func (*ModerationResponse) IsFlagged ¶
func (r *ModerationResponse) IsFlagged() bool
IsFlagged returns true if the input was flagged under any category.
type ModerationResult ¶
type ModerationResult struct { // Map of categories and whether the input was flagged under them. Categories map[string]bool `json:"categories"` // Map of categories and the associated scores. CategoryScores map[string]float64 `json:"category_scores"` // Whether the input was flagged under any category. Flagged bool `json:"flagged"` }
ModerationResult represents a single result from the moderation response.
type TrainingFile ¶
type TrainingFile struct { ID string `json:"id"` // ID of the file Object string `json:"object"` // Object type (should be "file") Bytes int `json:"bytes"` // Size of the file in bytes CreatedAt int64 `json:"created_at"` // Timestamp of the file upload Filename string `json:"filename"` // Name of the file Purpose string `json:"purpose"` // Purpose of the file (for example, "fine-tune-train") }
TrainingFile represents an uploaded file.