openai

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpenAiPerThousandTokenCost = map[string]map[string]float64{
	"prompt": {
		"gpt-4":                  0.03,
		"gpt-4-0314":             0.03,
		"gpt-4-0613":             0.03,
		"gpt-4-32k":              0.06,
		"gpt-4-32k-0613":         0.06,
		"gpt-4-32k-0314":         0.06,
		"gpt-3.5-turbo":          0.0015,
		"gpt-3.5-turbo-0301":     0.0015,
		"gpt-3.5-turbo-instruct": 0.0015,
		"gpt-3.5-turbo-0613":     0.0015,
		"gpt-3.5-turbo-16k":      0.0015,
		"gpt-3.5-turbo-16k-0613": 0.0015,
		"text-davinci-003":       0.12,
		"text-davinci-002":       0.12,
		"code-davinci-002":       0.12,
		"text-curie-001":         0.012,
		"text-babbage-001":       0.0024,
		"text-ada-001":           0.0016,
		"davinci":                0.12,
		"curie":                  0.012,
		"babbage":                0.0024,
		"ada":                    0.0016,
	},
	"fine_tune": {
		"text-davinci-003": 0.03,
		"text-davinci-002": 0.03,
		"code-davinci-002": 0.03,
		"text-curie-001":   0.03,
		"text-babbage-001": 0.0006,
		"text-ada-001":     0.0004,
		"davinci":          0.03,
		"curie":            0.03,
		"babbage":          0.0006,
		"ada":              0.0004,
	},
	"embedding": {
		"text-embedding-ada-002": 0.0001,
	},
	"completion": {
		"gpt-4":                  0.06,
		"gpt-4-0314":             0.06,
		"gpt-4-0613":             0.06,
		"gpt-4-32k":              0.12,
		"gpt-4-32k-0613":         0.12,
		"gpt-4-32k-0314":         0.12,
		"gpt-3.5-turbo":          0.002,
		"gpt-3.5-turbo-0301":     0.002,
		"gpt-3.5-turbo-0613":     0.002,
		"gpt-3.5-turbo-instruct": 0.002,
		"gpt-3.5-turbo-16k":      0.004,
		"gpt-3.5-turbo-16k-0613": 0.004,
	},
}

Functions

This section is empty.

Types

type ChatCompletionErrorContent

type ChatCompletionErrorContent struct {
	Message string `json:"message"`
	Type    string `json:"type"`
}

type ChatCompletionErrorResponse

type ChatCompletionErrorResponse struct {
	Error *ErrorContent `json:"error"`
}

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model            string           `json:"model"`
	Messages         []RequestMessage `json:"messages"`
	Functions        []Function       `json:"functions,omitempty"`
	MaxTokens        int              `json:"max_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"`
	FrequencyPenalty float32          `json:"frequency_penalty,omitempty"`
	LogitBias        map[string]int   `json:"logit_bias,omitempty"`
	User             string           `json:"user,omitempty"`
}

type ChatCompletionResponse

type ChatCompletionResponse struct {
	Id      string   `json:"id"`
	Object  string   `json:"object"`
	Model   string   `json:"model"`
	Created int64    `json:"created"`
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
}

type Choice

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

type CostEstimator

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

func NewCostEstimator

func NewCostEstimator(m map[string]map[string]float64, tc tokenCounter) *CostEstimator

func (*CostEstimator) EstimateChatCompletionPromptCost

func (ce *CostEstimator) EstimateChatCompletionPromptCost(r *ChatCompletionRequest) (float64, error)

func (*CostEstimator) EstimateCompletionCost

func (ce *CostEstimator) EstimateCompletionCost(model string, tks int) (float64, error)

func (*CostEstimator) EstimatePromptCost

func (ce *CostEstimator) EstimatePromptCost(model string, tks int) (float64, error)

type ErrorContent

type ErrorContent struct {
	Message         string `json:"message"`
	Type            string `json:"type,omitempty"`
	Param           string `json:"param,omitempty"`
	Code            int    `json:"code,omitempty"`
	InternalMessage string `json:"internal_message,omitempty"`
}

type Function

type Function struct {
	Name        string           `json:"name,omitempty"`
	Description string           `json:"description,omitempty"`
	Parameters  *FuntionCallProp `json:"parameters,omitempty"`
}

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

type FuntionCallProp

type FuntionCallProp struct {
	Description string                 `json:"description,omitempty"`
	PropType    string                 `json:"type,omitempty"`
	Enum        []string               `json:"enum,omitempty"`
	Items       interface{}            `json:"items,omitempty"`
	Required    []string               `json:"required,omitempty"`
	Properties  map[string]interface{} `json:"properties,omitempty"`
}

func (*FuntionCallProp) GetDescription

func (p *FuntionCallProp) GetDescription() string

func (*FuntionCallProp) GetEnum

func (p *FuntionCallProp) GetEnum() []string

func (*FuntionCallProp) GetItems

func (p *FuntionCallProp) GetItems() (functionCallProp, error)

func (*FuntionCallProp) GetProperties

func (p *FuntionCallProp) GetProperties() (map[string]functionCallProp, error)

func (*FuntionCallProp) GetRequired

func (p *FuntionCallProp) GetRequired() []string

func (*FuntionCallProp) GetType

func (p *FuntionCallProp) GetType() string

type RequestMessage

type RequestMessage struct {
	Name         string        `json:"name,omitempty"`
	FunctionCall *FunctionCall `json:"function_call,omitempty"`
	Role         string        `json:"role,omitempty"`
	Content      string        `json:"content,omitempty"`
}

type ResponseMessage

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

type TokenCounter

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

func NewTokenCounter

func NewTokenCounter() (*TokenCounter, error)

func (*TokenCounter) Count

func (tc *TokenCounter) Count(model string, input string) (int, error)

type Usage

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

Jump to

Keyboard shortcuts

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