|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type OpenAIRequest struct {
|
|
|
Model string `json:"model"`
|
|
|
Messages []OpenAIMessage `json:"messages"`
|
|
|
Stream bool `json:"stream"`
|
|
|
MaxTokens *int `json:"max_tokens,omitempty"`
|
|
|
Temperature *float64 `json:"temperature,omitempty"`
|
|
|
TopP *float64 `json:"top_p,omitempty"`
|
|
|
Stop []string `json:"stop,omitempty"`
|
|
|
PresencePenalty *float64 `json:"presence_penalty,omitempty"`
|
|
|
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
|
|
|
Tools []OpenAITool `json:"tools,omitempty"`
|
|
|
ToolChoice any `json:"tool_choice,omitempty"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIMessage struct {
|
|
|
Role string `json:"role"`
|
|
|
Content string `json:"content"`
|
|
|
Name *string `json:"name,omitempty"`
|
|
|
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
|
|
|
ToolCallID *string `json:"tool_call_id,omitempty"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAITool struct {
|
|
|
Type string `json:"type"`
|
|
|
Function OpenAIFunctionDef `json:"function"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIFunctionDef struct {
|
|
|
Name string `json:"name"`
|
|
|
Description string `json:"description,omitempty"`
|
|
|
Parameters any `json:"parameters"`
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type OpenAIResponse struct {
|
|
|
ID string `json:"id"`
|
|
|
Object string `json:"object"`
|
|
|
Created int64 `json:"created"`
|
|
|
Model string `json:"model"`
|
|
|
Choices []OpenAIChoice `json:"choices"`
|
|
|
Usage *OpenAIUsage `json:"usage,omitempty"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIChoice struct {
|
|
|
Index int `json:"index"`
|
|
|
Message OpenAIMessage `json:"message"`
|
|
|
FinishReason string `json:"finish_reason"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIToolCall struct {
|
|
|
ID string `json:"id"`
|
|
|
Type string `json:"type"`
|
|
|
Function OpenAIFunction `json:"function"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIFunction struct {
|
|
|
Name string `json:"name"`
|
|
|
Arguments string `json:"arguments"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIUsage struct {
|
|
|
PromptTokens int `json:"prompt_tokens"`
|
|
|
CompletionTokens int `json:"completion_tokens"`
|
|
|
TotalTokens int `json:"total_tokens"`
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type OpenAIChunk struct {
|
|
|
ID string `json:"id"`
|
|
|
Object string `json:"object"`
|
|
|
Created int64 `json:"created"`
|
|
|
Model string `json:"model"`
|
|
|
Choices []OpenAIChunkChoice `json:"choices"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type OpenAIChunkChoice struct {
|
|
|
Index int `json:"index"`
|
|
|
Delta OpenAIDelta `json:"delta"`
|
|
|
FinishReason *string `json:"finish_reason,omitempty"`
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type OpenAIDelta struct {
|
|
|
Role *string `json:"role,omitempty"`
|
|
|
Content *string `json:"content,omitempty"`
|
|
|
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ErrorResponse struct {
|
|
|
Error APIError `json:"error"`
|
|
|
}
|
|
|
|
|
|
|
|
|
type APIError struct {
|
|
|
Message string `json:"message"`
|
|
|
Type *string `json:"type,omitempty"`
|
|
|
Param *string `json:"param,omitempty"`
|
|
|
Code *string `json:"code,omitempty"`
|
|
|
}
|
|
|
|