Documentation ¶
Overview ¶
Package common contains common API structures and helper functions, not specific to an endpoint or model.
Index ¶
- Constants
- func CreateFormField[DataT any](fieldname string, data DataT, writer *multipart.Writer) error
- func CreateFormFile(fieldname, filename, filepath string, writer *multipart.Writer) error
- func IsUrl(str string) bool
- func MakeRequest[RequestT any, ResponseT any](request *RequestT, endpoint, method string, organizationID *string) (*ResponseT, error)
- func MakeRequestWithForm[ResponseT any](form *bytes.Buffer, endpoint, method, contentType string, ...) (*ResponseT, error)
- func SetRequestHeaders(req *http.Request, contentType string, organizationID *string)
- type ResponseError
- type ResponseUsage
Constants ¶
View Source
const ( // The version of the API currently implemented by this library. APIVersion = "v1" // The basis of all API endpoints. BaseURL = "https://api.openai.com/" + APIVersion + "/" )
Variables ¶
This section is empty.
Functions ¶
func CreateFormField ¶
func CreateFormFile ¶
func MakeRequest ¶
func MakeRequest[RequestT any, ResponseT any](request *RequestT, endpoint, method string, organizationID *string) (*ResponseT, error)
Send a request to the given OpenAI endpoint. The method parameter should be an HTTP method, such as GET or POST. The organizationID parameter is optional. If provided, it will be included in the request header. If not provided, the authorization.DefaultOrganizationID will be used, if it is set.
func MakeRequestWithForm ¶
Types ¶
type ResponseError ¶
type ResponseError struct { // The error message. Message string `json:"message"` // The error type. Type string `json:"type"` // The parameter that was invalid. Param string `json:"param"` }
A common error structure included in OpenAI API response bodies.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
type ResponseUsage ¶
type ResponseUsage struct { PromptTokens uint64 `json:"prompt_tokens"` CompletionTokens uint64 `json:"completion_tokens"` TotalTokens uint64 `json:"total_tokens"` }
A common usage information structure included in OpenAI API response bodies.
Click to show internal directories.
Click to hide internal directories.