|
|
package main |
|
|
|
|
|
import "encoding/json" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ClaudeRequest struct { |
|
|
Model string `json:"model"` |
|
|
Messages []ClaudeMessage `json:"messages"` |
|
|
System json.RawMessage `json:"system,omitempty"` |
|
|
MaxTokens *int `json:"max_tokens,omitempty"` |
|
|
StopSequences []string `json:"stop_sequences,omitempty"` |
|
|
Stream bool `json:"stream,omitempty"` |
|
|
Temperature *float64 `json:"temperature,omitempty"` |
|
|
TopP *float64 `json:"top_p,omitempty"` |
|
|
TopK *int `json:"top_k,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeMessage struct { |
|
|
Role string `json:"role"` |
|
|
Name string `json:"name,omitempty"` |
|
|
Content json.RawMessage `json:"content"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeContentBlock struct { |
|
|
Type string `json:"type"` |
|
|
Text string `json:"text,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeResponse struct { |
|
|
ID string `json:"id"` |
|
|
Type string `json:"type"` |
|
|
Role string `json:"role"` |
|
|
Content []ClaudeContentBlock `json:"content"` |
|
|
Model string `json:"model"` |
|
|
StopReason string `json:"stop_reason"` |
|
|
StopSequence *string `json:"stop_sequence"` |
|
|
Usage ClaudeUsage `json:"usage"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeUsage struct { |
|
|
InputTokens int `json:"input_tokens"` |
|
|
OutputTokens int `json:"output_tokens"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeErrorResponse struct { |
|
|
Type string `json:"type"` |
|
|
Error ClaudeError `json:"error"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeError struct { |
|
|
Type string `json:"type"` |
|
|
Message string `json:"message"` |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type OpenAIRequest struct { |
|
|
Model string `json:"model"` |
|
|
Messages []OpenAIMessage `json:"messages"` |
|
|
MaxTokens *int `json:"max_tokens,omitempty"` |
|
|
Temperature *float64 `json:"temperature,omitempty"` |
|
|
TopP *float64 `json:"top_p,omitempty"` |
|
|
TopK *int `json:"top_k,omitempty"` |
|
|
Stop []string `json:"stop,omitempty"` |
|
|
Stream bool `json:"stream,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
type OpenAIMessage struct { |
|
|
Role string `json:"role"` |
|
|
Content string `json:"content"` |
|
|
} |
|
|
|
|
|
|
|
|
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 OpenAIUsage struct { |
|
|
PromptTokens int `json:"prompt_tokens"` |
|
|
CompletionTokens int `json:"completion_tokens"` |
|
|
TotalTokens int `json:"total_tokens"` |
|
|
} |
|
|
|
|
|
|
|
|
type OpenAIStreamChoice struct { |
|
|
Index int `json:"index"` |
|
|
Delta OpenAIStreamDelta `json:"delta"` |
|
|
FinishReason *string `json:"finish_reason"` |
|
|
} |
|
|
|
|
|
|
|
|
type OpenAIStreamDelta struct { |
|
|
Role *string `json:"role,omitempty"` |
|
|
Content *string `json:"content,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
type OpenAIStreamChunk struct { |
|
|
ID string `json:"id"` |
|
|
Object string `json:"object"` |
|
|
Created int64 `json:"created"` |
|
|
Model string `json:"model"` |
|
|
Choices []OpenAIStreamChoice `json:"choices"` |
|
|
Usage *OpenAIUsage `json:"usage,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ClaudeSSEEvent struct { |
|
|
Type string `json:"type"` |
|
|
Index *int `json:"index,omitempty"` |
|
|
Message *ClaudeSSEMessage `json:"message,omitempty"` |
|
|
ContentBlock *ClaudeSSEContentBlock `json:"content_block,omitempty"` |
|
|
Delta *ClaudeSSEDelta `json:"delta,omitempty"` |
|
|
Usage *ClaudeSSEUsage `json:"usage,omitempty"` |
|
|
Error *ClaudeError `json:"error,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeSSEMessage struct { |
|
|
ID string `json:"id"` |
|
|
Type string `json:"type"` |
|
|
Role string `json:"role"` |
|
|
Content []ClaudeContentBlock `json:"content"` |
|
|
Model string `json:"model"` |
|
|
StopReason *string `json:"stop_reason"` |
|
|
StopSequence *string `json:"stop_sequence"` |
|
|
Usage ClaudeUsage `json:"usage"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeSSEContentBlock struct { |
|
|
Type string `json:"type"` |
|
|
Text string `json:"text"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeSSEDelta struct { |
|
|
Type string `json:"type,omitempty"` |
|
|
Text *string `json:"text,omitempty"` |
|
|
StopReason *string `json:"stop_reason,omitempty"` |
|
|
StopSequence *string `json:"stop_sequence,omitempty"` |
|
|
} |
|
|
|
|
|
|
|
|
type ClaudeSSEUsage struct { |
|
|
InputTokens *int `json:"input_tokens,omitempty"` |
|
|
OutputTokens int `json:"output_tokens"` |
|
|
} |