Documentation
¶
Index ¶
- type ChatCompletionChoice
- type ChatCompletionError
- type ChatCompletionRequest
- type ChatCompletionResponse
- type ChatCompletionResponseError
- type ChatCompletionUsage
- type ChatError
- type ChatMessage
- type LanguageModelClient
- type MessageRole
- type OpenAIClient
- type PromptTokenDetails
- type ReasoningEffort
- type ResponseFormat
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 ChatMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
type ChatCompletionError ¶
type ChatCompletionError struct {
Message string `json:"message"`
StatusCode int `json:"status_code,omitempty"`
RawBody json.RawMessage `json:"raw_body,omitempty"`
}
ChatCompletionError wraps standard errors with raw response body for error logging
func (*ChatCompletionError) Error ¶
func (e *ChatCompletionError) Error() string
func (*ChatCompletionError) GetRawResponseBody ¶
func (e *ChatCompletionError) GetRawResponseBody() json.RawMessage
GetRawResponseBody returns the raw response body if available
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
User string `json:"user,omitempty"`
Messages []ChatMessage `json:"messages"`
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
Temperature float32 `json:"temperature,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"`
PresencePenalty float32 `json:"presence_penalty,omitempty"`
FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
ReasoningEffort ReasoningEffort `json:"reasoning_effort,omitempty"`
Stream bool `json:"stream,omitempty"`
}
ChatCompletionRequest is the request body for the chat completion endpoint
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Choices []ChatCompletionChoice `json:"choices"`
Usage ChatCompletionUsage `json:"usage"`
}
The response from the chat completion endpoint
type ChatCompletionResponseError ¶
type ChatCompletionResponseError struct {
Error ChatError `json:"error"`
}
type ChatCompletionUsage ¶
type ChatCompletionUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
PromptTokensDetails *PromptTokenDetails `json:"prompt_tokens_details,omitempty"`
}
type ChatMessage ¶
type ChatMessage struct {
Role MessageRole `json:"role"`
Content *string `json:"content,omitempty"`
Reasoning *string `json:"reasoning,omitempty"`
ToolCallID *string `json:"tool_call_id,omitempty"`
}
type LanguageModelClient ¶
type LanguageModelClient interface {
ChatCompletion(ctx context.Context, req ChatCompletionRequest) (*ChatCompletionResponse, error)
SetBaseURL(baseUrl string)
}
type MessageRole ¶
type MessageRole string
const ( MessageRoleUser MessageRole = "user" MessageRoleAssistant MessageRole = "assistant" MessageRoleTool MessageRole = "tool" MessageRoleSystem MessageRole = "system" )
type OpenAIClient ¶
type OpenAIClient struct {
APIKey string
Env string
DumpRequests bool
BaseURL string
HTTPClient *http.Client
RetryConfig retry.Config
}
OpenAIClient is a minimal client for the OpenAI Chat API
func (*OpenAIClient) ChatCompletion ¶
func (c *OpenAIClient) ChatCompletion(ctx context.Context, req ChatCompletionRequest) (*ChatCompletionResponse, error)
Sends a chat completion request to OpenAI with retry logic
func (*OpenAIClient) SetBaseURL ¶
func (c *OpenAIClient) SetBaseURL(baseUrl string)
Sets the base URL for the OpenAI client
type PromptTokenDetails ¶
type PromptTokenDetails struct {
CachedTokens int `json:"cached_tokens"`
}
type ReasoningEffort ¶
type ReasoningEffort string
const ( ReasoningEffortLow ReasoningEffort = "low" ReasoningEffortMedium ReasoningEffort = "medium" ReasoningEffortHigh ReasoningEffort = "high" )
type ResponseFormat ¶
Click to show internal directories.
Click to hide internal directories.