52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package openai
|
|
|
|
// ChatMessage represents a single message within a chat completion request or response.
|
|
type ChatMessage struct {
|
|
Role string `json:"role"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
// ChatCompletionRequest encapsulates the payload for the OpenAI Chat Completions API.
|
|
type ChatCompletionRequest struct {
|
|
Model string `json:"model"`
|
|
Messages []ChatMessage `json:"messages"`
|
|
MaxTokens *int `json:"max_tokens,omitempty"`
|
|
Temperature *float64 `json:"temperature,omitempty"`
|
|
Stream bool `json:"stream,omitempty"`
|
|
}
|
|
|
|
// ChatCompletionChoice captures an individual response choice returned from the API.
|
|
type ChatCompletionChoice struct {
|
|
Index int `json:"index"`
|
|
Message ChatMessage `json:"message"`
|
|
FinishReason string `json:"finish_reason"`
|
|
}
|
|
|
|
// Usage captures token accounting for a chat completion call.
|
|
type Usage struct {
|
|
PromptTokens int `json:"prompt_tokens"`
|
|
CompletionTokens int `json:"completion_tokens"`
|
|
TotalTokens int `json:"total_tokens"`
|
|
}
|
|
|
|
// ChatCompletionResponse represents the top-level response payload from the API.
|
|
type ChatCompletionResponse struct {
|
|
ID string `json:"id"`
|
|
Object string `json:"object"`
|
|
Choices []ChatCompletionChoice `json:"choices"`
|
|
Usage Usage `json:"usage"`
|
|
}
|
|
|
|
// APIError captures structured error responses returned by the API.
|
|
type APIError struct {
|
|
Message string `json:"message"`
|
|
Type string `json:"type"`
|
|
Param string `json:"param"`
|
|
Code any `json:"code"`
|
|
}
|
|
|
|
// ErrorResponse is returned on non-2xx responses.
|
|
type ErrorResponse struct {
|
|
Error APIError `json:"error"`
|
|
}
|