Documentation ¶
Overview ¶
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Hello!", }, }, }, ) if err != nil { fmt.Printf("ChatCompletion error: %v\n", err) return } fmt.Println(resp.Choices[0].Message.Content)
Output:
Example (Chatbot) ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) req := openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleSystem, Content: "you are a helpful chatbot", }, }, } fmt.Println("Conversation") fmt.Println("---------------------") fmt.Print("> ") s := bufio.NewScanner(os.Stdin) for s.Scan() { req.Messages = append(req.Messages, openai.ChatCompletionMessage{ Role: openai.ChatMessageRoleUser, Content: s.Text(), }) resp, err := client.CreateChatCompletion(context.Background(), req) if err != nil { fmt.Printf("ChatCompletion error: %v\n", err) continue } fmt.Printf("%s\n\n", resp.Choices[0].Message.Content) req.Messages = append(req.Messages, resp.Choices[0].Message) fmt.Print("> ") }
Output:
Index ¶
- Constants
- Variables
- type APIError
- type APIType
- type Assistant
- type AssistantDeleteResponse
- type AssistantFile
- type AssistantFileRequest
- type AssistantFilesList
- type AssistantRequest
- type AssistantTool
- type AssistantToolCodeInterpreter
- type AssistantToolFileSearch
- type AssistantToolResource
- type AssistantToolType
- type AssistantsList
- type AudioRequest
- type AudioResponse
- type AudioResponseFormat
- type Base64Embedding
- type Batch
- type BatchChatCompletionRequest
- type BatchCompletionRequest
- type BatchEmbeddingRequest
- type BatchEndpoint
- type BatchLineItem
- type BatchRequestCounts
- type BatchResponse
- type ChatCompletionChoice
- type ChatCompletionMessage
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionResponseFormat
- type ChatCompletionResponseFormatJSONSchema
- type ChatCompletionResponseFormatType
- type ChatCompletionStream
- type ChatCompletionStreamChoice
- type ChatCompletionStreamChoiceDelta
- type ChatCompletionStreamResponse
- type ChatMessageImageURL
- type ChatMessagePart
- type ChatMessagePartType
- type ChunkingStrategy
- type ChunkingStrategyType
- type Client
- func (c *Client) CancelBatch(ctx context.Context, batchID string) (response BatchResponse, err error)
- func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error)
- func (c *Client) CancelFineTuningJob(ctx context.Context, fineTuningJobID string) (response FineTuningJob, err error)
- func (c *Client) CancelRun(ctx context.Context, threadID string, runID string) (response Run, err error)
- func (c *Client) CancelVectorStoreFileBatch(ctx context.Context, vectorStoreID string, batchID string) (response VectorStoreFileBatch, err error)
- func (c *Client) CreateAssistant(ctx context.Context, request AssistantRequest) (response Assistant, err error)
- func (c *Client) CreateAssistantFile(ctx context.Context, assistantID string, request AssistantFileRequest) (response AssistantFile, err error)
- func (c *Client) CreateBatch(ctx context.Context, request CreateBatchRequest) (response BatchResponse, err error)
- func (c *Client) CreateBatchWithUploadFile(ctx context.Context, request CreateBatchWithUploadFileRequest) (response BatchResponse, err error)
- func (c *Client) CreateChatCompletion(ctx context.Context, request ChatCompletionRequest) (response ChatCompletionResponse, err error)
- func (c *Client) CreateChatCompletionStream(ctx context.Context, request ChatCompletionRequest) (stream *ChatCompletionStream, err error)
- func (c *Client) CreateCompletion(ctx context.Context, request CompletionRequest) (response CompletionResponse, err error)
- func (c *Client) CreateCompletionStream(ctx context.Context, request CompletionRequest) (stream *CompletionStream, err error)
- func (c *Client) CreateEditImage(ctx context.Context, request ImageEditRequest) (response ImageResponse, err error)
- func (c *Client) CreateEmbeddings(ctx context.Context, conv EmbeddingRequestConverter) (res EmbeddingResponse, err error)
- func (c *Client) CreateFile(ctx context.Context, request FileRequest) (file File, err error)
- func (c *Client) CreateFileBytes(ctx context.Context, request FileBytesRequest) (file File, err error)
- func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (response FineTune, err error)deprecated
- func (c *Client) CreateFineTuningJob(ctx context.Context, request FineTuningJobRequest) (response FineTuningJob, err error)
- func (c *Client) CreateImage(ctx context.Context, request ImageRequest) (response ImageResponse, err error)
- func (c *Client) CreateMessage(ctx context.Context, threadID string, request MessageRequest) (msg Message, err error)
- func (c *Client) CreateRun(ctx context.Context, threadID string, request RunRequest) (response Run, err error)
- func (c *Client) CreateSpeech(ctx context.Context, request CreateSpeechRequest) (response RawResponse, err error)
- func (c *Client) CreateThread(ctx context.Context, request ThreadRequest) (response Thread, err error)
- func (c *Client) CreateThreadAndRun(ctx context.Context, request CreateThreadAndRunRequest) (response Run, err error)
- func (c *Client) CreateTranscription(ctx context.Context, request AudioRequest) (response AudioResponse, err error)
- func (c *Client) CreateTranslation(ctx context.Context, request AudioRequest) (response AudioResponse, err error)
- func (c *Client) CreateVariImage(ctx context.Context, request ImageVariRequest) (response ImageResponse, err error)
- func (c *Client) CreateVectorStore(ctx context.Context, request VectorStoreRequest) (response VectorStore, err error)
- func (c *Client) CreateVectorStoreFile(ctx context.Context, vectorStoreID string, request VectorStoreFileRequest) (response VectorStoreFile, err error)
- func (c *Client) CreateVectorStoreFileBatch(ctx context.Context, vectorStoreID string, request VectorStoreFileBatchRequest) (response VectorStoreFileBatch, err error)
- func (c *Client) DeleteAssistant(ctx context.Context, assistantID string) (response AssistantDeleteResponse, err error)
- func (c *Client) DeleteAssistantFile(ctx context.Context, assistantID string, fileID string) (err error)
- func (c *Client) DeleteFile(ctx context.Context, fileID string) (err error)
- func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (response FineTuneDeleteResponse, err error)deprecated
- func (c *Client) DeleteFineTuneModel(ctx context.Context, modelID string) (response FineTuneModelDeleteResponse, err error)
- func (c *Client) DeleteMessage(ctx context.Context, threadID, messageID string) (status MessageDeletionStatus, err error)
- func (c *Client) DeleteThread(ctx context.Context, threadID string) (response ThreadDeleteResponse, err error)
- func (c *Client) DeleteVectorStore(ctx context.Context, vectorStoreID string) (response VectorStoreDeleteResponse, err error)
- func (c *Client) DeleteVectorStoreFile(ctx context.Context, vectorStoreID string, fileID string) (err error)
- func (c *Client) Edits(ctx context.Context, request EditsRequest) (response EditsResponse, err error)
- func (c *Client) GetEngine(ctx context.Context, engineID string) (engine Engine, err error)
- func (c *Client) GetFile(ctx context.Context, fileID string) (file File, err error)
- func (c *Client) GetFileContent(ctx context.Context, fileID string) (content RawResponse, err error)
- func (c *Client) GetFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error)deprecated
- func (c *Client) GetModel(ctx context.Context, modelID string) (model Model, err error)
- func (c *Client) ListAssistantFiles(ctx context.Context, assistantID string, limit *int, order *string, ...) (response AssistantFilesList, err error)
- func (c *Client) ListAssistants(ctx context.Context, limit *int, order *string, after *string, before *string) (response AssistantsList, err error)
- func (c *Client) ListBatch(ctx context.Context, after *string, limit *int) (response ListBatchResponse, err error)
- func (c *Client) ListEngines(ctx context.Context) (engines EnginesList, err error)
- func (c *Client) ListFiles(ctx context.Context) (files FilesList, err error)
- func (c *Client) ListFineTuneEvents(ctx context.Context, fineTuneID string) (response FineTuneEventList, err error)deprecated
- func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err error)deprecated
- func (c *Client) ListFineTuningJobEvents(ctx context.Context, fineTuningJobID string, ...) (response FineTuningJobEventList, err error)
- func (c *Client) ListMessage(ctx context.Context, threadID string, limit *int, order *string, after *string, ...) (messages MessagesList, err error)
- func (c *Client) ListMessageFiles(ctx context.Context, threadID, messageID string) (files MessageFilesList, err error)
- func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error)
- func (c *Client) ListRunSteps(ctx context.Context, threadID string, runID string, pagination Pagination) (response RunStepList, err error)
- func (c *Client) ListRuns(ctx context.Context, threadID string, pagination Pagination) (response RunList, err error)
- func (c *Client) ListVectorStoreFiles(ctx context.Context, vectorStoreID string, pagination Pagination) (response VectorStoreFilesList, err error)
- func (c *Client) ListVectorStoreFilesInBatch(ctx context.Context, vectorStoreID string, batchID string, ...) (response VectorStoreFilesList, err error)
- func (c *Client) ListVectorStores(ctx context.Context, pagination Pagination) (response VectorStoresList, err error)
- func (c *Client) Moderations(ctx context.Context, request ModerationRequest) (response ModerationResponse, err error)
- func (c *Client) ModifyAssistant(ctx context.Context, assistantID string, request AssistantRequest) (response Assistant, err error)
- func (c *Client) ModifyMessage(ctx context.Context, threadID, messageID string, metadata map[string]string) (msg Message, err error)
- func (c *Client) ModifyRun(ctx context.Context, threadID string, runID string, request RunModifyRequest) (response Run, err error)
- func (c *Client) ModifyThread(ctx context.Context, threadID string, request ModifyThreadRequest) (response Thread, err error)
- func (c *Client) ModifyVectorStore(ctx context.Context, vectorStoreID string, request VectorStoreRequest) (response VectorStore, err error)
- func (c *Client) RetrieveAssistant(ctx context.Context, assistantID string) (response Assistant, err error)
- func (c *Client) RetrieveAssistantFile(ctx context.Context, assistantID string, fileID string) (response AssistantFile, err error)
- func (c *Client) RetrieveBatch(ctx context.Context, batchID string) (response BatchResponse, err error)
- func (c *Client) RetrieveFineTuningJob(ctx context.Context, fineTuningJobID string) (response FineTuningJob, err error)
- func (c *Client) RetrieveMessage(ctx context.Context, threadID, messageID string) (msg Message, err error)
- func (c *Client) RetrieveMessageFile(ctx context.Context, threadID, messageID, fileID string) (file MessageFile, err error)
- func (c *Client) RetrieveRun(ctx context.Context, threadID string, runID string) (response Run, err error)
- func (c *Client) RetrieveRunStep(ctx context.Context, threadID string, runID string, stepID string) (response RunStep, err error)
- func (c *Client) RetrieveThread(ctx context.Context, threadID string) (response Thread, err error)
- func (c *Client) RetrieveVectorStore(ctx context.Context, vectorStoreID string) (response VectorStore, err error)
- func (c *Client) RetrieveVectorStoreFile(ctx context.Context, vectorStoreID string, fileID string) (response VectorStoreFile, err error)
- func (c *Client) RetrieveVectorStoreFileBatch(ctx context.Context, vectorStoreID string, batchID string) (response VectorStoreFileBatch, err error)
- func (c *Client) SubmitToolOutputs(ctx context.Context, threadID string, runID string, ...) (response Run, err error)
- func (c *Client) UploadBatchFile(ctx context.Context, request UploadBatchFileRequest) (File, error)
- type ClientConfig
- type CodeInterpreterToolResources
- type CodeInterpreterToolResourcesRequest
- type CompletionChoice
- type CompletionRequest
- type CompletionResponse
- type CompletionStream
- type CompletionTokensDetails
- type ContentFilterResults
- type CreateBatchRequest
- type CreateBatchWithUploadFileRequest
- type CreateSpeechRequest
- type CreateThreadAndRunRequest
- type EditsChoice
- type EditsRequest
- type EditsResponse
- type Embedding
- type EmbeddingEncodingFormat
- type EmbeddingModel
- type EmbeddingRequest
- type EmbeddingRequestConverter
- type EmbeddingRequestStrings
- type EmbeddingRequestTokens
- type EmbeddingResponse
- type EmbeddingResponseBase64
- type Engine
- type EnginesList
- type ErrorResponse
- type File
- type FileBytesRequest
- type FileRequest
- type FileSearchToolResources
- type FileSearchToolResourcesRequest
- type FilesList
- type FineTunedeprecated
- type FineTuneDeleteResponsedeprecated
- type FineTuneEventdeprecated
- type FineTuneEventListdeprecated
- type FineTuneHyperParamsdeprecated
- type FineTuneListdeprecated
- type FineTuneModelDeleteResponse
- type FineTuneRequestdeprecated
- type FineTuningJob
- type FineTuningJobEvent
- type FineTuningJobEventList
- type FineTuningJobRequest
- type FinishReason
- type FunctionCall
- type FunctionDefinedeprecated
- type FunctionDefinition
- type HTTPDoer
- type Hate
- type Hyperparameters
- type ImageEditRequest
- type ImageFile
- type ImageRequest
- type ImageResponse
- type ImageResponseDataInner
- type ImageURLDetail
- type ImageVariRequest
- type InnerError
- type JailBreak
- type ListBatchResponse
- type ListFineTuningJobEventsParameter
- type LogProb
- type LogProbs
- type LogprobResult
- type Message
- type MessageContent
- type MessageDeletionStatus
- type MessageFile
- type MessageFilesList
- type MessageRequest
- type MessageText
- type MessagesList
- type Model
- type ModelsList
- type ModerationRequest
- type ModerationResponse
- type ModifyThreadRequest
- type Pagination
- type Permission
- type Profanity
- type PromptAnnotation
- type PromptFilterResult
- type PromptTokensDetails
- type PurposeType
- type RateLimitHeaders
- type RawResponse
- type ReponseFormat
- type RequestError
- type RequiredActionType
- type ResetTime
- type Response
- type Result
- type ResultCategories
- type ResultCategoryScores
- type Run
- type RunError
- type RunLastError
- type RunList
- type RunModifyRequest
- type RunRequest
- type RunRequiredAction
- type RunStatus
- type RunStep
- type RunStepList
- type RunStepStatus
- type RunStepType
- type SelfHarm
- type Sexual
- type SpeechModel
- type SpeechResponseFormat
- type SpeechVoice
- type StaticChunkingStrategy
- type StepDetails
- type StepDetailsMessageCreation
- type StreamOptions
- type SubmitToolOutputs
- type SubmitToolOutputsRequest
- type Thread
- type ThreadAttachment
- type ThreadAttachmentTool
- type ThreadDeleteResponse
- type ThreadMessage
- type ThreadMessageRole
- type ThreadRequest
- type ThreadTruncationStrategy
- type Tool
- type ToolCall
- type ToolChoice
- type ToolFunction
- type ToolOutput
- type ToolResources
- type ToolResourcesRequest
- type ToolType
- type TopLogProbs
- type TranscriptionTimestampGranularity
- type TruncationStrategy
- type UploadBatchFileRequest
- func (r *UploadBatchFileRequest) AddChatCompletion(customerID string, body ChatCompletionRequest)
- func (r *UploadBatchFileRequest) AddCompletion(customerID string, body CompletionRequest)
- func (r *UploadBatchFileRequest) AddEmbedding(customerID string, body EmbeddingRequest)
- func (r *UploadBatchFileRequest) MarshalJSONL() []byte
- type Usage
- type VectorStore
- type VectorStoreDeleteResponse
- type VectorStoreExpires
- type VectorStoreFile
- type VectorStoreFileBatch
- type VectorStoreFileBatchRequest
- type VectorStoreFileCount
- type VectorStoreFileRequest
- type VectorStoreFilesList
- type VectorStoreRequest
- type VectorStoreToolResources
- type VectorStoresList
- type Violence
Examples ¶
- Package
- Package (Chatbot)
- APIError
- Client.CreateChatCompletionStream
- Client.CreateCompletion
- Client.CreateCompletionStream
- Client.CreateImage
- Client.CreateImage (Base64)
- Client.CreateTranscription
- Client.CreateTranscription (Captions)
- Client.CreateTranslation
- ClientConfig (ClientWithProxy)
- DefaultAzureConfig
Constants ¶
const ( ChatMessageRoleSystem = "system" ChatMessageRoleUser = "user" ChatMessageRoleAssistant = "assistant" ChatMessageRoleFunction = "function" ChatMessageRoleTool = "tool" )
Chat message role defined by the OpenAI API.
const ( O1Mini = "o1-mini" O1Mini20240912 = "o1-mini-2024-09-12" O1Preview = "o1-preview" O1Preview20240912 = "o1-preview-2024-09-12" GPT432K0613 = "gpt-4-32k-0613" GPT432K0314 = "gpt-4-32k-0314" GPT432K = "gpt-4-32k" GPT40613 = "gpt-4-0613" GPT40314 = "gpt-4-0314" GPT4o = "gpt-4o" GPT4o20240513 = "gpt-4o-2024-05-13" GPT4o20240806 = "gpt-4o-2024-08-06" GPT4oLatest = "chatgpt-4o-latest" GPT4oMini = "gpt-4o-mini" GPT4oMini20240718 = "gpt-4o-mini-2024-07-18" GPT4Turbo = "gpt-4-turbo" GPT4Turbo20240409 = "gpt-4-turbo-2024-04-09" GPT4Turbo0125 = "gpt-4-0125-preview" GPT4Turbo1106 = "gpt-4-1106-preview" GPT4TurboPreview = "gpt-4-turbo-preview" GPT4VisionPreview = "gpt-4-vision-preview" GPT4 = "gpt-4" GPT3Dot5Turbo0125 = "gpt-3.5-turbo-0125" GPT3Dot5Turbo1106 = "gpt-3.5-turbo-1106" GPT3Dot5Turbo0613 = "gpt-3.5-turbo-0613" GPT3Dot5Turbo0301 = "gpt-3.5-turbo-0301" GPT3Dot5Turbo16K = "gpt-3.5-turbo-16k" GPT3Dot5Turbo16K0613 = "gpt-3.5-turbo-16k-0613" GPT3Dot5Turbo = "gpt-3.5-turbo" GPT3Dot5TurboInstruct = "gpt-3.5-turbo-instruct" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3TextDavinci003 = "text-davinci-003" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3TextDavinci002 = "text-davinci-002" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3TextCurie001 = "text-curie-001" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3TextBabbage001 = "text-babbage-001" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3TextAda001 = "text-ada-001" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3TextDavinci001 = "text-davinci-001" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3DavinciInstructBeta = "davinci-instruct-beta" // Deprecated: Model is shutdown. Use davinci-002 instead. GPT3Davinci = "davinci" GPT3Davinci002 = "davinci-002" // Deprecated: Model is shutdown. Use gpt-3.5-turbo-instruct instead. GPT3CurieInstructBeta = "curie-instruct-beta" GPT3Curie = "curie" GPT3Curie002 = "curie-002" // Deprecated: Model is shutdown. Use babbage-002 instead. GPT3Ada = "ada" GPT3Ada002 = "ada-002" // Deprecated: Model is shutdown. Use babbage-002 instead. GPT3Babbage = "babbage" GPT3Babbage002 = "babbage-002" )
GPT3 Defines the models provided by OpenAI to use when generating completions from OpenAI. GPT3 Models are designed for text-based tasks. For code-specific tasks, please refer to the Codex series of models.
const ( CodexCodeDavinci002 = "code-davinci-002" CodexCodeCushman001 = "code-cushman-001" CodexCodeDavinci001 = "code-davinci-001" )
Codex Defines the models provided by OpenAI. These models are designed for code-specific tasks, and use a different tokenizer which optimizes for whitespace.
const ( CreateImageSize256x256 = "256x256" CreateImageSize512x512 = "512x512" CreateImageSize1024x1024 = "1024x1024" // dall-e-3 supported only. CreateImageSize1792x1024 = "1792x1024" CreateImageSize1024x1792 = "1024x1792" )
Image sizes defined by the OpenAI API.
const ( CreateImageResponseFormatURL = "url" CreateImageResponseFormatB64JSON = "b64_json" )
const ( CreateImageModelDallE2 = "dall-e-2" CreateImageModelDallE3 = "dall-e-3" )
const ( CreateImageQualityHD = "hd" CreateImageQualityStandard = "standard" )
const ( CreateImageStyleVivid = "vivid" CreateImageStyleNatural = "natural" )
const ( ModerationTextStable = "text-moderation-stable" ModerationTextLatest = "text-moderation-latest" // Deprecated: use ModerationTextStable and ModerationTextLatest instead. ModerationText001 = "text-moderation-001" )
The default is text-moderation-latest which will be automatically upgraded over time. This ensures you are always using our most accurate model. If you use text-moderation-stable, we will provide advanced notice before updating the model. Accuracy of text-moderation-stable may be slightly lower than for text-moderation-latest.
const ( // TruncationStrategyAuto messages in the middle of the thread will be dropped to fit the context length of the model. TruncationStrategyAuto = TruncationStrategy("auto") // TruncationStrategyLastMessages the thread will be truncated to the n most recent messages in the thread. TruncationStrategyLastMessages = TruncationStrategy("last_messages") )
const AzureAPIKeyHeader = "api-key"
const (
Whisper1 = "whisper-1"
)
Whisper Defines the models provided by OpenAI to use when processing audio with OpenAI.
Variables ¶
var ( ErrChatCompletionInvalidModel = errors.New("this model is not supported with this method, please use CreateCompletion client method instead") //nolint:lll ErrChatCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateChatCompletionStream") //nolint:lll ErrContentFieldsMisused = errors.New("can't use both Content and MultiContent properties simultaneously") )
var ( ErrO1MaxTokensDeprecated = errors.New("this model is not supported MaxTokens, please use MaxCompletionTokens") //nolint:lll ErrCompletionUnsupportedModel = errors.New("this model is not supported with this method, please use CreateChatCompletion client method instead") //nolint:lll ErrCompletionStreamNotSupported = errors.New("streaming is not supported with this method, please use CreateCompletionStream") //nolint:lll ErrCompletionRequestPromptTypeNotSupported = errors.New("the type of CompletionRequest.Prompt only supports string and []string") //nolint:lll )
var ( ErrO1BetaLimitationsMessageTypes = errors.New("this model has beta-limitations, user and assistant messages only, system messages are not supported") //nolint:lll ErrO1BetaLimitationsStreaming = errors.New("this model has beta-limitations, streaming not supported") //nolint:lll ErrO1BetaLimitationsTools = errors.New("this model has beta-limitations, tools, function calling, and response format parameters are not supported") //nolint:lll ErrO1BetaLimitationsLogprobs = errors.New("this model has beta-limitations, logprobs not supported") //nolint:lll ErrO1BetaLimitationsOther = errors.New("this model has beta-limitations, temperature, top_p and n are fixed at 1, while presence_penalty and frequency_penalty are fixed at 0") //nolint:lll )
var (
ErrModerationInvalidModel = errors.New("this model is not supported with moderation, please use text-moderation-stable or text-moderation-latest instead") //nolint:lll
)
var (
ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages")
)
var ErrVectorLengthMismatch = errors.New("vector length mismatch")
var O1SeriesModels = map[string]struct{}{ O1Mini: {}, O1Mini20240912: {}, O1Preview: {}, O1Preview20240912: {}, }
O1SeriesModels List of new Series of OpenAI models. Some old api attributes not supported.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { Code any `json:"code,omitempty"` Message string `json:"message"` Param *string `json:"param,omitempty"` Type string `json:"type"` HTTPStatus string `json:"-"` HTTPStatusCode int `json:"-"` InnerError *InnerError `json:"innererror,omitempty"` }
APIError provides error information returned by the OpenAI API. InnerError struct is only valid for Azure OpenAI Service.
Example ¶
Open-AI maintains clear documentation on how to handle API errors.
see: https://platform.openai.com/docs/guides/error-codes/api-errors
var err error // Assume this is the error you are checking. e := &openai.APIError{} if errors.As(err, &e) { switch e.HTTPStatusCode { case 401: // invalid auth or key (do not retry) case 429: // rate limiting or engine overload (wait and retry) case 500: // openai server error (retry) default: // unhandled } }
Output:
func (*APIError) UnmarshalJSON ¶
type Assistant ¶
type Assistant struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` Model string `json:"model"` Instructions *string `json:"instructions,omitempty"` Tools []AssistantTool `json:"tools"` FileIDs []string `json:"file_ids,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` ToolResources *AssistantToolResource `json:"tool_resources,omitempty"` // contains filtered or unexported fields }
func (*Assistant) GetRateLimitHeaders ¶
func (h *Assistant) GetRateLimitHeaders() RateLimitHeaders
type AssistantDeleteResponse ¶
type AssistantDeleteResponse struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` // contains filtered or unexported fields }
func (*AssistantDeleteResponse) GetRateLimitHeaders ¶
func (h *AssistantDeleteResponse) GetRateLimitHeaders() RateLimitHeaders
type AssistantFile ¶
type AssistantFile struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` AssistantID string `json:"assistant_id"` // contains filtered or unexported fields }
func (*AssistantFile) GetRateLimitHeaders ¶
func (h *AssistantFile) GetRateLimitHeaders() RateLimitHeaders
type AssistantFileRequest ¶
type AssistantFileRequest struct {
FileID string `json:"file_id"`
}
type AssistantFilesList ¶
type AssistantFilesList struct { AssistantFiles []AssistantFile `json:"data"` // contains filtered or unexported fields }
func (*AssistantFilesList) GetRateLimitHeaders ¶
func (h *AssistantFilesList) GetRateLimitHeaders() RateLimitHeaders
type AssistantRequest ¶
type AssistantRequest struct { Model string `json:"model"` Name *string `json:"name,omitempty"` Description *string `json:"description,omitempty"` Instructions *string `json:"instructions,omitempty"` Tools []AssistantTool `json:"-"` FileIDs []string `json:"file_ids,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` ToolResources *AssistantToolResource `json:"tool_resources,omitempty"` ResponseFormat any `json:"response_format,omitempty"` Temperature *float32 `json:"temperature,omitempty"` TopP *float32 `json:"top_p,omitempty"` }
AssistantRequest provides the assistant request parameters. When modifying the tools the API functions as the following: If Tools is undefined, no changes are made to the Assistant's tools. If Tools is empty slice it will effectively delete all of the Assistant's tools. If Tools is populated, it will replace all of the existing Assistant's tools with the provided tools.
func (AssistantRequest) MarshalJSON ¶
func (a AssistantRequest) MarshalJSON() ([]byte, error)
MarshalJSON provides a custom marshaller for the assistant request to handle the API use cases If Tools is nil, the field is omitted from the JSON. If Tools is an empty slice, it's included in the JSON as an empty array ([]). If Tools is populated, it's included in the JSON with the elements.
type AssistantTool ¶
type AssistantTool struct { Type AssistantToolType `json:"type"` Function *FunctionDefinition `json:"function,omitempty"` }
type AssistantToolCodeInterpreter ¶
type AssistantToolCodeInterpreter struct {
FileIDs []string `json:"file_ids"`
}
type AssistantToolFileSearch ¶
type AssistantToolFileSearch struct {
VectorStoreIDs []string `json:"vector_store_ids"`
}
type AssistantToolResource ¶
type AssistantToolResource struct { FileSearch *AssistantToolFileSearch `json:"file_search,omitempty"` CodeInterpreter *AssistantToolCodeInterpreter `json:"code_interpreter,omitempty"` }
type AssistantToolType ¶
type AssistantToolType string
const ( AssistantToolTypeCodeInterpreter AssistantToolType = "code_interpreter" AssistantToolTypeRetrieval AssistantToolType = "retrieval" AssistantToolTypeFunction AssistantToolType = "function" AssistantToolTypeFileSearch AssistantToolType = "file_search" )
type AssistantsList ¶
type AssistantsList struct { Assistants []Assistant `json:"data"` LastID *string `json:"last_id"` FirstID *string `json:"first_id"` HasMore bool `json:"has_more"` // contains filtered or unexported fields }
AssistantsList is a list of assistants.
func (*AssistantsList) GetRateLimitHeaders ¶
func (h *AssistantsList) GetRateLimitHeaders() RateLimitHeaders
type AudioRequest ¶
type AudioRequest struct { Model string // FilePath is either an existing file in your filesystem or a filename representing the contents of Reader. FilePath string // Reader is an optional io.Reader when you do not want to use an existing file. Reader io.Reader Prompt string Temperature float32 Language string // Only for transcription. Format AudioResponseFormat TimestampGranularities []TranscriptionTimestampGranularity // Only for transcription. }
AudioRequest represents a request structure for audio API.
func (AudioRequest) HasJSONResponse ¶
func (r AudioRequest) HasJSONResponse() bool
HasJSONResponse returns true if the response format is JSON.
type AudioResponse ¶
type AudioResponse struct { Task string `json:"task"` Language string `json:"language"` Duration float64 `json:"duration"` Segments []struct { ID int `json:"id"` Seek int `json:"seek"` Start float64 `json:"start"` End float64 `json:"end"` Text string `json:"text"` Tokens []int `json:"tokens"` Temperature float64 `json:"temperature"` AvgLogprob float64 `json:"avg_logprob"` CompressionRatio float64 `json:"compression_ratio"` NoSpeechProb float64 `json:"no_speech_prob"` Transient bool `json:"transient"` } `json:"segments"` Words []struct { Word string `json:"word"` Start float64 `json:"start"` End float64 `json:"end"` } `json:"words"` Text string `json:"text"` // contains filtered or unexported fields }
AudioResponse represents a response structure for audio API.
func (*AudioResponse) GetRateLimitHeaders ¶
func (h *AudioResponse) GetRateLimitHeaders() RateLimitHeaders
type AudioResponseFormat ¶
type AudioResponseFormat string
Response formats; Whisper uses AudioResponseFormatJSON by default.
const ( AudioResponseFormatJSON AudioResponseFormat = "json" AudioResponseFormatText AudioResponseFormat = "text" AudioResponseFormatSRT AudioResponseFormat = "srt" AudioResponseFormatVerboseJSON AudioResponseFormat = "verbose_json" AudioResponseFormatVTT AudioResponseFormat = "vtt" )
type Base64Embedding ¶
type Base64Embedding struct { Object string `json:"object"` Embedding base64String `json:"embedding"` Index int `json:"index"` }
Base64Embedding is a container for base64 encoded embeddings.
type Batch ¶
type Batch struct { ID string `json:"id"` Object string `json:"object"` Endpoint BatchEndpoint `json:"endpoint"` Errors *struct { Object string `json:"object,omitempty"` Data []struct { Code string `json:"code,omitempty"` Message string `json:"message,omitempty"` Param *string `json:"param,omitempty"` Line *int `json:"line,omitempty"` } `json:"data"` } `json:"errors"` InputFileID string `json:"input_file_id"` CompletionWindow string `json:"completion_window"` Status string `json:"status"` OutputFileID *string `json:"output_file_id"` ErrorFileID *string `json:"error_file_id"` CreatedAt int `json:"created_at"` InProgressAt *int `json:"in_progress_at"` ExpiresAt *int `json:"expires_at"` FinalizingAt *int `json:"finalizing_at"` CompletedAt *int `json:"completed_at"` FailedAt *int `json:"failed_at"` ExpiredAt *int `json:"expired_at"` CancellingAt *int `json:"cancelling_at"` CancelledAt *int `json:"cancelled_at"` RequestCounts BatchRequestCounts `json:"request_counts"` Metadata map[string]any `json:"metadata"` }
type BatchChatCompletionRequest ¶
type BatchChatCompletionRequest struct { CustomID string `json:"custom_id"` Body ChatCompletionRequest `json:"body"` Method string `json:"method"` URL BatchEndpoint `json:"url"` }
func (BatchChatCompletionRequest) MarshalBatchLineItem ¶
func (r BatchChatCompletionRequest) MarshalBatchLineItem() []byte
type BatchCompletionRequest ¶
type BatchCompletionRequest struct { CustomID string `json:"custom_id"` Body CompletionRequest `json:"body"` Method string `json:"method"` URL BatchEndpoint `json:"url"` }
func (BatchCompletionRequest) MarshalBatchLineItem ¶
func (r BatchCompletionRequest) MarshalBatchLineItem() []byte
type BatchEmbeddingRequest ¶
type BatchEmbeddingRequest struct { CustomID string `json:"custom_id"` Body EmbeddingRequest `json:"body"` Method string `json:"method"` URL BatchEndpoint `json:"url"` }
func (BatchEmbeddingRequest) MarshalBatchLineItem ¶
func (r BatchEmbeddingRequest) MarshalBatchLineItem() []byte
type BatchEndpoint ¶
type BatchEndpoint string
const ( BatchEndpointChatCompletions BatchEndpoint = "/v1/chat/completions" BatchEndpointCompletions BatchEndpoint = "/v1/completions" BatchEndpointEmbeddings BatchEndpoint = "/v1/embeddings" )
type BatchLineItem ¶
type BatchLineItem interface {
MarshalBatchLineItem() []byte
}
type BatchRequestCounts ¶
type BatchResponse ¶
type BatchResponse struct { Batch // contains filtered or unexported fields }
func (*BatchResponse) GetRateLimitHeaders ¶
func (h *BatchResponse) GetRateLimitHeaders() RateLimitHeaders
type ChatCompletionChoice ¶
type ChatCompletionChoice struct { Index int `json:"index"` Message ChatCompletionMessage `json:"message"` // FinishReason // stop: API returned complete message, // or a message terminated by one of the stop sequences provided via the stop parameter // length: Incomplete model output due to max_tokens parameter or token limit // function_call: The model decided to call a function // content_filter: Omitted content due to a flag from our content filters // null: API response still in progress or incomplete FinishReason FinishReason `json:"finish_reason"` LogProbs *LogProbs `json:"logprobs,omitempty"` ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"` }
type ChatCompletionMessage ¶
type ChatCompletionMessage struct { Role string `json:"role"` Content string `json:"content"` Refusal string `json:"refusal,omitempty"` MultiContent []ChatMessagePart // This property isn't in the official documentation, but it's in // the documentation for the official library for python: // - https://github.com/openai/openai-python/blob/main/chatml.md // - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb Name string `json:"name,omitempty"` FunctionCall *FunctionCall `json:"function_call,omitempty"` // For Role=assistant prompts this may be set to the tool calls generated by the model, such as function calls. ToolCalls []ToolCall `json:"tool_calls,omitempty"` // For Role=tool prompts this should be set to the ID given in the assistant's prior request to call a tool. ToolCallID string `json:"tool_call_id,omitempty"` }
func (ChatCompletionMessage) MarshalJSON ¶
func (m ChatCompletionMessage) MarshalJSON() ([]byte, error)
func (*ChatCompletionMessage) UnmarshalJSON ¶
func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error
type ChatCompletionRequest ¶
type ChatCompletionRequest struct { Model string `json:"model"` Messages []ChatCompletionMessage `json:"messages"` // MaxTokens The maximum number of tokens that can be generated in the chat completion. // This value can be used to control costs for text generated via API. // This value is now deprecated in favor of max_completion_tokens, and is not compatible with o1 series models. // refs: https://platform.openai.com/docs/api-reference/chat/create#chat-create-max_tokens MaxTokens int `json:"max_tokens,omitempty"` // MaxCompletionTokens An upper bound for the number of tokens that can be generated for a completion, // including visible output tokens and reasoning tokens https://platform.openai.com/docs/guides/reasoning MaxCompletionTokens int `json:"max_completion_tokens,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` N int `json:"n,omitempty"` Stream bool `json:"stream,omitempty"` Stop []string `json:"stop,omitempty"` PresencePenalty float32 `json:"presence_penalty,omitempty"` ResponseFormat *ChatCompletionResponseFormat `json:"response_format,omitempty"` Seed *int `json:"seed,omitempty"` FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string. // incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}` // refs: https://platform.openai.com/docs/api-reference/chat/create#chat/create-logit_bias LogitBias map[string]int `json:"logit_bias,omitempty"` // LogProbs indicates whether to return log probabilities of the output tokens or not. // If true, returns the log probabilities of each output token returned in the content of message. // This option is currently not available on the gpt-4-vision-preview model. LogProbs bool `json:"logprobs,omitempty"` // TopLogProbs is an integer between 0 and 5 specifying the number of most likely tokens to return at each // token position, each with an associated log probability. // logprobs must be set to true if this parameter is used. TopLogProbs int `json:"top_logprobs,omitempty"` User string `json:"user,omitempty"` // Deprecated: use Tools instead. Functions []FunctionDefinition `json:"functions,omitempty"` // Deprecated: use ToolChoice instead. FunctionCall any `json:"function_call,omitempty"` Tools []Tool `json:"tools,omitempty"` // This can be either a string or an ToolChoice object. ToolChoice any `json:"tool_choice,omitempty"` // Options for streaming response. Only set this when you set stream: true. StreamOptions *StreamOptions `json:"stream_options,omitempty"` // Disable the default behavior of parallel tool calls by setting it: false. ParallelToolCalls any `json:"parallel_tool_calls,omitempty"` }
ChatCompletionRequest represents a request structure for chat completion API.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Model string `json:"model"` Choices []ChatCompletionChoice `json:"choices"` Usage Usage `json:"usage"` SystemFingerprint string `json:"system_fingerprint"` PromptFilterResults []PromptFilterResult `json:"prompt_filter_results,omitempty"` // contains filtered or unexported fields }
ChatCompletionResponse represents a response structure for chat completion API.
func (*ChatCompletionResponse) GetRateLimitHeaders ¶
func (h *ChatCompletionResponse) GetRateLimitHeaders() RateLimitHeaders
type ChatCompletionResponseFormat ¶
type ChatCompletionResponseFormat struct { Type ChatCompletionResponseFormatType `json:"type,omitempty"` JSONSchema *ChatCompletionResponseFormatJSONSchema `json:"json_schema,omitempty"` }
type ChatCompletionResponseFormatType ¶
type ChatCompletionResponseFormatType string
const ( ChatCompletionResponseFormatTypeJSONObject ChatCompletionResponseFormatType = "json_object" ChatCompletionResponseFormatTypeJSONSchema ChatCompletionResponseFormatType = "json_schema" ChatCompletionResponseFormatTypeText ChatCompletionResponseFormatType = "text" )
type ChatCompletionStream ¶
type ChatCompletionStream struct {
// contains filtered or unexported fields
}
ChatCompletionStream Note: Perhaps it is more elegant to abstract Stream using generics.
type ChatCompletionStreamChoice ¶
type ChatCompletionStreamChoice struct { Index int `json:"index"` Delta ChatCompletionStreamChoiceDelta `json:"delta"` FinishReason FinishReason `json:"finish_reason"` ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"` }
type ChatCompletionStreamChoiceDelta ¶
type ChatCompletionStreamChoiceDelta struct { Content string `json:"content,omitempty"` Role string `json:"role,omitempty"` FunctionCall *FunctionCall `json:"function_call,omitempty"` ToolCalls []ToolCall `json:"tool_calls,omitempty"` }
type ChatCompletionStreamResponse ¶
type ChatCompletionStreamResponse struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Model string `json:"model"` Choices []ChatCompletionStreamChoice `json:"choices"` SystemFingerprint string `json:"system_fingerprint"` PromptAnnotations []PromptAnnotation `json:"prompt_annotations,omitempty"` PromptFilterResults []PromptFilterResult `json:"prompt_filter_results,omitempty"` // An optional field that will only be present when you set stream_options: {"include_usage": true} in your request. // When present, it contains a null value except for the last chunk which contains the token usage statistics // for the entire request. Usage *Usage `json:"usage,omitempty"` }
type ChatMessageImageURL ¶
type ChatMessageImageURL struct { URL string `json:"url,omitempty"` Detail ImageURLDetail `json:"detail,omitempty"` }
type ChatMessagePart ¶
type ChatMessagePart struct { Type ChatMessagePartType `json:"type,omitempty"` Text string `json:"text,omitempty"` ImageURL *ChatMessageImageURL `json:"image_url,omitempty"` }
type ChatMessagePartType ¶
type ChatMessagePartType string
const ( ChatMessagePartTypeText ChatMessagePartType = "text" ChatMessagePartTypeImageURL ChatMessagePartType = "image_url" )
type ChunkingStrategy ¶
type ChunkingStrategy struct { Type ChunkingStrategyType `json:"type"` Static *StaticChunkingStrategy `json:"static,omitempty"` }
type ChunkingStrategyType ¶
type ChunkingStrategyType string
const ( ChunkingStrategyTypeAuto ChunkingStrategyType = "auto" ChunkingStrategyTypeStatic ChunkingStrategyType = "static" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is OpenAI GPT-3 API client.
func NewClientWithConfig ¶
func NewClientWithConfig(config ClientConfig) *Client
NewClientWithConfig creates new OpenAI API client for specified config.
func NewOrgClient
deprecated
func (*Client) CancelBatch ¶
func (c *Client) CancelBatch( ctx context.Context, batchID string, ) (response BatchResponse, err error)
CancelBatch — API call to Cancel batch.
func (*Client) CancelFineTune ¶
func (c *Client) CancelFineTune(ctx context.Context, fineTuneID string) (response FineTune, err error)
CancelFineTune cancel a fine-tune job. Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*Client) CancelFineTuningJob ¶
func (c *Client) CancelFineTuningJob(ctx context.Context, fineTuningJobID string) (response FineTuningJob, err error)
CancelFineTuningJob cancel a fine tuning job.
func (*Client) CancelRun ¶
func (c *Client) CancelRun( ctx context.Context, threadID string, runID string) (response Run, err error)
CancelRun cancels a run.
func (*Client) CancelVectorStoreFileBatch ¶
func (c *Client) CancelVectorStoreFileBatch( ctx context.Context, vectorStoreID string, batchID string, ) (response VectorStoreFileBatch, err error)
CancelVectorStoreFileBatch cancel a new vector store file batch.
func (*Client) CreateAssistant ¶
func (c *Client) CreateAssistant(ctx context.Context, request AssistantRequest) (response Assistant, err error)
CreateAssistant creates a new assistant.
func (*Client) CreateAssistantFile ¶
func (c *Client) CreateAssistantFile( ctx context.Context, assistantID string, request AssistantFileRequest, ) (response AssistantFile, err error)
CreateAssistantFile creates a new assistant file.
func (*Client) CreateBatch ¶
func (c *Client) CreateBatch( ctx context.Context, request CreateBatchRequest, ) (response BatchResponse, err error)
CreateBatch — API call to Create batch.
func (*Client) CreateBatchWithUploadFile ¶
func (c *Client) CreateBatchWithUploadFile( ctx context.Context, request CreateBatchWithUploadFileRequest, ) (response BatchResponse, err error)
CreateBatchWithUploadFile — API call to Create batch with upload file.
func (*Client) CreateChatCompletion ¶
func (c *Client) CreateChatCompletion( ctx context.Context, request ChatCompletionRequest, ) (response ChatCompletionResponse, err error)
CreateChatCompletion — API call to Create a completion for the chat message.
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, request ChatCompletionRequest, ) (stream *ChatCompletionStream, err error)
CreateChatCompletionStream — API call to create a chat completion w/ streaming support. It sets whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) stream, err := client.CreateChatCompletionStream( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo, MaxTokens: 20, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Lorem ipsum", }, }, Stream: true, }, ) if err != nil { fmt.Printf("ChatCompletionStream error: %v\n", err) return } defer stream.Close() fmt.Print("Stream response: ") for { var response openai.ChatCompletionStreamResponse response, err = stream.Recv() if errors.Is(err, io.EOF) { fmt.Println("\nStream finished") return } if err != nil { fmt.Printf("\nStream error: %v\n", err) return } fmt.Println(response.Choices[0].Delta.Content) }
Output:
func (*Client) CreateCompletion ¶
func (c *Client) CreateCompletion( ctx context.Context, request CompletionRequest, ) (response CompletionResponse, err error)
CreateCompletion — API call to create a completion. This is the main endpoint of the API. Returns new text as well as, if requested, the probabilities over each alternative token at each position.
If using a fine-tuned model, simply provide the model's ID in the CompletionRequest object, and the server will use the model's parameters to generate the completion.
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) resp, err := client.CreateCompletion( context.Background(), openai.CompletionRequest{ Model: openai.GPT3Babbage002, MaxTokens: 5, Prompt: "Lorem ipsum", }, ) if err != nil { fmt.Printf("Completion error: %v\n", err) return } fmt.Println(resp.Choices[0].Text)
Output:
func (*Client) CreateCompletionStream ¶
func (c *Client) CreateCompletionStream( ctx context.Context, request CompletionRequest, ) (stream *CompletionStream, err error)
CreateCompletionStream — API call to create a completion w/ streaming support. It sets whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) stream, err := client.CreateCompletionStream( context.Background(), openai.CompletionRequest{ Model: openai.GPT3Babbage002, MaxTokens: 5, Prompt: "Lorem ipsum", Stream: true, }, ) if err != nil { fmt.Printf("CompletionStream error: %v\n", err) return } defer stream.Close() for { var response openai.CompletionResponse response, err = stream.Recv() if errors.Is(err, io.EOF) { fmt.Println("Stream finished") return } if err != nil { fmt.Printf("Stream error: %v\n", err) return } fmt.Printf("Stream response: %#v\n", response) }
Output:
func (*Client) CreateEditImage ¶
func (c *Client) CreateEditImage(ctx context.Context, request ImageEditRequest) (response ImageResponse, err error)
CreateEditImage - API call to create an image. This is the main endpoint of the DALL-E API.
func (*Client) CreateEmbeddings ¶
func (c *Client) CreateEmbeddings( ctx context.Context, conv EmbeddingRequestConverter, ) (res EmbeddingResponse, err error)
CreateEmbeddings returns an EmbeddingResponse which will contain an Embedding for every item in |body.Input|. https://beta.openai.com/docs/api-reference/embeddings/create
Body should be of type EmbeddingRequestStrings for embedding strings or EmbeddingRequestTokens for embedding groups of text already converted to tokens.
func (*Client) CreateFile ¶
CreateFile uploads a jsonl file to GPT3 FilePath must be a local file path.
func (*Client) CreateFileBytes ¶
func (c *Client) CreateFileBytes(ctx context.Context, request FileBytesRequest) (file File, err error)
CreateFileBytes uploads bytes directly to OpenAI without requiring a local file.
func (*Client) CreateFineTune
deprecated
func (c *Client) CreateFineTune(ctx context.Context, request FineTuneRequest) (response FineTune, err error)
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*Client) CreateFineTuningJob ¶
func (c *Client) CreateFineTuningJob( ctx context.Context, request FineTuningJobRequest, ) (response FineTuningJob, err error)
CreateFineTuningJob create a fine tuning job.
func (*Client) CreateImage ¶
func (c *Client) CreateImage(ctx context.Context, request ImageRequest) (response ImageResponse, err error)
CreateImage - API call to create an image. This is the main endpoint of the DALL-E API.
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) respURL, err := client.CreateImage( context.Background(), openai.ImageRequest{ Prompt: "Parrot on a skateboard performs a trick, cartoon style, natural light, high detail", Size: openai.CreateImageSize256x256, ResponseFormat: openai.CreateImageResponseFormatURL, N: 1, }, ) if err != nil { fmt.Printf("Image creation error: %v\n", err) return } fmt.Println(respURL.Data[0].URL)
Output:
Example (Base64) ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) resp, err := client.CreateImage( context.Background(), openai.ImageRequest{ Prompt: "Portrait of a humanoid parrot in a classic costume, high detail, realistic light, unreal engine", Size: openai.CreateImageSize512x512, ResponseFormat: openai.CreateImageResponseFormatB64JSON, N: 1, }, ) if err != nil { fmt.Printf("Image creation error: %v\n", err) return } b, err := base64.StdEncoding.DecodeString(resp.Data[0].B64JSON) if err != nil { fmt.Printf("Base64 decode error: %v\n", err) return } f, err := os.Create("example.png") if err != nil { fmt.Printf("File creation error: %v\n", err) return } defer f.Close() _, err = f.Write(b) if err != nil { fmt.Printf("File write error: %v\n", err) return } fmt.Println("The image was saved as example.png")
Output:
func (*Client) CreateMessage ¶
func (c *Client) CreateMessage(ctx context.Context, threadID string, request MessageRequest) (msg Message, err error)
CreateMessage creates a new message.
func (*Client) CreateRun ¶
func (c *Client) CreateRun( ctx context.Context, threadID string, request RunRequest, ) (response Run, err error)
CreateRun creates a new run.
func (*Client) CreateSpeech ¶
func (c *Client) CreateSpeech(ctx context.Context, request CreateSpeechRequest) (response RawResponse, err error)
func (*Client) CreateThread ¶
func (c *Client) CreateThread(ctx context.Context, request ThreadRequest) (response Thread, err error)
CreateThread creates a new thread.
func (*Client) CreateThreadAndRun ¶
func (c *Client) CreateThreadAndRun( ctx context.Context, request CreateThreadAndRunRequest) (response Run, err error)
CreateThreadAndRun submits tool outputs.
func (*Client) CreateTranscription ¶
func (c *Client) CreateTranscription( ctx context.Context, request AudioRequest, ) (response AudioResponse, err error)
CreateTranscription — API call to create a transcription. Returns transcribed text.
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) resp, err := client.CreateTranscription( context.Background(), openai.AudioRequest{ Model: openai.Whisper1, FilePath: "recording.mp3", }, ) if err != nil { fmt.Printf("Transcription error: %v\n", err) return } fmt.Println(resp.Text)
Output:
Example (Captions) ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) resp, err := client.CreateTranscription( context.Background(), openai.AudioRequest{ Model: openai.Whisper1, FilePath: os.Args[1], Format: openai.AudioResponseFormatSRT, }, ) if err != nil { fmt.Printf("Transcription error: %v\n", err) return } f, err := os.Create(os.Args[1] + ".srt") if err != nil { fmt.Printf("Could not open file: %v\n", err) return } defer f.Close() if _, err = f.WriteString(resp.Text); err != nil { fmt.Printf("Error writing to file: %v\n", err) return }
Output:
func (*Client) CreateTranslation ¶
func (c *Client) CreateTranslation( ctx context.Context, request AudioRequest, ) (response AudioResponse, err error)
CreateTranslation — API call to translate audio into English.
Example ¶
client := openai.NewClient(os.Getenv("OPENAI_API_KEY")) resp, err := client.CreateTranslation( context.Background(), openai.AudioRequest{ Model: openai.Whisper1, FilePath: "recording.mp3", }, ) if err != nil { fmt.Printf("Translation error: %v\n", err) return } fmt.Println(resp.Text)
Output:
func (*Client) CreateVariImage ¶
func (c *Client) CreateVariImage(ctx context.Context, request ImageVariRequest) (response ImageResponse, err error)
CreateVariImage - API call to create an image variation. This is the main endpoint of the DALL-E API. Use abbreviations(vari for variation) because ci-lint has a single-line length limit ...
func (*Client) CreateVectorStore ¶
func (c *Client) CreateVectorStore(ctx context.Context, request VectorStoreRequest) (response VectorStore, err error)
CreateVectorStore creates a new vector store.
func (*Client) CreateVectorStoreFile ¶
func (c *Client) CreateVectorStoreFile( ctx context.Context, vectorStoreID string, request VectorStoreFileRequest, ) (response VectorStoreFile, err error)
CreateVectorStoreFile creates a new vector store file.
func (*Client) CreateVectorStoreFileBatch ¶
func (c *Client) CreateVectorStoreFileBatch( ctx context.Context, vectorStoreID string, request VectorStoreFileBatchRequest, ) (response VectorStoreFileBatch, err error)
CreateVectorStoreFileBatch creates a new vector store file batch.
func (*Client) DeleteAssistant ¶
func (c *Client) DeleteAssistant( ctx context.Context, assistantID string, ) (response AssistantDeleteResponse, err error)
DeleteAssistant deletes an assistant.
func (*Client) DeleteAssistantFile ¶
func (c *Client) DeleteAssistantFile( ctx context.Context, assistantID string, fileID string, ) (err error)
DeleteAssistantFile deletes an existing file.
func (*Client) DeleteFile ¶
DeleteFile deletes an existing file.
func (*Client) DeleteFineTune
deprecated
func (c *Client) DeleteFineTune(ctx context.Context, fineTuneID string) (response FineTuneDeleteResponse, err error)
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*Client) DeleteFineTuneModel ¶
func (c *Client) DeleteFineTuneModel(ctx context.Context, modelID string) ( response FineTuneModelDeleteResponse, err error)
DeleteFineTuneModel Deletes a fine-tune model. You must have the Owner role in your organization to delete a model.
func (*Client) DeleteMessage ¶
func (c *Client) DeleteMessage( ctx context.Context, threadID, messageID string, ) (status MessageDeletionStatus, err error)
DeleteMessage deletes a message..
func (*Client) DeleteThread ¶
func (c *Client) DeleteThread( ctx context.Context, threadID string, ) (response ThreadDeleteResponse, err error)
DeleteThread deletes a thread.
func (*Client) DeleteVectorStore ¶
func (c *Client) DeleteVectorStore( ctx context.Context, vectorStoreID string, ) (response VectorStoreDeleteResponse, err error)
DeleteVectorStore deletes an vector store.
func (*Client) DeleteVectorStoreFile ¶
func (c *Client) DeleteVectorStoreFile( ctx context.Context, vectorStoreID string, fileID string, ) (err error)
DeleteVectorStoreFile deletes an existing file.
func (*Client) Edits ¶
func (c *Client) Edits(ctx context.Context, request EditsRequest) (response EditsResponse, err error)
Edits Perform an API call to the Edits endpoint.
Deprecated: Users of the Edits API and its associated models (e.g., text-davinci-edit-001 or code-davinci-edit-001)
will need to migrate to GPT-3.5 Turbo by January 4, 2024. You can use CreateChatCompletion or CreateChatCompletionStream instead.
func (*Client) GetEngine ¶
GetEngine Retrieves an engine instance, providing basic information about the engine such as the owner and availability.
func (*Client) GetFile ¶
GetFile Retrieves a file instance, providing basic information about the file such as the file name and purpose.
func (*Client) GetFileContent ¶
func (*Client) GetFineTune
deprecated
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*Client) GetModel ¶
GetModel Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
func (*Client) ListAssistantFiles ¶
func (c *Client) ListAssistantFiles( ctx context.Context, assistantID string, limit *int, order *string, after *string, before *string, ) (response AssistantFilesList, err error)
ListAssistantFiles Lists the currently available files for an assistant.
func (*Client) ListAssistants ¶
func (c *Client) ListAssistants( ctx context.Context, limit *int, order *string, after *string, before *string, ) (response AssistantsList, err error)
ListAssistants Lists the currently available assistants.
func (*Client) ListBatch ¶
func (c *Client) ListBatch(ctx context.Context, after *string, limit *int) (response ListBatchResponse, err error)
ListBatch API call to List batch.
func (*Client) ListEngines ¶
func (c *Client) ListEngines(ctx context.Context) (engines EnginesList, err error)
ListEngines Lists the currently available engines, and provides basic information about each option such as the owner and availability.
func (*Client) ListFiles ¶
ListFiles Lists the currently available files, and provides basic information about each file such as the file name and purpose.
func (*Client) ListFineTuneEvents
deprecated
func (c *Client) ListFineTuneEvents(ctx context.Context, fineTuneID string) (response FineTuneEventList, err error)
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*Client) ListFineTunes
deprecated
func (c *Client) ListFineTunes(ctx context.Context) (response FineTuneList, err error)
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*Client) ListFineTuningJobEvents ¶
func (c *Client) ListFineTuningJobEvents( ctx context.Context, fineTuningJobID string, setters ...ListFineTuningJobEventsParameter, ) (response FineTuningJobEventList, err error)
ListFineTuningJobs list fine tuning jobs events.
func (*Client) ListMessage ¶
func (c *Client) ListMessage(ctx context.Context, threadID string, limit *int, order *string, after *string, before *string, runID *string, ) (messages MessagesList, err error)
ListMessage fetches all messages in the thread.
func (*Client) ListMessageFiles ¶
func (c *Client) ListMessageFiles( ctx context.Context, threadID, messageID string, ) (files MessageFilesList, err error)
ListMessageFiles fetches all files attached to a message.
func (*Client) ListModels ¶
func (c *Client) ListModels(ctx context.Context) (models ModelsList, err error)
ListModels Lists the currently available models, and provides basic information about each model such as the model id and parent.
func (*Client) ListRunSteps ¶
func (c *Client) ListRunSteps( ctx context.Context, threadID string, runID string, pagination Pagination, ) (response RunStepList, err error)
ListRunSteps lists run steps.
func (*Client) ListRuns ¶
func (c *Client) ListRuns( ctx context.Context, threadID string, pagination Pagination, ) (response RunList, err error)
ListRuns lists runs.
func (*Client) ListVectorStoreFiles ¶
func (c *Client) ListVectorStoreFiles( ctx context.Context, vectorStoreID string, pagination Pagination, ) (response VectorStoreFilesList, err error)
ListVectorStoreFiles Lists the currently available files for a vector store.
func (*Client) ListVectorStoreFilesInBatch ¶
func (c *Client) ListVectorStoreFilesInBatch( ctx context.Context, vectorStoreID string, batchID string, pagination Pagination, ) (response VectorStoreFilesList, err error)
ListVectorStoreFiles Lists the currently available files for a vector store.
func (*Client) ListVectorStores ¶
func (c *Client) ListVectorStores( ctx context.Context, pagination Pagination, ) (response VectorStoresList, err error)
ListVectorStores Lists the currently available vector store.
func (*Client) Moderations ¶
func (c *Client) Moderations(ctx context.Context, request ModerationRequest) (response ModerationResponse, err error)
Moderations — perform a moderation api call over a string. Input can be an array or slice but a string will reduce the complexity.
func (*Client) ModifyAssistant ¶
func (c *Client) ModifyAssistant( ctx context.Context, assistantID string, request AssistantRequest, ) (response Assistant, err error)
ModifyAssistant modifies an assistant.
func (*Client) ModifyMessage ¶
func (c *Client) ModifyMessage( ctx context.Context, threadID, messageID string, metadata map[string]string, ) (msg Message, err error)
ModifyMessage modifies a message.
func (*Client) ModifyRun ¶
func (c *Client) ModifyRun( ctx context.Context, threadID string, runID string, request RunModifyRequest, ) (response Run, err error)
ModifyRun modifies a run.
func (*Client) ModifyThread ¶
func (c *Client) ModifyThread( ctx context.Context, threadID string, request ModifyThreadRequest, ) (response Thread, err error)
ModifyThread modifies a thread.
func (*Client) ModifyVectorStore ¶
func (c *Client) ModifyVectorStore( ctx context.Context, vectorStoreID string, request VectorStoreRequest, ) (response VectorStore, err error)
ModifyVectorStore modifies a vector store.
func (*Client) RetrieveAssistant ¶
func (c *Client) RetrieveAssistant( ctx context.Context, assistantID string, ) (response Assistant, err error)
RetrieveAssistant retrieves an assistant.
func (*Client) RetrieveAssistantFile ¶
func (c *Client) RetrieveAssistantFile( ctx context.Context, assistantID string, fileID string, ) (response AssistantFile, err error)
RetrieveAssistantFile retrieves an assistant file.
func (*Client) RetrieveBatch ¶
func (c *Client) RetrieveBatch( ctx context.Context, batchID string, ) (response BatchResponse, err error)
RetrieveBatch — API call to Retrieve batch.
func (*Client) RetrieveFineTuningJob ¶
func (c *Client) RetrieveFineTuningJob( ctx context.Context, fineTuningJobID string, ) (response FineTuningJob, err error)
RetrieveFineTuningJob retrieve a fine tuning job.
func (*Client) RetrieveMessage ¶
func (c *Client) RetrieveMessage( ctx context.Context, threadID, messageID string, ) (msg Message, err error)
RetrieveMessage retrieves a Message.
func (*Client) RetrieveMessageFile ¶
func (c *Client) RetrieveMessageFile( ctx context.Context, threadID, messageID, fileID string, ) (file MessageFile, err error)
RetrieveMessageFile fetches a message file.
func (*Client) RetrieveRun ¶
func (c *Client) RetrieveRun( ctx context.Context, threadID string, runID string, ) (response Run, err error)
RetrieveRun retrieves a run.
func (*Client) RetrieveRunStep ¶
func (c *Client) RetrieveRunStep( ctx context.Context, threadID string, runID string, stepID string, ) (response RunStep, err error)
RetrieveRunStep retrieves a run step.
func (*Client) RetrieveThread ¶
RetrieveThread retrieves a thread.
func (*Client) RetrieveVectorStore ¶
func (c *Client) RetrieveVectorStore( ctx context.Context, vectorStoreID string, ) (response VectorStore, err error)
RetrieveVectorStore retrieves an vector store.
func (*Client) RetrieveVectorStoreFile ¶
func (c *Client) RetrieveVectorStoreFile( ctx context.Context, vectorStoreID string, fileID string, ) (response VectorStoreFile, err error)
RetrieveVectorStoreFile retrieves a vector store file.
func (*Client) RetrieveVectorStoreFileBatch ¶
func (c *Client) RetrieveVectorStoreFileBatch( ctx context.Context, vectorStoreID string, batchID string, ) (response VectorStoreFileBatch, err error)
RetrieveVectorStoreFileBatch retrieves a vector store file batch.
func (*Client) SubmitToolOutputs ¶
func (c *Client) SubmitToolOutputs( ctx context.Context, threadID string, runID string, request SubmitToolOutputsRequest) (response Run, err error)
SubmitToolOutputs submits tool outputs.
func (*Client) UploadBatchFile ¶
UploadBatchFile — upload batch file.
type ClientConfig ¶
type ClientConfig struct { BaseURL string OrgID string APIType APIType APIVersion string // required when APIType is APITypeAzure or APITypeAzureAD AssistantVersion string AzureModelMapperFunc func(model string) string // replace model to azure deployment name func HTTPClient HTTPDoer EmptyMessagesLimit uint // contains filtered or unexported fields }
ClientConfig is a configuration of a client.
Example (ClientWithProxy) ¶
config := openai.DefaultConfig(os.Getenv("OPENAI_API_KEY")) port := os.Getenv("OPENAI_PROXY_PORT") proxyURL, err := url.Parse(fmt.Sprintf("http://localhost:%s", port)) if err != nil { panic(err) } transport := &http.Transport{ Proxy: http.ProxyURL(proxyURL), } config.HTTPClient = &http.Client{ Transport: transport, } client := openai.NewClientWithConfig(config) client.CreateChatCompletion( //nolint:errcheck // outside of the scope of this example. context.Background(), openai.ChatCompletionRequest{ // etc... }, )
Output:
func DefaultAzureConfig ¶
func DefaultAzureConfig(apiKey, baseURL string) ClientConfig
Example ¶
azureKey := os.Getenv("AZURE_OPENAI_API_KEY") // Your azure API key azureEndpoint := os.Getenv("AZURE_OPENAI_ENDPOINT") // Your azure OpenAI endpoint config := openai.DefaultAzureConfig(azureKey, azureEndpoint) client := openai.NewClientWithConfig(config) resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ Model: openai.GPT3Dot5Turbo, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser, Content: "Hello Azure OpenAI!", }, }, }, ) if err != nil { fmt.Printf("ChatCompletion error: %v\n", err) return } fmt.Println(resp.Choices[0].Message.Content)
Output:
func DefaultConfig ¶
func DefaultConfig(authToken string) ClientConfig
func (ClientConfig) GetAzureDeploymentByModel ¶
func (c ClientConfig) GetAzureDeploymentByModel(model string) string
func (ClientConfig) String ¶
func (ClientConfig) String() string
type CodeInterpreterToolResources ¶
type CodeInterpreterToolResources struct {
FileIDs []string `json:"file_ids,omitempty"`
}
type CodeInterpreterToolResourcesRequest ¶
type CodeInterpreterToolResourcesRequest struct {
FileIDs []string `json:"file_ids,omitempty"`
}
type CompletionChoice ¶
type CompletionChoice struct { Text string `json:"text"` Index int `json:"index"` FinishReason string `json:"finish_reason"` LogProbs LogprobResult `json:"logprobs"` }
CompletionChoice represents one of possible completions.
type CompletionRequest ¶
type CompletionRequest struct { Model string `json:"model"` Prompt any `json:"prompt,omitempty"` BestOf int `json:"best_of,omitempty"` Echo bool `json:"echo,omitempty"` FrequencyPenalty float32 `json:"frequency_penalty,omitempty"` // LogitBias is must be a token id string (specified by their token ID in the tokenizer), not a word string. // incorrect: `"logit_bias":{"You": 6}`, correct: `"logit_bias":{"1639": 6}` // refs: https://platform.openai.com/docs/api-reference/completions/create#completions/create-logit_bias LogitBias map[string]int `json:"logit_bias,omitempty"` // Store can be set to true to store the output of this completion request for use in distillations and evals. // https://platform.openai.com/docs/api-reference/chat/create#chat-create-store Store bool `json:"store,omitempty"` LogProbs int `json:"logprobs,omitempty"` MaxTokens int `json:"max_tokens,omitempty"` N int `json:"n,omitempty"` PresencePenalty float32 `json:"presence_penalty,omitempty"` Seed *int `json:"seed,omitempty"` Stop []string `json:"stop,omitempty"` Stream bool `json:"stream,omitempty"` Suffix string `json:"suffix,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` User string `json:"user,omitempty"` }
CompletionRequest represents a request structure for completion API.
type CompletionResponse ¶
type CompletionResponse struct { ID string `json:"id"` Object string `json:"object"` Created int64 `json:"created"` Model string `json:"model"` Choices []CompletionChoice `json:"choices"` Usage Usage `json:"usage"` // contains filtered or unexported fields }
CompletionResponse represents a response structure for completion API.
func (*CompletionResponse) GetRateLimitHeaders ¶
func (h *CompletionResponse) GetRateLimitHeaders() RateLimitHeaders
type CompletionStream ¶
type CompletionStream struct {
// contains filtered or unexported fields
}
type CompletionTokensDetails ¶
type CompletionTokensDetails struct { AudioTokens int `json:"audio_tokens"` ReasoningTokens int `json:"reasoning_tokens"` }
CompletionTokensDetails Breakdown of tokens used in a completion.
type ContentFilterResults ¶
type ContentFilterResults struct { Hate Hate `json:"hate,omitempty"` SelfHarm SelfHarm `json:"self_harm,omitempty"` Sexual Sexual `json:"sexual,omitempty"` Violence Violence `json:"violence,omitempty"` JailBreak JailBreak `json:"jailbreak,omitempty"` Profanity Profanity `json:"profanity,omitempty"` }
type CreateBatchRequest ¶
type CreateBatchRequest struct { InputFileID string `json:"input_file_id"` Endpoint BatchEndpoint `json:"endpoint"` CompletionWindow string `json:"completion_window"` Metadata map[string]any `json:"metadata"` }
type CreateBatchWithUploadFileRequest ¶
type CreateBatchWithUploadFileRequest struct { Endpoint BatchEndpoint `json:"endpoint"` CompletionWindow string `json:"completion_window"` Metadata map[string]any `json:"metadata"` UploadBatchFileRequest }
type CreateSpeechRequest ¶
type CreateSpeechRequest struct { Model SpeechModel `json:"model"` Input string `json:"input"` Voice SpeechVoice `json:"voice"` ResponseFormat SpeechResponseFormat `json:"response_format,omitempty"` // Optional, default to mp3 Speed float64 `json:"speed,omitempty"` // Optional, default to 1.0 }
type CreateThreadAndRunRequest ¶
type CreateThreadAndRunRequest struct { RunRequest Thread ThreadRequest `json:"thread"` }
type EditsChoice ¶
EditsChoice represents one of possible edits.
type EditsRequest ¶
type EditsRequest struct { Model *string `json:"model,omitempty"` Input string `json:"input,omitempty"` Instruction string `json:"instruction,omitempty"` N int `json:"n,omitempty"` Temperature float32 `json:"temperature,omitempty"` TopP float32 `json:"top_p,omitempty"` }
EditsRequest represents a request structure for Edits API.
type EditsResponse ¶
type EditsResponse struct { Object string `json:"object"` Created int64 `json:"created"` Usage Usage `json:"usage"` Choices []EditsChoice `json:"choices"` // contains filtered or unexported fields }
EditsResponse represents a response structure for Edits API.
func (*EditsResponse) GetRateLimitHeaders ¶
func (h *EditsResponse) GetRateLimitHeaders() RateLimitHeaders
type Embedding ¶
type Embedding struct { Object string `json:"object"` Embedding []float32 `json:"embedding"` Index int `json:"index"` }
Embedding is a special format of data representation that can be easily utilized by machine learning models and algorithms. The embedding is an information dense representation of the semantic meaning of a piece of text. Each embedding is a vector of floating point numbers, such that the distance between two embeddings in the vector space is correlated with semantic similarity between two inputs in the original format. For example, if two texts are similar, then their vector representations should also be similar.
func (*Embedding) DotProduct ¶
DotProduct calculates the dot product of the embedding vector with another embedding vector. Both vectors must have the same length; otherwise, an ErrVectorLengthMismatch is returned. The method returns the calculated dot product as a float32 value.
type EmbeddingEncodingFormat ¶
type EmbeddingEncodingFormat string
EmbeddingEncodingFormat is the format of the embeddings data. Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. If not specified OpenAI will use "float".
const ( EmbeddingEncodingFormatFloat EmbeddingEncodingFormat = "float" EmbeddingEncodingFormatBase64 EmbeddingEncodingFormat = "base64" )
type EmbeddingModel ¶
type EmbeddingModel string
EmbeddingModel enumerates the models which can be used to generate Embedding vectors.
const ( // Deprecated: The following block is shut down. Use text-embedding-ada-002 instead. AdaSimilarity EmbeddingModel = "text-similarity-ada-001" BabbageSimilarity EmbeddingModel = "text-similarity-babbage-001" CurieSimilarity EmbeddingModel = "text-similarity-curie-001" DavinciSimilarity EmbeddingModel = "text-similarity-davinci-001" AdaSearchDocument EmbeddingModel = "text-search-ada-doc-001" AdaSearchQuery EmbeddingModel = "text-search-ada-query-001" BabbageSearchDocument EmbeddingModel = "text-search-babbage-doc-001" BabbageSearchQuery EmbeddingModel = "text-search-babbage-query-001" CurieSearchDocument EmbeddingModel = "text-search-curie-doc-001" CurieSearchQuery EmbeddingModel = "text-search-curie-query-001" DavinciSearchDocument EmbeddingModel = "text-search-davinci-doc-001" DavinciSearchQuery EmbeddingModel = "text-search-davinci-query-001" AdaCodeSearchCode EmbeddingModel = "code-search-ada-code-001" AdaCodeSearchText EmbeddingModel = "code-search-ada-text-001" BabbageCodeSearchCode EmbeddingModel = "code-search-babbage-code-001" BabbageCodeSearchText EmbeddingModel = "code-search-babbage-text-001" AdaEmbeddingV2 EmbeddingModel = "text-embedding-ada-002" SmallEmbedding3 EmbeddingModel = "text-embedding-3-small" LargeEmbedding3 EmbeddingModel = "text-embedding-3-large" )
type EmbeddingRequest ¶
type EmbeddingRequest struct { Input any `json:"input"` Model EmbeddingModel `json:"model"` User string `json:"user"` EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` // Dimensions The number of dimensions the resulting output embeddings should have. // Only supported in text-embedding-3 and later models. Dimensions int `json:"dimensions,omitempty"` }
func (EmbeddingRequest) Convert ¶
func (r EmbeddingRequest) Convert() EmbeddingRequest
type EmbeddingRequestConverter ¶
type EmbeddingRequestConverter interface { // Needs to be of type EmbeddingRequestStrings or EmbeddingRequestTokens Convert() EmbeddingRequest }
type EmbeddingRequestStrings ¶
type EmbeddingRequestStrings struct { // Input is a slice of strings for which you want to generate an Embedding vector. // Each input must not exceed 8192 tokens in length. // OpenAPI suggests replacing newlines (\n) in your input with a single space, as they // have observed inferior results when newlines are present. // E.g. // "The food was delicious and the waiter..." Input []string `json:"input"` // 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 EmbeddingModel `json:"model"` // A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. User string `json:"user"` // EmbeddingEncodingFormat is the format of the embeddings data. // Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. // If not specified OpenAI will use "float". EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` // Dimensions The number of dimensions the resulting output embeddings should have. // Only supported in text-embedding-3 and later models. Dimensions int `json:"dimensions,omitempty"` }
EmbeddingRequestStrings is the input to a create embeddings request with a slice of strings.
func (EmbeddingRequestStrings) Convert ¶
func (r EmbeddingRequestStrings) Convert() EmbeddingRequest
type EmbeddingRequestTokens ¶
type EmbeddingRequestTokens struct { // Input is a slice of slices of ints ([][]int) for which you want to generate an Embedding vector. // Each input must not exceed 8192 tokens in length. // OpenAPI suggests replacing newlines (\n) in your input with a single space, as they // have observed inferior results when newlines are present. // E.g. // "The food was delicious and the waiter..." Input [][]int `json:"input"` // 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 EmbeddingModel `json:"model"` // A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. User string `json:"user"` // EmbeddingEncodingFormat is the format of the embeddings data. // Currently, only "float" and "base64" are supported, however, "base64" is not officially documented. // If not specified OpenAI will use "float". EncodingFormat EmbeddingEncodingFormat `json:"encoding_format,omitempty"` // Dimensions The number of dimensions the resulting output embeddings should have. // Only supported in text-embedding-3 and later models. Dimensions int `json:"dimensions,omitempty"` }
func (EmbeddingRequestTokens) Convert ¶
func (r EmbeddingRequestTokens) Convert() EmbeddingRequest
type EmbeddingResponse ¶
type EmbeddingResponse struct { Object string `json:"object"` Data []Embedding `json:"data"` Model EmbeddingModel `json:"model"` Usage Usage `json:"usage"` // contains filtered or unexported fields }
EmbeddingResponse is the response from a Create embeddings request.
func (*EmbeddingResponse) GetRateLimitHeaders ¶
func (h *EmbeddingResponse) GetRateLimitHeaders() RateLimitHeaders
type EmbeddingResponseBase64 ¶
type EmbeddingResponseBase64 struct { Object string `json:"object"` Data []Base64Embedding `json:"data"` Model EmbeddingModel `json:"model"` Usage Usage `json:"usage"` // contains filtered or unexported fields }
EmbeddingResponseBase64 is the response from a Create embeddings request with base64 encoding format.
func (*EmbeddingResponseBase64) GetRateLimitHeaders ¶
func (h *EmbeddingResponseBase64) GetRateLimitHeaders() RateLimitHeaders
func (*EmbeddingResponseBase64) ToEmbeddingResponse ¶
func (r *EmbeddingResponseBase64) ToEmbeddingResponse() (EmbeddingResponse, error)
ToEmbeddingResponse converts an embeddingResponseBase64 to an EmbeddingResponse.
type Engine ¶
type Engine struct { ID string `json:"id"` Object string `json:"object"` Owner string `json:"owner"` Ready bool `json:"ready"` // contains filtered or unexported fields }
Engine struct represents engine from OpenAPI API.
func (*Engine) GetRateLimitHeaders ¶
func (h *Engine) GetRateLimitHeaders() RateLimitHeaders
type EnginesList ¶
type EnginesList struct { Engines []Engine `json:"data"` // contains filtered or unexported fields }
EnginesList is a list of engines.
func (*EnginesList) GetRateLimitHeaders ¶
func (h *EnginesList) GetRateLimitHeaders() RateLimitHeaders
type ErrorResponse ¶
type ErrorResponse struct {
Error *APIError `json:"error,omitempty"`
}
type File ¶
type File struct { Bytes int `json:"bytes"` CreatedAt int64 `json:"created_at"` ID string `json:"id"` FileName string `json:"filename"` Object string `json:"object"` Status string `json:"status"` Purpose string `json:"purpose"` StatusDetails string `json:"status_details"` // contains filtered or unexported fields }
File struct represents an OpenAPI file.
func (*File) GetRateLimitHeaders ¶
func (h *File) GetRateLimitHeaders() RateLimitHeaders
type FileBytesRequest ¶
type FileBytesRequest struct { // the name of the uploaded file in OpenAI Name string // the bytes of the file Bytes []byte // the purpose of the file Purpose PurposeType }
FileBytesRequest represents a file upload request.
type FileRequest ¶
type FileSearchToolResources ¶
type FileSearchToolResources struct {
VectorStoreIDs []string `json:"vector_store_ids,omitempty"`
}
type FileSearchToolResourcesRequest ¶
type FileSearchToolResourcesRequest struct { VectorStoreIDs []string `json:"vector_store_ids,omitempty"` VectorStores []VectorStoreToolResources `json:"vector_stores,omitempty"` }
type FilesList ¶
type FilesList struct { Files []File `json:"data"` // contains filtered or unexported fields }
FilesList is a list of files that belong to the user or organization.
func (*FilesList) GetRateLimitHeaders ¶
func (h *FilesList) GetRateLimitHeaders() RateLimitHeaders
type FineTune
deprecated
type FineTune struct { ID string `json:"id"` Object string `json:"object"` Model string `json:"model"` CreatedAt int64 `json:"created_at"` FineTuneEventList []FineTuneEvent `json:"events,omitempty"` FineTunedModel string `json:"fine_tuned_model"` HyperParams FineTuneHyperParams `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"` // contains filtered or unexported fields }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*FineTune) GetRateLimitHeaders ¶
func (h *FineTune) GetRateLimitHeaders() RateLimitHeaders
type FineTuneDeleteResponse
deprecated
type FineTuneDeleteResponse struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` // contains filtered or unexported fields }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*FineTuneDeleteResponse) GetRateLimitHeaders ¶
func (h *FineTuneDeleteResponse) GetRateLimitHeaders() RateLimitHeaders
type FineTuneEvent
deprecated
type FineTuneEvent struct { Object string `json:"object"` CreatedAt int64 `json:"created_at"` Level string `json:"level"` Message string `json:"message"` }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
type FineTuneEventList
deprecated
type FineTuneEventList struct { Object string `json:"object"` Data []FineTuneEvent `json:"data"` // contains filtered or unexported fields }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*FineTuneEventList) GetRateLimitHeaders ¶
func (h *FineTuneEventList) GetRateLimitHeaders() RateLimitHeaders
type FineTuneHyperParams
deprecated
type FineTuneHyperParams struct { BatchSize int `json:"batch_size"` LearningRateMultiplier float64 `json:"learning_rate_multiplier"` Epochs int `json:"n_epochs"` PromptLossWeight float64 `json:"prompt_loss_weight"` }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
type FineTuneList
deprecated
type FineTuneList struct { Object string `json:"object"` Data []FineTune `json:"data"` // contains filtered or unexported fields }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
func (*FineTuneList) GetRateLimitHeaders ¶
func (h *FineTuneList) GetRateLimitHeaders() RateLimitHeaders
type FineTuneModelDeleteResponse ¶
type FineTuneModelDeleteResponse struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` // contains filtered or unexported fields }
FineTuneModelDeleteResponse represents the deletion status of a fine-tuned model.
func (*FineTuneModelDeleteResponse) GetRateLimitHeaders ¶
func (h *FineTuneModelDeleteResponse) GetRateLimitHeaders() RateLimitHeaders
type FineTuneRequest
deprecated
type FineTuneRequest struct { TrainingFile string `json:"training_file"` ValidationFile string `json:"validation_file,omitempty"` Model string `json:"model,omitempty"` Epochs int `json:"n_epochs,omitempty"` BatchSize int `json:"batch_size,omitempty"` LearningRateMultiplier float32 `json:"learning_rate_multiplier,omitempty"` PromptLossRate float32 `json:"prompt_loss_rate,omitempty"` ComputeClassificationMetrics bool `json:"compute_classification_metrics,omitempty"` ClassificationClasses int `json:"classification_n_classes,omitempty"` ClassificationPositiveClass string `json:"classification_positive_class,omitempty"` ClassificationBetas []float32 `json:"classification_betas,omitempty"` Suffix string `json:"suffix,omitempty"` }
Deprecated: On August 22nd, 2023, OpenAI announced the deprecation of the /v1/fine-tunes API. This API will be officially deprecated on January 4th, 2024. OpenAI recommends to migrate to the new fine tuning API implemented in fine_tuning_job.go.
type FineTuningJob ¶
type FineTuningJob struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` FinishedAt int64 `json:"finished_at"` Model string `json:"model"` FineTunedModel string `json:"fine_tuned_model,omitempty"` OrganizationID string `json:"organization_id"` Status string `json:"status"` Hyperparameters Hyperparameters `json:"hyperparameters"` TrainingFile string `json:"training_file"` ValidationFile string `json:"validation_file,omitempty"` ResultFiles []string `json:"result_files"` TrainedTokens int `json:"trained_tokens"` // contains filtered or unexported fields }
func (*FineTuningJob) GetRateLimitHeaders ¶
func (h *FineTuningJob) GetRateLimitHeaders() RateLimitHeaders
type FineTuningJobEvent ¶
type FineTuningJobEventList ¶
type FineTuningJobEventList struct { Object string `json:"object"` Data []FineTuneEvent `json:"data"` HasMore bool `json:"has_more"` // contains filtered or unexported fields }
func (*FineTuningJobEventList) GetRateLimitHeaders ¶
func (h *FineTuningJobEventList) GetRateLimitHeaders() RateLimitHeaders
type FineTuningJobRequest ¶
type FineTuningJobRequest struct { TrainingFile string `json:"training_file"` ValidationFile string `json:"validation_file,omitempty"` Model string `json:"model,omitempty"` Hyperparameters *Hyperparameters `json:"hyperparameters,omitempty"` Suffix string `json:"suffix,omitempty"` }
type FinishReason ¶
type FinishReason string
const ( FinishReasonStop FinishReason = "stop" FinishReasonLength FinishReason = "length" FinishReasonFunctionCall FinishReason = "function_call" FinishReasonToolCalls FinishReason = "tool_calls" FinishReasonContentFilter FinishReason = "content_filter" FinishReasonNull FinishReason = "null" )
func (FinishReason) MarshalJSON ¶
func (r FinishReason) MarshalJSON() ([]byte, error)
type FunctionCall ¶
type FunctionDefine
deprecated
type FunctionDefine = FunctionDefinition
Deprecated: use FunctionDefinition instead.
type FunctionDefinition ¶
type FunctionDefinition struct { Name string `json:"name"` Description string `json:"description,omitempty"` Strict bool `json:"strict,omitempty"` // Parameters is an object describing the function. // You can pass json.RawMessage to describe the schema, // or you can pass in a struct which serializes to the proper JSON schema. // The jsonschema package is provided for convenience, but you should // consider another specialized library if you require more complex schemas. Parameters any `json:"parameters"` }
type Hyperparameters ¶
type ImageEditRequest ¶
type ImageEditRequest struct { Image *os.File `json:"image,omitempty"` Mask *os.File `json:"mask,omitempty"` Prompt string `json:"prompt,omitempty"` Model string `json:"model,omitempty"` N int `json:"n,omitempty"` Size string `json:"size,omitempty"` ResponseFormat string `json:"response_format,omitempty"` }
ImageEditRequest represents the request structure for the image API.
type ImageRequest ¶
type ImageRequest struct { Prompt string `json:"prompt,omitempty"` Model string `json:"model,omitempty"` N int `json:"n,omitempty"` Quality string `json:"quality,omitempty"` Size string `json:"size,omitempty"` Style string `json:"style,omitempty"` ResponseFormat string `json:"response_format,omitempty"` User string `json:"user,omitempty"` }
ImageRequest represents the request structure for the image API.
type ImageResponse ¶
type ImageResponse struct { Created int64 `json:"created,omitempty"` Data []ImageResponseDataInner `json:"data,omitempty"` // contains filtered or unexported fields }
ImageResponse represents a response structure for image API.
func (*ImageResponse) GetRateLimitHeaders ¶
func (h *ImageResponse) GetRateLimitHeaders() RateLimitHeaders
type ImageResponseDataInner ¶
type ImageResponseDataInner struct { URL string `json:"url,omitempty"` B64JSON string `json:"b64_json,omitempty"` RevisedPrompt string `json:"revised_prompt,omitempty"` }
ImageResponseDataInner represents a response data structure for image API.
type ImageURLDetail ¶
type ImageURLDetail string
const ( ImageURLDetailHigh ImageURLDetail = "high" ImageURLDetailLow ImageURLDetail = "low" ImageURLDetailAuto ImageURLDetail = "auto" )
type ImageVariRequest ¶
type ImageVariRequest struct { Image *os.File `json:"image,omitempty"` Model string `json:"model,omitempty"` N int `json:"n,omitempty"` Size string `json:"size,omitempty"` ResponseFormat string `json:"response_format,omitempty"` }
ImageVariRequest represents the request structure for the image API.
type InnerError ¶
type InnerError struct { Code string `json:"code,omitempty"` ContentFilterResults ContentFilterResults `json:"content_filter_result,omitempty"` }
InnerError Azure Content filtering. Only valid for Azure OpenAI Service.
type ListBatchResponse ¶
type ListBatchResponse struct { Object string `json:"object"` Data []Batch `json:"data"` FirstID string `json:"first_id"` LastID string `json:"last_id"` HasMore bool `json:"has_more"` // contains filtered or unexported fields }
func (*ListBatchResponse) GetRateLimitHeaders ¶
func (h *ListBatchResponse) GetRateLimitHeaders() RateLimitHeaders
type ListFineTuningJobEventsParameter ¶
type ListFineTuningJobEventsParameter func(*listFineTuningJobEventsParameters)
func ListFineTuningJobEventsWithAfter ¶
func ListFineTuningJobEventsWithAfter(after string) ListFineTuningJobEventsParameter
func ListFineTuningJobEventsWithLimit ¶
func ListFineTuningJobEventsWithLimit(limit int) ListFineTuningJobEventsParameter
type LogProb ¶
type LogProb struct { Token string `json:"token"` LogProb float64 `json:"logprob"` Bytes []byte `json:"bytes,omitempty"` // Omitting the field if it is null // TopLogProbs is a list of the most likely tokens and their log probability, at this token position. // In rare cases, there may be fewer than the number of requested top_logprobs returned. TopLogProbs []TopLogProbs `json:"top_logprobs"` }
LogProb represents the probability information for a token.
type LogProbs ¶
type LogProbs struct { // Content is a list of message content tokens with log probability information. Content []LogProb `json:"content"` }
LogProbs is the top-level structure containing the log probability information.
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 Message ¶
type Message struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int `json:"created_at"` ThreadID string `json:"thread_id"` Role string `json:"role"` Content []MessageContent `json:"content"` FileIds []string `json:"file_ids"` //nolint:revive //backwards-compatibility AssistantID *string `json:"assistant_id,omitempty"` RunID *string `json:"run_id,omitempty"` Metadata map[string]any `json:"metadata"` // contains filtered or unexported fields }
func (*Message) GetRateLimitHeaders ¶
func (h *Message) GetRateLimitHeaders() RateLimitHeaders
type MessageContent ¶
type MessageContent struct { Type string `json:"type"` Text *MessageText `json:"text,omitempty"` ImageFile *ImageFile `json:"image_file,omitempty"` }
type MessageDeletionStatus ¶
type MessageDeletionStatus struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` // contains filtered or unexported fields }
func (*MessageDeletionStatus) GetRateLimitHeaders ¶
func (h *MessageDeletionStatus) GetRateLimitHeaders() RateLimitHeaders
type MessageFile ¶
type MessageFile struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int `json:"created_at"` MessageID string `json:"message_id"` // contains filtered or unexported fields }
func (*MessageFile) GetRateLimitHeaders ¶
func (h *MessageFile) GetRateLimitHeaders() RateLimitHeaders
type MessageFilesList ¶
type MessageFilesList struct { MessageFiles []MessageFile `json:"data"` // contains filtered or unexported fields }
func (*MessageFilesList) GetRateLimitHeaders ¶
func (h *MessageFilesList) GetRateLimitHeaders() RateLimitHeaders
type MessageRequest ¶
type MessageText ¶
type MessagesList ¶
type MessagesList struct { Messages []Message `json:"data"` Object string `json:"object"` FirstID *string `json:"first_id"` LastID *string `json:"last_id"` HasMore bool `json:"has_more"` // contains filtered or unexported fields }
func (*MessagesList) GetRateLimitHeaders ¶
func (h *MessagesList) GetRateLimitHeaders() RateLimitHeaders
type Model ¶
type Model struct { CreatedAt int64 `json:"created"` ID string `json:"id"` Object string `json:"object"` OwnedBy string `json:"owned_by"` Permission []Permission `json:"permission"` Root string `json:"root"` Parent string `json:"parent"` // contains filtered or unexported fields }
Model struct represents an OpenAPI model.
func (*Model) GetRateLimitHeaders ¶
func (h *Model) GetRateLimitHeaders() RateLimitHeaders
type ModelsList ¶
type ModelsList struct { Models []Model `json:"data"` // contains filtered or unexported fields }
ModelsList is a list of models, including those that belong to the user or organization.
func (*ModelsList) GetRateLimitHeaders ¶
func (h *ModelsList) GetRateLimitHeaders() RateLimitHeaders
type ModerationRequest ¶
type ModerationRequest struct { Input string `json:"input,omitempty"` Model string `json:"model,omitempty"` }
ModerationRequest represents a request structure for moderation API.
type ModerationResponse ¶
type ModerationResponse struct { ID string `json:"id"` Model string `json:"model"` Results []Result `json:"results"` // contains filtered or unexported fields }
ModerationResponse represents a response structure for moderation API.
func (*ModerationResponse) GetRateLimitHeaders ¶
func (h *ModerationResponse) GetRateLimitHeaders() RateLimitHeaders
type ModifyThreadRequest ¶
type ModifyThreadRequest struct { Metadata map[string]any `json:"metadata"` ToolResources *ToolResources `json:"tool_resources,omitempty"` }
type Permission ¶
type Permission struct { CreatedAt int64 `json:"created"` ID string `json:"id"` Object string `json:"object"` AllowCreateEngine bool `json:"allow_create_engine"` AllowSampling bool `json:"allow_sampling"` AllowLogprobs bool `json:"allow_logprobs"` AllowSearchIndices bool `json:"allow_search_indices"` AllowView bool `json:"allow_view"` AllowFineTuning bool `json:"allow_fine_tuning"` Organization string `json:"organization"` Group interface{} `json:"group"` IsBlocking bool `json:"is_blocking"` }
Permission struct represents an OpenAPI permission.
type PromptAnnotation ¶
type PromptAnnotation struct { PromptIndex int `json:"prompt_index,omitempty"` ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"` }
type PromptFilterResult ¶
type PromptFilterResult struct { Index int `json:"index"` ContentFilterResults ContentFilterResults `json:"content_filter_results,omitempty"` }
type PromptTokensDetails ¶
type PromptTokensDetails struct { AudioTokens int `json:"audio_tokens"` CachedTokens int `json:"cached_tokens"` }
PromptTokensDetails Breakdown of tokens used in the prompt.
type PurposeType ¶
type PurposeType string
PurposeType represents the purpose of the file when uploading.
const ( PurposeFineTune PurposeType = "fine-tune" PurposeFineTuneResults PurposeType = "fine-tune-results" PurposeAssistants PurposeType = "assistants" PurposeAssistantsOutput PurposeType = "assistants_output" PurposeBatch PurposeType = "batch" )
type RateLimitHeaders ¶
type RateLimitHeaders struct { LimitRequests int `json:"x-ratelimit-limit-requests"` LimitTokens int `json:"x-ratelimit-limit-tokens"` RemainingRequests int `json:"x-ratelimit-remaining-requests"` RemainingTokens int `json:"x-ratelimit-remaining-tokens"` ResetRequests ResetTime `json:"x-ratelimit-reset-requests"` ResetTokens ResetTime `json:"x-ratelimit-reset-tokens"` }
RateLimitHeaders struct represents Openai rate limits headers.
type RawResponse ¶
type RawResponse struct { io.ReadCloser // contains filtered or unexported fields }
func (*RawResponse) GetRateLimitHeaders ¶
func (h *RawResponse) GetRateLimitHeaders() RateLimitHeaders
type ReponseFormat ¶
type ReponseFormat struct {
Type string `json:"type"`
}
ReponseFormat specifies the format the model must output. https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-response_format. Type can either be text or json_object.
type RequestError ¶
RequestError provides information about generic request errors.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
func (*RequestError) Unwrap ¶
func (e *RequestError) Unwrap() error
type RequiredActionType ¶
type RequiredActionType string
const (
RequiredActionTypeSubmitToolOutputs RequiredActionType = "submit_tool_outputs"
)
type Result ¶
type Result struct { Categories ResultCategories `json:"categories"` CategoryScores ResultCategoryScores `json:"category_scores"` Flagged bool `json:"flagged"` }
Result represents one of possible moderation results.
type ResultCategories ¶
type ResultCategories struct { Hate bool `json:"hate"` HateThreatening bool `json:"hate/threatening"` Harassment bool `json:"harassment"` HarassmentThreatening bool `json:"harassment/threatening"` SelfHarm bool `json:"self-harm"` SelfHarmIntent bool `json:"self-harm/intent"` SelfHarmInstructions bool `json:"self-harm/instructions"` Sexual bool `json:"sexual"` SexualMinors bool `json:"sexual/minors"` Violence bool `json:"violence"` ViolenceGraphic bool `json:"violence/graphic"` }
ResultCategories represents Categories of Result.
type ResultCategoryScores ¶
type ResultCategoryScores struct { Hate float32 `json:"hate"` HateThreatening float32 `json:"hate/threatening"` Harassment float32 `json:"harassment"` HarassmentThreatening float32 `json:"harassment/threatening"` SelfHarm float32 `json:"self-harm"` SelfHarmIntent float32 `json:"self-harm/intent"` SelfHarmInstructions float32 `json:"self-harm/instructions"` Sexual float32 `json:"sexual"` SexualMinors float32 `json:"sexual/minors"` Violence float32 `json:"violence"` ViolenceGraphic float32 `json:"violence/graphic"` }
ResultCategoryScores represents CategoryScores of Result.
type Run ¶
type Run struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` ThreadID string `json:"thread_id"` AssistantID string `json:"assistant_id"` Status RunStatus `json:"status"` RequiredAction *RunRequiredAction `json:"required_action,omitempty"` LastError *RunLastError `json:"last_error,omitempty"` ExpiresAt int64 `json:"expires_at"` StartedAt *int64 `json:"started_at,omitempty"` CancelledAt *int64 `json:"cancelled_at,omitempty"` FailedAt *int64 `json:"failed_at,omitempty"` CompletedAt *int64 `json:"completed_at,omitempty"` Model string `json:"model"` Instructions string `json:"instructions,omitempty"` Tools []Tool `json:"tools"` FileIDS []string `json:"file_ids"` //nolint:revive // backwards-compatibility Metadata map[string]any `json:"metadata"` Usage Usage `json:"usage,omitempty"` Temperature *float32 `json:"temperature,omitempty"` // The maximum number of prompt tokens that may be used over the course of the run. // If the run exceeds the number of prompt tokens specified, the run will end with status 'incomplete'. MaxPromptTokens int `json:"max_prompt_tokens,omitempty"` // The maximum number of completion tokens that may be used over the course of the run. // If the run exceeds the number of completion tokens specified, the run will end with status 'incomplete'. MaxCompletionTokens int `json:"max_completion_tokens,omitempty"` // ThreadTruncationStrategy defines the truncation strategy to use for the thread. TruncationStrategy *ThreadTruncationStrategy `json:"truncation_strategy,omitempty"` // contains filtered or unexported fields }
func (*Run) GetRateLimitHeaders ¶
func (h *Run) GetRateLimitHeaders() RateLimitHeaders
type RunLastError ¶
type RunList ¶
type RunList struct { Runs []Run `json:"data"` // contains filtered or unexported fields }
RunList is a list of runs.
func (*RunList) GetRateLimitHeaders ¶
func (h *RunList) GetRateLimitHeaders() RateLimitHeaders
type RunModifyRequest ¶
type RunRequest ¶
type RunRequest struct { AssistantID string `json:"assistant_id"` Model string `json:"model,omitempty"` Instructions string `json:"instructions,omitempty"` AdditionalInstructions string `json:"additional_instructions,omitempty"` Tools []Tool `json:"tools,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` // Sampling temperature between 0 and 2. Higher values like 0.8 are more random. // lower values are more focused and deterministic. Temperature *float32 `json:"temperature,omitempty"` TopP *float32 `json:"top_p,omitempty"` // The maximum number of prompt tokens that may be used over the course of the run. // If the run exceeds the number of prompt tokens specified, the run will end with status 'incomplete'. MaxPromptTokens int `json:"max_prompt_tokens,omitempty"` // The maximum number of completion tokens that may be used over the course of the run. // If the run exceeds the number of completion tokens specified, the run will end with status 'incomplete'. MaxCompletionTokens int `json:"max_completion_tokens,omitempty"` // ThreadTruncationStrategy defines the truncation strategy to use for the thread. TruncationStrategy *ThreadTruncationStrategy `json:"truncation_strategy,omitempty"` // This can be either a string or a ToolChoice object. ToolChoice any `json:"tool_choice,omitempty"` // This can be either a string or a ResponseFormat object. ResponseFormat any `json:"response_format,omitempty"` // Disable the default behavior of parallel tool calls by setting it: false. ParallelToolCalls any `json:"parallel_tool_calls,omitempty"` }
type RunRequiredAction ¶
type RunRequiredAction struct { Type RequiredActionType `json:"type"` SubmitToolOutputs *SubmitToolOutputs `json:"submit_tool_outputs,omitempty"` }
type RunStatus ¶
type RunStatus string
const ( RunStatusQueued RunStatus = "queued" RunStatusInProgress RunStatus = "in_progress" RunStatusRequiresAction RunStatus = "requires_action" RunStatusCancelling RunStatus = "cancelling" RunStatusFailed RunStatus = "failed" RunStatusCompleted RunStatus = "completed" RunStatusIncomplete RunStatus = "incomplete" RunStatusExpired RunStatus = "expired" RunStatusCancelled RunStatus = "cancelled" )
type RunStep ¶
type RunStep struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` AssistantID string `json:"assistant_id"` ThreadID string `json:"thread_id"` RunID string `json:"run_id"` Type RunStepType `json:"type"` Status RunStepStatus `json:"status"` StepDetails StepDetails `json:"step_details"` LastError *RunLastError `json:"last_error,omitempty"` ExpiredAt *int64 `json:"expired_at,omitempty"` CancelledAt *int64 `json:"cancelled_at,omitempty"` FailedAt *int64 `json:"failed_at,omitempty"` CompletedAt *int64 `json:"completed_at,omitempty"` Metadata map[string]any `json:"metadata"` // contains filtered or unexported fields }
func (*RunStep) GetRateLimitHeaders ¶
func (h *RunStep) GetRateLimitHeaders() RateLimitHeaders
type RunStepList ¶
type RunStepList struct { RunSteps []RunStep `json:"data"` FirstID string `json:"first_id"` LastID string `json:"last_id"` HasMore bool `json:"has_more"` // contains filtered or unexported fields }
RunStepList is a list of steps.
func (*RunStepList) GetRateLimitHeaders ¶
func (h *RunStepList) GetRateLimitHeaders() RateLimitHeaders
type RunStepStatus ¶
type RunStepStatus string
const ( RunStepStatusInProgress RunStepStatus = "in_progress" RunStepStatusCancelling RunStepStatus = "cancelled" RunStepStatusFailed RunStepStatus = "failed" RunStepStatusCompleted RunStepStatus = "completed" RunStepStatusExpired RunStepStatus = "expired" )
type RunStepType ¶
type RunStepType string
const ( RunStepTypeMessageCreation RunStepType = "message_creation" RunStepTypeToolCalls RunStepType = "tool_calls" )
type SpeechModel ¶
type SpeechModel string
const ( TTSModel1 SpeechModel = "tts-1" TTSModel1HD SpeechModel = "tts-1-hd" TTSModelCanary SpeechModel = "canary-tts" )
type SpeechResponseFormat ¶
type SpeechResponseFormat string
const ( SpeechResponseFormatMp3 SpeechResponseFormat = "mp3" SpeechResponseFormatOpus SpeechResponseFormat = "opus" SpeechResponseFormatAac SpeechResponseFormat = "aac" SpeechResponseFormatFlac SpeechResponseFormat = "flac" SpeechResponseFormatWav SpeechResponseFormat = "wav" SpeechResponseFormatPcm SpeechResponseFormat = "pcm" )
type SpeechVoice ¶
type SpeechVoice string
const ( VoiceAlloy SpeechVoice = "alloy" VoiceEcho SpeechVoice = "echo" VoiceFable SpeechVoice = "fable" VoiceOnyx SpeechVoice = "onyx" VoiceNova SpeechVoice = "nova" VoiceShimmer SpeechVoice = "shimmer" )
type StaticChunkingStrategy ¶
type StepDetails ¶
type StepDetails struct { Type RunStepType `json:"type"` MessageCreation *StepDetailsMessageCreation `json:"message_creation,omitempty"` ToolCalls []ToolCall `json:"tool_calls,omitempty"` }
type StepDetailsMessageCreation ¶
type StepDetailsMessageCreation struct {
MessageID string `json:"message_id"`
}
type StreamOptions ¶
type StreamOptions struct { // If set, an additional chunk will be streamed before the data: [DONE] message. // The usage field on this chunk shows the token usage statistics for the entire request, // and the choices field will always be an empty array. // All other chunks will also include a usage field, but with a null value. IncludeUsage bool `json:"include_usage,omitempty"` }
type SubmitToolOutputs ¶
type SubmitToolOutputs struct {
ToolCalls []ToolCall `json:"tool_calls"`
}
type SubmitToolOutputsRequest ¶
type SubmitToolOutputsRequest struct {
ToolOutputs []ToolOutput `json:"tool_outputs"`
}
type Thread ¶
type Thread struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` Metadata map[string]any `json:"metadata"` ToolResources ToolResources `json:"tool_resources,omitempty"` // contains filtered or unexported fields }
func (*Thread) GetRateLimitHeaders ¶
func (h *Thread) GetRateLimitHeaders() RateLimitHeaders
type ThreadAttachment ¶
type ThreadAttachment struct { FileID string `json:"file_id"` Tools []ThreadAttachmentTool `json:"tools"` }
type ThreadAttachmentTool ¶
type ThreadAttachmentTool struct {
Type string `json:"type"`
}
type ThreadDeleteResponse ¶
type ThreadDeleteResponse struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` // contains filtered or unexported fields }
func (*ThreadDeleteResponse) GetRateLimitHeaders ¶
func (h *ThreadDeleteResponse) GetRateLimitHeaders() RateLimitHeaders
type ThreadMessage ¶
type ThreadMessage struct { Role ThreadMessageRole `json:"role"` Content string `json:"content"` FileIDs []string `json:"file_ids,omitempty"` Attachments []ThreadAttachment `json:"attachments,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` }
type ThreadMessageRole ¶
type ThreadMessageRole string
const ( ThreadMessageRoleAssistant ThreadMessageRole = "assistant" ThreadMessageRoleUser ThreadMessageRole = "user" )
type ThreadRequest ¶
type ThreadRequest struct { Messages []ThreadMessage `json:"messages,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` ToolResources *ToolResourcesRequest `json:"tool_resources,omitempty"` }
type ThreadTruncationStrategy ¶
type ThreadTruncationStrategy struct { // default 'auto'. Type TruncationStrategy `json:"type,omitempty"` // this field should be set if the truncation strategy is set to LastMessages. LastMessages *int `json:"last_messages,omitempty"` }
ThreadTruncationStrategy defines the truncation strategy to use for the thread. https://platform.openai.com/docs/assistants/how-it-works/truncation-strategy.
type Tool ¶
type Tool struct { Type ToolType `json:"type"` Function *FunctionDefinition `json:"function,omitempty"` }
type ToolCall ¶
type ToolCall struct { // Index is not nil only in chat completion chunk object Index *int `json:"index,omitempty"` ID string `json:"id"` Type ToolType `json:"type"` Function FunctionCall `json:"function"` }
type ToolChoice ¶
type ToolChoice struct { Type ToolType `json:"type"` Function ToolFunction `json:"function,omitempty"` }
type ToolFunction ¶
type ToolFunction struct {
Name string `json:"name"`
}
type ToolOutput ¶
type ToolResources ¶
type ToolResources struct { CodeInterpreter *CodeInterpreterToolResources `json:"code_interpreter,omitempty"` FileSearch *FileSearchToolResources `json:"file_search,omitempty"` }
type ToolResourcesRequest ¶
type ToolResourcesRequest struct { CodeInterpreter *CodeInterpreterToolResourcesRequest `json:"code_interpreter,omitempty"` FileSearch *FileSearchToolResourcesRequest `json:"file_search,omitempty"` }
type TopLogProbs ¶
type TranscriptionTimestampGranularity ¶
type TranscriptionTimestampGranularity string
const ( TranscriptionTimestampGranularityWord TranscriptionTimestampGranularity = "word" TranscriptionTimestampGranularitySegment TranscriptionTimestampGranularity = "segment" )
type TruncationStrategy ¶
type TruncationStrategy string
TruncationStrategy defines the existing truncation strategies existing for thread management in an assistant.
type UploadBatchFileRequest ¶
type UploadBatchFileRequest struct { FileName string Lines []BatchLineItem }
func (*UploadBatchFileRequest) AddChatCompletion ¶
func (r *UploadBatchFileRequest) AddChatCompletion(customerID string, body ChatCompletionRequest)
func (*UploadBatchFileRequest) AddCompletion ¶
func (r *UploadBatchFileRequest) AddCompletion(customerID string, body CompletionRequest)
func (*UploadBatchFileRequest) AddEmbedding ¶
func (r *UploadBatchFileRequest) AddEmbedding(customerID string, body EmbeddingRequest)
func (*UploadBatchFileRequest) MarshalJSONL ¶
func (r *UploadBatchFileRequest) MarshalJSONL() []byte
type Usage ¶
type Usage struct { PromptTokens int `json:"prompt_tokens"` CompletionTokens int `json:"completion_tokens"` TotalTokens int `json:"total_tokens"` PromptTokensDetails *PromptTokensDetails `json:"prompt_tokens_details"` CompletionTokensDetails *CompletionTokensDetails `json:"completion_tokens_details"` }
Usage Represents the total token usage per request to OpenAI.
type VectorStore ¶
type VectorStore struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` Name string `json:"name"` UsageBytes int `json:"usage_bytes"` FileCounts VectorStoreFileCount `json:"file_counts"` Status string `json:"status"` ExpiresAfter *VectorStoreExpires `json:"expires_after"` ExpiresAt *int `json:"expires_at"` Metadata map[string]any `json:"metadata"` // contains filtered or unexported fields }
func (*VectorStore) GetRateLimitHeaders ¶
func (h *VectorStore) GetRateLimitHeaders() RateLimitHeaders
type VectorStoreDeleteResponse ¶
type VectorStoreDeleteResponse struct { ID string `json:"id"` Object string `json:"object"` Deleted bool `json:"deleted"` // contains filtered or unexported fields }
func (*VectorStoreDeleteResponse) GetRateLimitHeaders ¶
func (h *VectorStoreDeleteResponse) GetRateLimitHeaders() RateLimitHeaders
type VectorStoreExpires ¶
type VectorStoreFile ¶
type VectorStoreFile struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` VectorStoreID string `json:"vector_store_id"` UsageBytes int `json:"usage_bytes"` Status string `json:"status"` // contains filtered or unexported fields }
func (*VectorStoreFile) GetRateLimitHeaders ¶
func (h *VectorStoreFile) GetRateLimitHeaders() RateLimitHeaders
type VectorStoreFileBatch ¶
type VectorStoreFileBatch struct { ID string `json:"id"` Object string `json:"object"` CreatedAt int64 `json:"created_at"` VectorStoreID string `json:"vector_store_id"` Status string `json:"status"` FileCounts VectorStoreFileCount `json:"file_counts"` // contains filtered or unexported fields }
func (*VectorStoreFileBatch) GetRateLimitHeaders ¶
func (h *VectorStoreFileBatch) GetRateLimitHeaders() RateLimitHeaders
type VectorStoreFileBatchRequest ¶
type VectorStoreFileBatchRequest struct {
FileIDs []string `json:"file_ids"`
}
type VectorStoreFileCount ¶
type VectorStoreFileRequest ¶
type VectorStoreFileRequest struct {
FileID string `json:"file_id"`
}
type VectorStoreFilesList ¶
type VectorStoreFilesList struct { VectorStoreFiles []VectorStoreFile `json:"data"` // contains filtered or unexported fields }
func (*VectorStoreFilesList) GetRateLimitHeaders ¶
func (h *VectorStoreFilesList) GetRateLimitHeaders() RateLimitHeaders
type VectorStoreRequest ¶
type VectorStoreRequest struct { Name string `json:"name,omitempty"` FileIDs []string `json:"file_ids,omitempty"` ExpiresAfter *VectorStoreExpires `json:"expires_after,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` }
VectorStoreRequest provides the vector store request parameters.
type VectorStoreToolResources ¶
type VectorStoreToolResources struct { FileIDs []string `json:"file_ids,omitempty"` ChunkingStrategy *ChunkingStrategy `json:"chunking_strategy,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` }
type VectorStoresList ¶
type VectorStoresList struct { VectorStores []VectorStore `json:"data"` LastID *string `json:"last_id"` FirstID *string `json:"first_id"` HasMore bool `json:"has_more"` // contains filtered or unexported fields }
VectorStoresList is a list of vector store.
func (*VectorStoresList) GetRateLimitHeaders ¶
func (h *VectorStoresList) GetRateLimitHeaders() RateLimitHeaders
Source Files ¶
- assistant.go
- audio.go
- batch.go
- chat.go
- chat_stream.go
- client.go
- common.go
- completion.go
- config.go
- edits.go
- embeddings.go
- engines.go
- error.go
- files.go
- fine_tunes.go
- fine_tuning_job.go
- image.go
- messages.go
- models.go
- moderation.go
- ratelimit.go
- run.go
- speech.go
- stream.go
- stream_reader.go
- thread.go
- vector_store.go
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package jsonschema provides very simple functionality for representing a JSON schema as a (nested) struct.
|
Package jsonschema provides very simple functionality for representing a JSON schema as a (nested) struct. |