Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateInputTokensCost(model string, inputTokens float64) (bool, float64)
- func CalculateOutputTokensCost(model string, outputTokens float64) (bool, float64)
- type APIKey
- type ChatClient
- type ChatCompletion
- type ChatMessage
- type CreateChatCompletion
- type ErrorDetail
- type ErrorResponse
- type GenerativeAIClient
- type Pricing
- type ResponseFormat
- type TotalUsageCost
- func (tuc *TotalUsageCost) TotalCompletionTokens() int
- func (tuc *TotalUsageCost) TotalCompletionTokensCost() (bool, float64)
- func (tuc *TotalUsageCost) TotalPromptTokens() int
- func (tuc *TotalUsageCost) TotalPromptTokensCost() (bool, float64)
- func (tuc *TotalUsageCost) TotalTotalTokens() int
- func (tuc *TotalUsageCost) TotalTotalTokensCost() (bool, float64)
- type UsageCost
- func (uc *UsageCost) CompletionTokens() int
- func (uc *UsageCost) CompletionTokensCost() (bool, float64)
- func (uc *UsageCost) ModelName() string
- func (uc *UsageCost) PromptTokens() int
- func (uc *UsageCost) PromptTokensCost() (bool, float64)
- func (uc *UsageCost) TotalTokens() int
- func (uc *UsageCost) TotalTokensCost() (bool, float64)
Constants ¶
const OneMillion = 1_000_000
Variables ¶
var ErrUnexpectedStatusCode = errors.New("unexpected status code")
ErrUnexpectedStatusCode is an error for unexpected status code.
Functions ¶
Types ¶
type ChatClient ¶
type ChatClient struct {
// contains filtered or unexported fields
}
ChatClient represents an interface for chat client operations.
func New ¶
func New(apikey APIKey, model, logLevel string, maxTokens *int) *ChatClient
New creates a new ChatClient instance.
func (*ChatClient) MakeCreateChatCompletion ¶
func (c *ChatClient) MakeCreateChatCompletion(prompt string) *CreateChatCompletion
MakeCreateChatCompletion creates a new CreateChatCompletion.
func (*ChatClient) RequestCreateChatCompletion ¶
func (c *ChatClient) RequestCreateChatCompletion(ctx context.Context, ccc *CreateChatCompletion) (*ChatCompletion, error)
RequestCreateChatCompletion requests the AI to create chat completion based on the given prompt.
type ChatCompletion ¶
type ChatCompletion struct {
ID string `json:"id"`
Object string `json:"object"`
Created int `json:"created"`
Model string `json:"model"`
ResponseFormat ResponseFormat `json:"response_format"`
SystemFingerprint string `json:"system_fingerprint"`
Choices []struct {
FinishReason string `json:"finish_reason"`
Index int `json:"index"`
Message ChatMessage `json:"message"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
ChatCompletion represents the JSON structure for the completion response.
type ChatMessage ¶
type CreateChatCompletion ¶
type CreateChatCompletion struct {
Messages []ChatMessage `json:"messages"`
Model string `json:"model"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
N *int `json:"n,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
Seed *int `json:"seed,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Stop []string `json:"stop,omitempty"`
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
LogitBias map[string]float64 `json:"logit_bias,omitempty"`
User *string `json:"user,omitempty"`
PresencePenalty *float64 `json:"presence_penalty,omitempty"`
}
CreateChatCompletion represents the structure of a request to the OpenAI API Chat endpoint.
type ErrorDetail ¶
type ErrorDetail struct {
Message string `json:"message"`
Type string `json:"type"`
Param interface{} `json:"param"` // Param can be of any type, hence using interface{}.
Code string `json:"code"`
}
ErrorDetail represents the details of the error.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse represents the JSON structure for the error response.
type GenerativeAIClient ¶
type GenerativeAIClient interface {
RequestCreateChatCompletion(context.Context, *CreateChatCompletion) (*ChatCompletion, error)
MakeCreateChatCompletion(string) *CreateChatCompletion
}
GenerativeAIClient represents an interface for generating AI client operations.
type Pricing ¶
type Pricing struct {
Model string
InputTokensCostDollar float64
InputTokens float64
OutputTokensCostDollar float64
OutputTokens float64
}
func GetPricing ¶
type ResponseFormat ¶
type ResponseFormat struct {
Type string `json:"type"`
}
type TotalUsageCost ¶
type TotalUsageCost struct {
UsageCosts []*UsageCost
}
func NewTotalUsageCost ¶
func NewTotalUsageCost(usageCosts []*UsageCost) *TotalUsageCost
NewTotalUsageCost creates a new TotalUsageCost instance.
func (*TotalUsageCost) TotalCompletionTokens ¶
func (tuc *TotalUsageCost) TotalCompletionTokens() int
TotalCompletionTokens calculates the total number of completion tokens.
func (*TotalUsageCost) TotalCompletionTokensCost ¶
func (tuc *TotalUsageCost) TotalCompletionTokensCost() (bool, float64)
TotalCompletionTokensCost calculates the total cost of completion tokens.
func (*TotalUsageCost) TotalPromptTokens ¶
func (tuc *TotalUsageCost) TotalPromptTokens() int
TotalPromptTokens calculates the total number of prompt tokens.
func (*TotalUsageCost) TotalPromptTokensCost ¶
func (tuc *TotalUsageCost) TotalPromptTokensCost() (bool, float64)
TotalPromptTokensCost calculates the total cost of prompt tokens.
func (*TotalUsageCost) TotalTotalTokens ¶
func (tuc *TotalUsageCost) TotalTotalTokens() int
TotalTotalTokens calculates the total number of tokens.
func (*TotalUsageCost) TotalTotalTokensCost ¶
func (tuc *TotalUsageCost) TotalTotalTokensCost() (bool, float64)
TotalTotalTokensCost calculates the total cost of tokens.
type UsageCost ¶
type UsageCost struct {
// contains filtered or unexported fields
}
func NewUsageCost ¶
func NewUsageCost(chatCompletion *ChatCompletion) *UsageCost