Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultTimeOut = 30 * time.Second DefaultMaxRetries = 3 DefaultRetryDelay = 1 * time.Second DefaultTemperature = 0.1 DefaultMaxTokens = 10000 )
View Source
const ( ChatMessageRoleSystem = "system" ChatMessageRoleUser = "user" ChatMessageRoleAssistant = "assistant" )
Chat message roles
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatCompletionMessage ¶
ChatCompletionMessage represents a single message in conversation
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []ChatCompletionMessage `json:"messages"`
Stream bool `json:"stream,omitempty"`
Temperature float64 `json:"temperature,omitempty"` // Controls randomness (0-2)
MaxTokens int `json:"max_tokens,omitempty"` // Maximum tokens to generate
}
ChatCompletionRequest defines chat completion parameters
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Message ChatCompletionMessage `json:"message"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage,omitempty"`
}
ChatCompletionResponse contains full API response
type ChatCompletionStreamResponse ¶
type ChatCompletionStreamResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []struct {
Index int `json:"index"`
Delta ChatCompletionMessage `json:"delta"`
FinishReason *string `json:"finish_reason,omitempty"`
} `json:"choices"`
}
ChatCompletionStreamResponse contains streaming chunk
type Client ¶
type Client interface {
CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error)
CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest) (Stream, error)
}
Client interface defines the contract for chat completion service
func NewClient ¶
func NewClient(endPoint, apiKey string, opts ...ClientOption) Client
NewClient creates a new client with options
type ClientOption ¶
type ClientOption func(*openAIClient)
ClientOption configures the client
func WithRetryPolicy ¶
func WithRetryPolicy(maxRetries int, retryDelay time.Duration) ClientOption
WithRetryPolicy configures retry behavior
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets request timeout
Click to show internal directories.
Click to hide internal directories.