openai

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpenAiPerThousandTokenCost = map[string]map[string]float64{
	"prompt": {
		"gpt-4o":                      0.005,
		"gpt-4o-2024-05-13":           0.005,
		"gpt-4-1106-preview":          0.01,
		"gpt-4-turbo-preview":         0.01,
		"gpt-4-turbo":                 0.01,
		"gpt-4-turbo-2024-04-09":      0.01,
		"gpt-4-0125-preview":          0.01,
		"gpt-4-1106-vision-preview":   0.01,
		"gpt-4-vision-preview":        0.01,
		"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-1106":          0.001,
		"gpt-3.5-turbo-0125":          0.0005,
		"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,
		"finetune-gpt-4-0613":         0.045,
		"finetune-gpt-3.5-turbo-0125": 0.003,
		"finetune-gpt-3.5-turbo-1106": 0.003,
		"finetune-gpt-3.5-turbo-0613": 0.003,
		"finetune-babbage-002":        0.0016,
		"finetune-davinci-002":        0.012,
	},
	"finetune": {
		"gpt-4-0613":         0.09,
		"gpt-3.5-turbo-0125": 0.008,
		"gpt-3.5-turbo-1106": 0.008,
		"gpt-3.5-turbo-0613": 0.008,
		"babbage-002":        0.0004,
		"davinci-002":        0.006,
	},
	"embeddings": {
		"text-embedding-ada-002": 0.0001,
		"text-embedding-3-small": 0.00002,
		"text-embedding-3-large": 0.00013,
	},
	"audio": {
		"whisper-1": 0.006,
		"tts-1":     0.015,
		"tts-1-hd":  0.03,
	},
	"completion": {
		"gpt-3.5-turbo-1106":          0.002,
		"gpt-4o":                      0.015,
		"gpt-4o-2024-05-13":           0.015,
		"gpt-4-turbo-preview":         0.03,
		"gpt-4-turbo":                 0.03,
		"gpt-4-turbo-2024-04-09":      0.03,
		"gpt-4-1106-preview":          0.03,
		"gpt-4-0125-preview":          0.03,
		"gpt-4-1106-vision-preview":   0.03,
		"gpt-4-vision-preview":        0.03,
		"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-0125":          0.0015,
		"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,
		"finetune-gpt-4-0613":         0.09,
		"finetune-gpt-3.5-turbo-0125": 0.006,
		"finetune-gpt-3.5-turbo-1106": 0.006,
		"finetune-gpt-3.5-turbo-0613": 0.006,
		"finetune-babbage-002":        0.0016,
		"finetune-davinci-002":        0.012,
	},
}

Functions

This section is empty.

Types

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) EstimateChatCompletionPromptCostWithTokenCounts added in v1.3.0

func (ce *CostEstimator) EstimateChatCompletionPromptCostWithTokenCounts(r *goopenai.ChatCompletionRequest) (int, float64, error)

func (*CostEstimator) EstimateChatCompletionPromptTokenCounts added in v1.6.0

func (ce *CostEstimator) EstimateChatCompletionPromptTokenCounts(model string, r *goopenai.ChatCompletionRequest) (int, error)

func (*CostEstimator) EstimateChatCompletionStreamCostWithTokenCounts added in v1.3.0

func (ce *CostEstimator) EstimateChatCompletionStreamCostWithTokenCounts(model string, content string) (int, float64, error)

func (*CostEstimator) EstimateCompletionCost

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

func (*CostEstimator) EstimateEmbeddingsCost added in v1.0.4

func (ce *CostEstimator) EstimateEmbeddingsCost(r *goopenai.EmbeddingRequest) (float64, error)

func (*CostEstimator) EstimateEmbeddingsInputCost added in v1.0.4

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

func (*CostEstimator) EstimateFinetuningCost added in v1.11.0

func (ce *CostEstimator) EstimateFinetuningCost(num int, model string) (float64, error)

func (*CostEstimator) EstimatePromptCost

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

func (*CostEstimator) EstimateSpeechCost added in v1.11.0

func (ce *CostEstimator) EstimateSpeechCost(input string, model string) (float64, error)

func (*CostEstimator) EstimateTotalCost added in v0.0.9

func (ce *CostEstimator) EstimateTotalCost(model string, promptTks, completionTks int) (float64, error)

func (*CostEstimator) EstimateTranscriptionCost added in v1.11.0

func (ce *CostEstimator) EstimateTranscriptionCost(secs float64, model string) (float64, error)

type CreateThreadAndRunRequest added in v1.24.0

type CreateThreadAndRunRequest struct {
	*goopenai.RunRequest
	Thread ThreadRequest `json:"thread"`
}

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 ImageFile added in v1.24.0

type ImageFile struct {
	FileId string `json:"file_id"`
	Detail string `json:"detail"`
}

type ImageFileContentPart added in v1.24.0

type ImageFileContentPart struct {
	Type      string    `json:"type"`
	ImageFile ImageFile `json:"image_file"`
}

type ImageUrl added in v1.24.0

type ImageUrl struct {
	Url    string `json:"url"`
	Detail string `json:"detail"`
}

type ImageUrlContentPart added in v1.24.0

type ImageUrlContentPart struct {
	Type     string   `json:"type"`
	ImageUrl ImageUrl `json:"image_url"`
}

type MessageRequest added in v1.24.0

type MessageRequest struct {
	Role     string         `json:"role"`
	Content  any            `json:"content"`
	FileIds  []string       `json:"file_ids,omitempty"` //nolint:revive // backwards-compatibility
	Metadata map[string]any `json:"metadata,omitempty"`
}

type TextContentPart added in v1.24.0

type TextContentPart struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type ThreadMessage added in v1.24.0

type ThreadMessage struct {
	Role     ThreadMessageRole `json:"role"`
	Content  any               `json:"content"`
	FileIDs  []string          `json:"file_ids,omitempty"`
	Metadata map[string]any    `json:"metadata,omitempty"`
}

type ThreadMessageRole added in v1.24.0

type ThreadMessageRole string
const (
	ThreadMessageRoleUser      ThreadMessageRole = "user"
	ThreadMessageRoleAssistant ThreadMessageRole = "assistant"
)

type ThreadRequest added in v1.24.0

type ThreadRequest struct {
	Messages []ThreadMessage `json:"messages,omitempty"`
	Metadata map[string]any  `json:"metadata,omitempty"`
}

type TokenCounter

type TokenCounter struct {
}

func NewTokenCounter

func NewTokenCounter() *TokenCounter

func (*TokenCounter) Count

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

Jump to

Keyboard shortcuts

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