common

package
v0.3.1-beta Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 12 Imported by: 0

README

OpenAI Common

Common API structures and helper functions, not specific to an endpoint or model.

Documentation

Overview

Package common contains common API structures and helper functions, not specific to an endpoint or model.

Index

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 CreateFormField[DataT any](fieldname string, data DataT, writer *multipart.Writer) error

func CreateFormFile

func CreateFormFile(fieldname, filename, filepath string, writer *multipart.Writer) error

func IsUrl

func IsUrl(str string) bool

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

func MakeRequestWithForm[ResponseT any](form *bytes.Buffer, endpoint, method, contentType string, organizationID *string) (*ResponseT, error)

func SetRequestHeaders

func SetRequestHeaders(req *http.Request, contentType string, organizationID *string)

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.

Jump to

Keyboard shortcuts

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