Documentation ¶
Index ¶
- Constants
- func Float32Ptr(f float32) *float32
- func IntPtr(i int) *int
- type APIError
- type APIErrorResponse
- type Client
- type ClientOption
- type CompletionRequest
- type CompletionResponse
- type CompletionResponseChoice
- type EditsRequest
- type EditsResponse
- type EditsResponseChoice
- type EditsResponseUsage
- type Embedding
- type EmbeddingsRequest
- type EmbeddingsResponse
- type EmbeddingsResponseUsage
- type EngineObject
- type EnginesResponse
- type Event
- type File
- type FileDeleteResponse
- type FileUploadResponse
- type FineTuneOptions
- type FineTuneResponse
- type HyperParams
- type LogprobResult
- type SearchData
- type SearchRequest
- type SearchResponse
Constants ¶
const ( TextAda001Engine = "text-ada-001" TextBabbage001Engine = "text-babbage-001" TextCurie001Engine = "text-curie-001" TextDavinci001Engine = "text-davinci-001" AdaEngine = "ada" BabbageEngine = "babbage" CurieEngine = "curie" DavinciEngine = "davinci" DefaultEngine = DavinciEngine )
Engine Types
const ( FineTunePurpose = "fine-tune" SearchPurpose = "search" AnswersPurpose = "answers" ClassificationsPurpose = "classifications" )
const ( TextSimilarityAda001 = "text-similarity-ada-001" TextSimilarityBabbage001 = "text-similarity-babbage-001" TextSimilarityCurie001 = "text-similarity-curie-001" TextSimilarityDavinci001 = "text-similarity-davinci-001" )
const ( TextSearchAdaDoc001 = "text-search-ada-doc-001" TextSearchAdaQuery001 = "text-search-ada-query-001" TextSearchBabbageDoc001 = "text-search-babbage-doc-001" TextSearchBabbageQuery001 = "text-search-babbage-query-001" TextSearchCurieDoc001 = "text-search-curie-doc-001" TextSearchCurieQuery001 = "text-search-curie-query-001" TextSearchDavinciDoc001 = "text-search-davinci-doc-001" TextSearchDavinciQuery001 = "text-search-davinci-query-001" )
const ( CodeSearchAdaCode001 = "code-search-ada-code-001" CodeSearchAdaText001 = "code-search-ada-text-001" CodeSearchBabbageCode001 = "code-search-babbage-code-001" CodeSearchBabbageText001 = "code-search-babbage-text-001" )
Variables ¶
This section is empty.
Functions ¶
func Float32Ptr ¶
Float32Ptr converts a float32 to a *float32 as a convenience
Types ¶
type APIError ¶
type APIError struct { StatusCode int `json:"status_code"` Message string `json:"message"` Type string `json:"type"` }
APIError represents an error that occured on an API
type APIErrorResponse ¶
type APIErrorResponse struct {
Error APIError `json:"error"`
}
APIErrorResponse is the full error respnose that has been returned by an API.
type Client ¶
type Client interface { // Engines lists the currently available engines, and provides basic information about each // option such as the owner and availability. Engines(ctx context.Context) (*EnginesResponse, error) // Engine retrieves an engine instance, providing basic information about the engine such // as the owner and availability. Engine(ctx context.Context, engine string) (*EngineObject, error) // Completion creates a completion with the default engine. This is the main endpoint of the API // which auto-completes based on the given prompt. Completion(ctx context.Context, request CompletionRequest) (*CompletionResponse, error) // CompletionStream creates a completion with the default engine and streams the results through // multiple calls to onData. CompletionStream(ctx context.Context, request CompletionRequest, onData func(*CompletionResponse)) error // CompletionWithEngine is the same as Completion except allows overriding the default engine on the client CompletionWithEngine(ctx context.Context, engine string, request CompletionRequest) (*CompletionResponse, error) // CompletionStreamWithEngine is the same as CompletionStream except allows overriding the default engine on the client CompletionStreamWithEngine(ctx context.Context, engine string, request CompletionRequest, onData func(*CompletionResponse)) error // Given a prompt and an instruction, the model will return an edited version of the prompt. Edits(ctx context.Context, request EditsRequest) (*EditsResponse, error) // Search performs a semantic search over a list of documents with the default engine. Search(ctx context.Context, request SearchRequest) (*SearchResponse, error) // SearchWithEngine performs a semantic search over a list of documents with the specified engine. SearchWithEngine(ctx context.Context, engine string, request SearchRequest) (*SearchResponse, error) //UploadFile Uploads a file that contains document(s) to be used across various endpoints/features. UploadFile(ctx context.Context, filename string, purpose string) (*FileUploadResponse, error) //DeleteFile deletes a file from the server-side storage identified by id DeleteFile(ctx context.Context, fileId string) (*FileDeleteResponse, error) //CreateFineTune Creates a job that fine-tunes a specified model from a given dataset. CreateFineTune(ctx context.Context, fileId string) (*FineTuneResponse, error) //CreateFineTuneWithOptions Creates a job that fine-tunes a specified model from a given dataset. CreateFineTuneWithOptions(ctx context.Context, fineTuneOptions FineTuneOptions) (*FineTuneResponse, error) //GetFineTune Gets info about the fine-tune job. GetFineTune(ctx context.Context, id string) (*FineTuneResponse, error) CreateEmbeddings(ctx context.Context, model string, input []string) (*EmbeddingsResponse, error) }
A Client is an API client to communicate with the OpenAI gpt-3 APIs
func NewClient ¶
func NewClient(apiKey string, options ...ClientOption) Client
NewClient returns a new OpenAI GPT-3 API client. An apiKey is required to use the client
type ClientOption ¶
type ClientOption func(*client) error
ClientOption are options that can be passed when creating a new client
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL is a client option that allows you to override the default base url of the client. The default base url is "https://api.openai.com/v1"
func WithDefaultEngine ¶
func WithDefaultEngine(engine string) ClientOption
WithDefaultEngine is a client option that allows you to override the default engine of the client
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient allows you to override the internal http.Client used
func WithOrg ¶
func WithOrg(id string) ClientOption
WithOrg is a client option that allows you to override the organization ID
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout is a client option that allows you to override the default timeout duration of requests for the client. The default is 30 seconds. If you are overriding the http client as well, just include the timeout there.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent is a client option that allows you to override the default user agent of the client
type CompletionRequest ¶
type CompletionRequest struct { // A list of string prompts to use. // TODO there are other prompt types here for using token integers that we could add support for. Prompt string `json:"prompt"` //for edits Suffix *string `json:"suffix"` // How many tokens to complete up to. Max of 512 MaxTokens *int `json:"max_tokens,omitempty"` // Sampling temperature to use Temperature *float32 `json:"temperature,omitempty"` // Alternative to temperature for nucleus sampling TopP *float32 `json:"top_p,omitempty"` // How many choice to create for each prompt N *int `json:"n"` // Include the probabilities of most likely tokens LogProbs *int `json:"logprobs"` // Echo back the prompt in addition to the completion Echo bool `json:"echo"` // Up to 4 sequences where the API will stop generating tokens. Response will not contain the stop sequence. Stop []string `json:"stop,omitempty"` // PresencePenalty number between 0 and 1 that penalizes tokens that have already appeared in the text so far. PresencePenalty float32 `json:"presence_penalty"` // FrequencyPenalty number between 0 and 1 that penalizes tokens on existing frequency in the text so far. FrequencyPenalty float32 `json:"frequency_penalty"` // Whether to stream back results or not. Don't set this value in the request yourself // as it will be overriden depending on if you use CompletionStream or Completion methods. Stream bool `json:"stream,omitempty"` }
CompletionRequest is a request for the completions API
type CompletionResponse ¶
type CompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Created int `json:"created"` Model string `json:"model"` Choices []CompletionResponseChoice `json:"choices"` }
CompletionResponse is the full response from a request to the completions API
type CompletionResponseChoice ¶
type CompletionResponseChoice struct { Text string `json:"text"` Index int `json:"index"` LogProbs LogprobResult `json:"logprobs"` FinishReason string `json:"finish_reason"` }
CompletionResponseChoice is one of the choices returned in the response to the Completions API
type EditsRequest ¶
type EditsRequest struct { // ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them. Model string `json:"model"` // The input text to use as a starting point for the edit. Input string `json:"input"` // The instruction that tells the model how to edit the prompt. Instruction string `json:"instruction"` // Sampling temperature to use Temperature *float32 `json:"temperature,omitempty"` // Alternative to temperature for nucleus sampling TopP *float32 `json:"top_p,omitempty"` // How many edits to generate for the input and instruction. Defaults to 1 N *int `json:"n"` }
EditsRequest is a request for the edits API
type EditsResponse ¶
type EditsResponse struct { Object string `json:"object"` Created int `json:"created"` Choices []EditsResponseChoice `json:"choices"` Usage EditsResponseUsage `json:"usage"` }
EditsResponse is the full response from a request to the edits API
type EditsResponseChoice ¶
EditsResponseChoice is one of the choices returned in the response to the Edits API
type EditsResponseUsage ¶
type EditsResponseUsage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` }
EditsResponseUsage is a structure used in the response from a request to the edits API
type EmbeddingsRequest ¶
type EmbeddingsResponse ¶
type EmbeddingsResponse struct { Object string `json:"object"` Usage EmbeddingsResponseUsage `json:"usage"` Data []Embedding `json:"data"` }
type EmbeddingsResponseUsage ¶
type EmbeddingsResponseUsage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` }
EmbeddingsResponseUsage is a structure used in the response from a request to the edits API
type EngineObject ¶
type EngineObject struct { ID string `json:"id"` Object string `json:"object"` Owner string `json:"owner"` Ready bool `json:"ready"` }
EngineObject contained in an engine reponse
type EnginesResponse ¶
type EnginesResponse struct { Data []EngineObject `json:"data"` Object string `json:"object"` }
EnginesResponse is returned from the Engines API
type FileDeleteResponse ¶
type FileUploadResponse ¶
type FineTuneOptions ¶
type FineTuneOptions struct { TrainingFile string `json:"training_file"` BatchSize int `json:"batch_size"` LearningRateMultiplier float64 `json:"learning_rate_multiplier"` NEpochs int `json:"n_epochs"` PromptLessWeight float64 `json:"prompt_loss_weight"` ComputeClassificatioNMetrics bool `json:"compute_classification_metrics"` ClassificationNClasses *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 FineTuneResponse ¶
type FineTuneResponse struct { ID string `json:"id"` Object string `json:"object"` Model string `json:"model"` CreatedAt int `json:"created_at"` Events []Event `json:"events"` TrainingFiles []File `json:"training_files"` ResultFiles []File `json:"result_files"` ValidationFiles []File `json:"validation_files"` UpdatedAt int `json:"updated_at"` Status string `json:"status"` OrganizationID string `json:"organization_id"` HyperParams HyperParams FineTunedModel *string `json:"fine_tuned_model"` }
type HyperParams ¶
type LogprobResult ¶
type LogprobResult struct { Tokens []string `json:"tokens"` TokenLogprobs []float32 `json:"token_logprobs"` TopLogprobs []map[string]float32 `json:"top_logprobs"` TextOffset []int `json:"text_offset"` }
LogprobResult represents logprob result of Choice
type SearchData ¶
type SearchData struct { Document int `json:"document"` Object string `json:"object"` Score float64 `json:"score"` }
SearchData is a single search result from the document search API
type SearchRequest ¶
SearchRequest is a request for the document search API
type SearchResponse ¶
type SearchResponse struct { Data []SearchData `json:"data"` Object string `json:"object"` }
SearchResponse is the full response from a request to the document search API