openai

package
v0.0.0-...-ba22aaa Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

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

type AudioAPI

type AudioAPI Api

func (*AudioAPI) CreateEnglishTranslation

func (a *AudioAPI) CreateEnglishTranslation(ctx context.Context, aTReq *AudioTranscriptionRequest) (*AudioTranscriptionResponse, *Response, error)

CreateTranslation translates audio into into English.

func (*AudioAPI) CreateTranscription

CreateTranscription transcribes audio into the input language.

type AudioTranscriptionRequest

type AudioTranscriptionRequest struct {
	File           string  `json:"file" required:"true"`
	Model          string  `json:"model" required:"true"`
	Prompt         string  `json:"prompt,omitempty"`
	ResponseFormat string  `json:"response_format,omitempty"`
	Temperature    float64 `json:"temperature,omitempty"`
	Language       string  `json:"language,omitempty"`
}

type AudioTranscriptionResponse

type AudioTranscriptionResponse struct {
	Text string `json:"text"`
}

type Categories

type Categories struct {
	Hate            bool `json:"hate"`
	HateThreatening bool `json:"hate/threatening"`
	SelfHarm        bool `json:"self-harm"`
	Sexual          bool `json:"sexual"`
	SexualMinors    bool `json:"sexual/minors"`
	Violence        bool `json:"violence"`
	ViolenceGraphic bool `json:"violence/graphic"`
}

type CategoryScores

type CategoryScores struct {
	Hate            float64 `json:"hate"`
	HateThreatening float64 `json:"hate/threatening"`
	SelfHarm        float64 `json:"self-harm"`
	Sexual          float64 `json:"sexual"`
	SexualMinors    float64 `json:"sexual/minors"`
	Violence        float64 `json:"violence"`
	ViolenceGraphic float64 `json:"violence/graphic"`
}

type ChatAPI

type ChatAPI Api

func (*ChatAPI) CreateChatCompletion

func (c *ChatAPI) CreateChatCompletion(ctx context.Context, chatReq *ChatRequest) (*ChatCompletion, *Response, error)

CreateChatCompletion creates a completion for the chat message

type ChatCompletion

type ChatCompletion struct {
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Created int64    `json:"created"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

type ChatRequest

type ChatRequest struct {
	Model            string             `json:"model" binding:"required"`
	Messages         []string           `json:"messages" binding:"required"`
	Temperature      float64            `json:"temperature,omitempty"`
	TopP             float64            `json:"top_p,omitempty"`
	N                int                `json:"n,omitempty"`
	Stream           bool               `json:"stream,omitempty"`
	Stop             interface{}        `json:"stop,omitempty"`
	MaxTokens        int                `json:"max_tokens,omitempty"`
	PresencePenalty  float64            `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64            `json:"frequency_penalty,omitempty"`
	LogitBias        map[string]float64 `json:"logit_bias,omitempty"`
	User             string             `json:"user,omitempty"`
}

type Choice

type Choice struct {
	Index        int     `json:"index"`
	Message      Message `json:"message"`
	FinishReason string  `json:"finish_reason"`
}

type Completion

type Completion struct {
	ID      string       `json:"id"`
	Object  string       `json:"object"`
	Created int64        `json:"created"`
	Model   string       `json:"model"`
	Choices []TextChoice `json:"choices"`
	Usage   TextUsage    `json:"usage"`
}

type CompletionRequest

type CompletionRequest struct {
	Model            string      `json:"model" binding:"required"`
	Prompt           interface{} `json:"prompt,omitempty"`
	Suffix           string      `json:"suffix,omitempty"`
	MaxTokens        int         `json:"max_tokens,omitempty"`
	Temperature      float64     `json:"temperature,omitempty"`
	TopP             float64     `json:"top_p,omitempty"`
	N                int         `json:"n,omitempty"`
	Stream           bool        `json:"stream,omitempty"`
	Logprobs         int         `json:"logprobs,omitempty"`
	Echo             bool        `json:"echo,omitempty"`
	Stop             interface{} `json:"stop,omitempty"`
	PresencePenalty  float64     `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64     `json:"frequency_penalty,omitempty"`
	BestOf           int         `json:"best_of,omitempty"`
	LogitBias        interface{} `json:"logit_bias,omitempty"`
	User             string      `json:"user,omitempty"`
}

type CompletionsAPI

type CompletionsAPI Api

func (*CompletionsAPI) CreateCompletion

func (c *CompletionsAPI) CreateCompletion(ctx context.Context, completionReq *CompletionRequest) (*Completion, *Response, error)

CreateCompletion creates a completion for the provided prompt and parameters

type ContentModerationInput

type ContentModerationInput struct {
	Input string `json:"input" binding:"required"`
	Model string `json:"model,omitempty"`
}

type DeleteModelResponse

type DeleteModelResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Deleted bool   `json:"deleted"`
}

type EditRequest

type EditRequest struct {
	Model       string  `json:"model" binding:"required"`
	Input       string  `json:"input,omitempty"`
	Instruction string  `json:"instruction" binding:"required"`
	N           int     `json:"n,omitempty" default:"1"`
	Temperature float64 `json:"temperature,omitempty" default:"1"`
	TopP        float64 `json:"top_p,omitempty" default:"1"`
}

type EditedChoice

type EditedChoice struct {
	Text  string `json:"text"`
	Index int    `json:"index"`
}

type EditedInput

type EditedInput struct {
	Object  string         `json:"object"`
	Created int64          `json:"created"`
	Choices []EditedChoice `json:"choices"`
	Usage   EditedUsage    `json:"usage"`
}

type EditedUsage

type EditedUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type EditsAPI

type EditsAPI Api

func (*EditsAPI) CreateEdit

func (e *EditsAPI) CreateEdit(ctx context.Context, editReq *EditRequest) (*EditedInput, *Response, error)

CreateEdit creates a new edit for the provided input, instruction, and parameters.

type Embed

type Embed struct {
	Object    string    `json:"object"`
	Embedding []float64 `json:"embedding"`
	Index     int       `json:"index"`
}

type EmbedUse

type EmbedUse struct {
	PromptTokens int `json:"prompt_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

type EmbeddingRequest

type EmbeddingRequest struct {
	Model string      `json:"model" binding:"required"`
	Input interface{} `json:"input" binding:"required"`
	User  string      `json:"user,omitempty"`
}

type EmbeddingResponse

type EmbeddingResponse struct {
	Object string   `json:"object"`
	Data   []Embed  `json:"data"`
	Model  string   `json:"model"`
	Usage  EmbedUse `json:"usage"`
}

type EmbeddingsAPI

type EmbeddingsAPI Api

func (*EmbeddingsAPI) CreateEmbeddings

func (em *EmbeddingsAPI) CreateEmbeddings(ctx context.Context, embReq *EmbeddingRequest) (*EmbeddingResponse, *Response, error)

CreateEmbeddings creates an embedding vector representing the input text

type EnginesAPI

type EnginesAPI Api

The Engines endpoints are deprecated. Please use their replacement, Models, instead.

type File

type File struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	Bytes     int    `json:"bytes"`
	CreatedAt int64  `json:"created_at"`
	Filename  string `json:"filename"`
	Purpose   string `json:"purpose"`
}

type FileAPI

type FileAPI Api

func (*FileAPI) DeleteFile

func (f *FileAPI) DeleteFile(ctx context.Context, id string) (*FileDeleteResponse, *Response, error)

DeleteFile deletes file

func (*FileAPI) List

func (f *FileAPI) List(ctx context.Context) (*FileList, *Response, error)

List returns a list of files that belong to the user's organization.

func (*FileAPI) RetrieveFile

func (f *FileAPI) RetrieveFile(ctx context.Context, id string) (*File, *Response, error)

RetrieveFile returns information about a specific file.

func (*FileAPI) RetrieveFileContent

func (f *FileAPI) RetrieveFileContent(ctx context.Context, id string) (*Response, error)

RetrieveFileContent returns the contents of the specified file.

func (*FileAPI) UploadFile

func (f *FileAPI) UploadFile(ctx context.Context, fuReq *FileUploadRequest) (*File, *Response, error)

UploadFile uploads a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB. Please contact https://help.openai.com/ if you need to increase the storage limit.

type FileDeleteResponse

type FileDeleteResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Deleted bool   `json:"deleted"`
}

type FileList

type FileList struct {
	Data   []File `json:"data"`
	Object string `json:"object"`
}

type FileUploadRequest

type FileUploadRequest struct {
	// Name of the JSON Lines file to be uploaded.
	// If the purpose is set to "fine-tune",
	// each line is a JSON record with "prompt" and "completion" fields representing your training examples (https://platform.openai.com/docs/guides/fine-tuning/prepare-training-data).
	File string `json:"file"`

	// The intended purpose of the uploaded documents.
	// Use "fine-tune" for Fine-tuning. This allows us to validate the format of the uploaded file.
	Purpose string `json:"purpose"`
}

type FineTune

type FineTune struct {
	ID              string          `json:"id"`
	Object          string          `json:"object"`
	Model           string          `json:"model"`
	CreatedAt       int64           `json:"created_at"`
	Events          []FineTuneEvent `json:"events"`
	FineTunedModel  interface{}     `json:"fine_tuned_model"`
	Hyperparams     Hyperparams     `json:"hyperparams"`
	OrganizationID  string          `json:"organization_id"`
	ResultFiles     []interface{}   `json:"result_files"`
	Status          string          `json:"status"`
	ValidationFiles []interface{}   `json:"validation_files"`
	TrainingFiles   []TrainingFile  `json:"training_files"`
	UpdatedAt       int64           `json:"updated_at"`
}

type FineTuneEvent

type FineTuneEvent struct {
	Object    string `json:"object"`
	CreatedAt int64  `json:"created_at"`
	Level     string `json:"level"`
	Message   string `json:"message"`
}

type FineTuneEventList

type FineTuneEventList struct {
	Object string          `json:"object"`
	Data   []FineTuneEvent `json:"data"`
}

type FineTuneInfo

type FineTuneInfo struct {
	ID              string          `json:"id"`
	Object          string          `json:"object"`
	Model           string          `json:"model"`
	CreatedAt       int64           `json:"created_at"`
	Events          []FineTuneEvent `json:"events"`
	FineTunedModel  string          `json:"fine_tuned_model"`
	Hyperparams     HyperParams     `json:"hyperparams"`
	OrganizationID  string          `json:"organization_id"`
	ResultFiles     []File          `json:"result_files"`
	Status          string          `json:"status"`
	ValidationFiles []File          `json:"validation_files"`
	TrainingFiles   []File          `json:"training_files"`
	UpdatedAt       int64           `json:"updated_at"`
}

type FineTuneList

type FineTuneList struct {
	Object string     `json:"object"`
	Data   []FineTune `json:"data"`
}

type FineTuneRequest

type FineTuneRequest struct {
	TrainingFile                 string    `json:"training_file" validate:"required"`
	ValidationFile               string    `json:"validation_file"`
	Model                        string    `json:"model,omitempty"`
	NumEpochs                    int       `json:"n_epochs,omitempty"`
	BatchSize                    *int      `json:"batch_size,omitempty"`
	LearningRateMultiplier       *float64  `json:"learning_rate_multiplier,omitempty"`
	PromptLossWeight             *float64  `json:"prompt_loss_weight,omitempty"`
	ComputeClassificationMetrics bool      `json:"compute_classification_metrics,omitempty"`
	ClassificationNumClasses     *int      `json:"classification_n_classes,omitempty"`
	ClassificationPositiveClass  string    `json:"classification_positive_class,omitempty"`
	ClassificationBetas          []float64 `json:"classification_betas,omitempty"`
	Suffix                       string    `json:"suffix,omitempty"`
}

type FineTunesAPI

type FineTunesAPI Api

func (*FineTunesAPI) CancelFineTune

func (ft *FineTunesAPI) CancelFineTune(ctx context.Context, id string) (*FineTuneInfo, *Response, error)

CancelFineTune immediately cancel a fine-tune job.

func (*FineTunesAPI) CreateFineTune

func (ft *FineTunesAPI) CreateFineTune(ctx context.Context, ftReq *FineTuneRequest) (*FineTune, *Response, error)

CreateFineTune creates a job that fine-tunes a specified model from a given dataset. Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.

func (*FineTunesAPI) Delete

func (ft *FineTunesAPI) Delete(ctx context.Context, model string) (*DeleteModelResponse, *Response, error)

Delete a fine-tuned model. You must have the Owner role in your organization.

func (*FineTunesAPI) List

func (ft *FineTunesAPI) List(ctx context.Context) (*FineTuneList, *Response, error)

List your organization's fine-tuning jobs

func (*FineTunesAPI) ListFineTuneEvents

func (ft *FineTunesAPI) ListFineTuneEvents(ctx context.Context, id string) (*FineTuneEventList, *Response, error)

ListFineTuneEvents gets fine-grained status updates for a fine-tune job.

func (*FineTunesAPI) RetrieveFineTune

func (ft *FineTunesAPI) RetrieveFineTune(ctx context.Context, id string) (*FineTuneInfo, *Response, error)

RetrieveFineTune gets info about the fine-tune job.

type HyperParams

type HyperParams struct {
	BatchSize              int     `json:"batch_size"`
	LearningRateMultiplier float64 `json:"learning_rate_multiplier"`
	NEpochs                int     `json:"n_epochs"`
	PromptLossWeight       float64 `json:"prompt_loss_weight"`
}

type Hyperparams

type Hyperparams struct {
	BatchSize              int     `json:"batch_size"`
	LearningRateMultiplier float64 `json:"learning_rate_multiplier"`
	NEpochs                int     `json:"n_epochs"`
	PromptLossWeight       float64 `json:"prompt_loss_weight"`
}

type ImageData

type ImageData struct {
	URL string `json:"url"`
}

type ImageEditRequest

type ImageEditRequest struct {
	Image          string `json:"image" binding:"required"`
	Mask           string `json:"mask,omitempty"`
	Prompt         string `json:"prompt" binding:"required"`
	N              int    `json:"n,omitempty" default:"1"`
	Size           string `json:"size,omitempty" default:"1024x1024"`
	ResponseFormat string `json:"response_format,omitempty" default:"url"`
	User           string `json:"user,omitempty"`
}

type ImageRequest

type ImageRequest struct {
	Prompt         string `json:"prompt" binding:"required"`
	N              int    `json:"n,omitempty" default:"1"`
	Size           string `json:"size,omitempty" default:"1024x1024"`
	ResponseFormat string `json:"response_format,omitempty" default:"url"`
	User           string `json:"user,omitempty"`
}

type ImageResponse

type ImageResponse struct {
	Created int64       `json:"created"`
	Data    []ImageData `json:"data"`
}

type ImagesAPI

type ImagesAPI Api

func (*ImagesAPI) CreateImage

func (i *ImagesAPI) CreateImage(ctx context.Context, imgReq *ImageRequest) (*ImageResponse, *Response, error)

CreateImage creates an image given a prompt.

func (*ImagesAPI) CreateImageEdit

func (i *ImagesAPI) CreateImageEdit(ctx context.Context, imgEditReq *ImageEditRequest) (*ImageResponse, *Response, error)

CreateImageEdit creates an edited or extended image given an original image and a prompt.

func (*ImagesAPI) CreateImageVariation

func (i *ImagesAPI) CreateImageVariation(ctx context.Context, imgReq *ImageRequest) (*ImageResponse, *Response, error)

CreateImageVariation creates a variation of a given image.

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type Model

type Model struct {
	ID         string      `json:"id"`
	Object     string      `json:"object"`
	OwnedBy    string      `json:"owned_by"`
	Permission interface{} `json:"permission"`
}

type ModelList

type ModelList struct {
	Data   []Model `json:"data"`
	Object string  `json:"object"`
}

type ModelsAPI

type ModelsAPI Api

func (*ModelsAPI) List

func (m *ModelsAPI) List(ctx context.Context) (*ModelList, *Response, error)

List lists the currently available models, and provides basic information about each one such as the owner and availability.

func (*ModelsAPI) RetrieveModel

func (m *ModelsAPI) RetrieveModel(ctx context.Context, name string) (*Model, *Response, error)

RetrieveModel retrieves a model instance, providing basic information about the model such as the owner and permissioning.

type ModerationsAPI

type ModerationsAPI Api

func (*ModerationsAPI) CreateModeration

type OpenAIClient

type OpenAIClient struct {
	BaseURL *url.URL

	Completions *CompletionsAPI
	Models      *ModelsAPI
	Chat        *ChatAPI
	Images      *ImagesAPI
	Embeddings  *EmbeddingsAPI
	Audio       *AudioAPI
	File        *FileAPI
	FineTunes   *FineTunesAPI
	Moderations *ModerationsAPI
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client) *OpenAIClient

func (*OpenAIClient) Do

func (c *OpenAIClient) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

func (*OpenAIClient) NewRequest

func (oapiClient *OpenAIClient) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

type Response

type Response struct {
	*http.Response
}

type Results

type Results struct {
	Categories     Categories     `json:"categories"`
	CategoryScores CategoryScores `json:"category_scores"`
	Flagged        bool           `json:"flagged"`
}

type TextChoice

type TextChoice struct {
	Text         string      `json:"text"`
	Index        int         `json:"index"`
	Logprobs     interface{} `json:"logprobs"`
	FinishReason string      `json:"finish_reason"`
}

type TextModerationResponse

type TextModerationResponse struct {
	ID      string    `json:"id"`
	Model   string    `json:"model,omitempty"`
	Results []Results `json:"results"`
}

type TextUsage

type TextUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type TrainingFile

type TrainingFile struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	Bytes     int    `json:"bytes"`
	CreatedAt int64  `json:"created_at"`
	Filename  string `json:"filename"`
	Purpose   string `json:"purpose"`
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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