Documentation
¶
Overview ¶
Package client provides HTTP clients for API-based AI providers.
Index ¶
- type ChatCompletionChoice
- type ChatCompletionError
- type ChatCompletionMessage
- type ChatCompletionMessageDelta
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionStreamChoice
- type ChatCompletionStreamChunk
- type ChatCompletionUsage
- type OpenAICompatClient
- func (c *OpenAICompatClient) CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (*ChatCompletionResponse, error)
- func (c *OpenAICompatClient) CreateChatCompletionStream(ctx context.Context, req ChatCompletionRequest, writer io.Writer) (*ChatCompletionUsage, error)
- func (c *OpenAICompatClient) HealthCheck(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatCompletionChoice ¶
type ChatCompletionChoice struct {
Index int `json:"index"`
Message ChatCompletionMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
ChatCompletionChoice represents a single completion choice.
type ChatCompletionError ¶
type ChatCompletionError struct {
Message string `json:"message"`
Type string `json:"type"`
Param string `json:"param,omitempty"`
Code string `json:"code,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
ChatCompletionError represents an error response from the API.
type ChatCompletionMessage ¶
type ChatCompletionMessage struct {
Role string `json:"role"` // "system", "user", or "assistant"
Content string `json:"content"` // The message content
}
ChatCompletionMessage represents a message in the conversation.
type ChatCompletionMessageDelta ¶
type ChatCompletionMessageDelta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
}
ChatCompletionMessageDelta represents incremental message content in streaming.
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []ChatCompletionMessage `json:"messages"`
Temperature *float64 `json:"temperature,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
Stream bool `json:"stream,omitempty"`
// Provider-specific fields
Provider map[string]interface{} `json:"provider,omitempty"`
}
ChatCompletionRequest represents a request to the chat completions endpoint.
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatCompletionChoice `json:"choices"`
Usage *ChatCompletionUsage `json:"usage,omitempty"`
Error *ChatCompletionError `json:"error,omitempty"`
}
ChatCompletionResponse represents the response from the chat completions endpoint.
type ChatCompletionStreamChoice ¶
type ChatCompletionStreamChoice struct {
Index int `json:"index"`
Delta ChatCompletionMessageDelta `json:"delta"`
FinishReason *string `json:"finish_reason"`
}
ChatCompletionStreamChoice represents a choice in a streaming response.
type ChatCompletionStreamChunk ¶
type ChatCompletionStreamChunk struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Choices []ChatCompletionStreamChoice `json:"choices"`
Usage *ChatCompletionUsage `json:"usage,omitempty"`
}
ChatCompletionStreamChunk represents a chunk in a streaming response.
type ChatCompletionUsage ¶
type ChatCompletionUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
ChatCompletionUsage contains token usage information.
type OpenAICompatClient ¶
type OpenAICompatClient struct {
// contains filtered or unexported fields
}
OpenAICompatClient is an HTTP client for OpenAI-compatible APIs. It supports both streaming and non-streaming requests.
func NewOpenAICompatClient ¶
func NewOpenAICompatClient(baseURL, apiKey string) *OpenAICompatClient
NewOpenAICompatClient creates a new OpenAI-compatible API client.
func (*OpenAICompatClient) CreateChatCompletion ¶
func (c *OpenAICompatClient) CreateChatCompletion( ctx context.Context, req ChatCompletionRequest, ) (*ChatCompletionResponse, error)
CreateChatCompletion sends a non-streaming chat completion request.
func (*OpenAICompatClient) CreateChatCompletionStream ¶
func (c *OpenAICompatClient) CreateChatCompletionStream( ctx context.Context, req ChatCompletionRequest, writer io.Writer, ) (*ChatCompletionUsage, error)
CreateChatCompletionStream sends a streaming chat completion request.
func (*OpenAICompatClient) HealthCheck ¶
func (c *OpenAICompatClient) HealthCheck(ctx context.Context) error
HealthCheck performs a simple health check by making a minimal API request.