Documentation
¶
Index ¶
- Constants
- func CallFunction(ctx context.Context, client Client, fn *config.LLMFunction, ...) (string, error)
- func EstimateTokens(requestJSON []byte) int
- func HandleRetryAfter(retryAfter time.Duration)
- type APIError
- type APIFunction
- type ChatRequest
- type ChatResponse
- type Client
- type Function
- type FunctionCall
- type FunctionCallArguments
- type FunctionChoice
- type FunctionDef
- type Message
- type MessageChoice
- type MessageResponse
- type OpenAIClient
- type Parameters
- type Property
- type RateLimitInfo
- type RateLimiter
- type WaitInfo
Constants ¶
View Source
const (
ProviderOpenAICompatible = "openai-compatible"
)
Core constants
Variables ¶
This section is empty.
Functions ¶
func CallFunction ¶
func CallFunction(ctx context.Context, client Client, fn *config.LLMFunction, input map[string]interface{}) (string, error)
Function-related functions
func EstimateTokens ¶
func HandleRetryAfter ¶
HandleRetryAfter handles 429 responses by waiting for the specified duration
Types ¶
type APIFunction ¶
type APIFunction struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters Parameters `json:"parameters"`
}
API-related structures
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Functions []Function `json:"tools,omitempty"`
}
Request/Response structures
type ChatResponse ¶
type ChatResponse struct {
Choices []MessageChoice `json:"choices"`
Error *APIError `json:"error,omitempty"`
}
type Client ¶
type Client interface {
GenerateText(ctx context.Context, systemPrompt, userPrompt string, functions []APIFunction) (string, error)
}
Core interfaces
type Function ¶
type Function struct {
Type string `json:"type"`
Function FunctionDef `json:"function"`
}
type FunctionCall ¶
type FunctionCallArguments ¶
type FunctionChoice ¶
type FunctionDef ¶
type FunctionDef struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters Parameters `json:"parameters"`
}
type MessageChoice ¶
type MessageChoice struct {
Message MessageResponse `json:"message"`
Index int `json:"index"`
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
}
type MessageResponse ¶
type MessageResponse struct {
Content string `json:"content"`
FunctionCalls []FunctionCall `json:"tool_calls,omitempty"` //nolint:tagliatelle // Following OpenAI API spec
}
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
Primary client structure
func (*OpenAIClient) GenerateText ¶
func (c *OpenAIClient) GenerateText(ctx context.Context, systemPrompt, userPrompt string, apiFunctions []APIFunction) (string, error)
type Parameters ¶
type RateLimitInfo ¶
type RateLimitInfo struct {
RemainingTokens int
TokensResetIn time.Duration
RemainingRequests int
RequestsResetIn time.Duration
RetryAfter time.Duration // Only set when receiving 429
}
RateLimitInfo contains rate limit information from API headers
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter handles rate limiting for LLM API calls
func NewRateLimiter ¶
func NewRateLimiter() *RateLimiter
NewRateLimiter creates a new rate limiter instance
func (*RateLimiter) UpdateLimits ¶
func (rl *RateLimiter) UpdateLimits(info RateLimitInfo)
UpdateLimits updates the rate limiter with new information from API headers
func (*RateLimiter) WaitForCapacity ¶
func (rl *RateLimiter) WaitForCapacity()
WaitForCapacity waits until there's capacity to make a request
Click to show internal directories.
Click to hide internal directories.