forked from seifghazi/claude-code-proxy
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.go
More file actions
253 lines (218 loc) · 8.08 KB
/
models.go
File metadata and controls
253 lines (218 loc) · 8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package model
import (
"encoding/json"
"time"
)
type ContextKey string
const BodyBytesKey ContextKey = "bodyBytes"
type PromptGrade struct {
Score int `json:"score"`
MaxScore int `json:"maxScore"`
Feedback string `json:"feedback"`
ImprovedPrompt string `json:"improvedPrompt"`
Criteria map[string]CriteriaScore `json:"criteria"`
GradingTimestamp string `json:"gradingTimestamp"`
IsProcessing bool `json:"isProcessing"`
}
type CriteriaScore struct {
Score int `json:"score"`
Feedback string `json:"feedback"`
}
type RequestLog struct {
RequestID string `json:"requestId"`
Timestamp string `json:"timestamp"`
Method string `json:"method"`
Endpoint string `json:"endpoint"`
Headers map[string][]string `json:"headers"`
Body interface{} `json:"body"`
Model string `json:"model,omitempty"`
OriginalModel string `json:"originalModel,omitempty"`
RoutedModel string `json:"routedModel,omitempty"`
UserAgent string `json:"userAgent"`
ContentType string `json:"contentType"`
PromptGrade *PromptGrade `json:"promptGrade,omitempty"`
Response *ResponseLog `json:"response,omitempty"`
}
// RequestSummary is a lightweight version of RequestLog for list views
type RequestSummary struct {
RequestID string `json:"requestId"`
Timestamp string `json:"timestamp"`
Method string `json:"method"`
Endpoint string `json:"endpoint"`
Model string `json:"model,omitempty"`
OriginalModel string `json:"originalModel,omitempty"`
RoutedModel string `json:"routedModel,omitempty"`
StatusCode int `json:"statusCode,omitempty"`
ResponseTime int64 `json:"responseTime,omitempty"`
Usage *AnthropicUsage `json:"usage,omitempty"`
}
type ResponseLog struct {
StatusCode int `json:"statusCode"`
Headers map[string][]string `json:"headers"`
Body json.RawMessage `json:"body,omitempty"`
BodyText string `json:"bodyText,omitempty"`
ResponseTime int64 `json:"responseTime"`
StreamingChunks []string `json:"streamingChunks,omitempty"`
IsStreaming bool `json:"isStreaming"`
CompletedAt string `json:"completedAt"`
}
type ChatMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
Stream bool `json:"stream,omitempty"`
}
type AnthropicUsage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
CacheReadInputTokens int `json:"cache_read_input_tokens,omitempty"`
ServiceTier string `json:"service_tier,omitempty"`
}
type AnthropicResponse struct {
Content []AnthropicContentBlock `json:"content"`
ID string `json:"id"`
Model string `json:"model"`
Role string `json:"role"`
StopReason string `json:"stop_reason"`
StopSequence *string `json:"stop_sequence"`
Type string `json:"type"`
Usage AnthropicUsage `json:"usage"`
}
type AnthropicContentBlock struct {
Type string `json:"type"`
Text string `json:"text"`
}
type AnthropicMessage struct {
Role string `json:"role"`
Content interface{} `json:"content"`
}
func (m *AnthropicMessage) GetContentBlocks() []AnthropicContentBlock {
switch v := m.Content.(type) {
case string:
return []AnthropicContentBlock{{Type: "text", Text: v}}
case []interface{}:
var blocks []AnthropicContentBlock
for _, item := range v {
if block, ok := item.(map[string]interface{}); ok {
if typ, hasType := block["type"].(string); hasType {
if text, hasText := block["text"].(string); hasText {
blocks = append(blocks, AnthropicContentBlock{Type: typ, Text: text})
}
}
}
}
return blocks
case []AnthropicContentBlock:
return v
default:
return []AnthropicContentBlock{}
}
}
type AnthropicSystemMessage struct {
Text string `json:"text"`
Type string `json:"type"`
CacheControl *CacheControl `json:"cache_control,omitempty"`
}
type CacheControl struct {
Type string `json:"type"`
}
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema InputSchema `json:"input_schema"`
}
type InputSchema struct {
Type string `json:"type"`
Properties map[string]interface{} `json:"properties"`
Required []string `json:"required,omitempty"`
}
type AnthropicRequest struct {
Model string `json:"model"`
Messages []AnthropicMessage `json:"messages"`
MaxTokens int `json:"max_tokens"`
Temperature *float64 `json:"temperature,omitempty"`
System []AnthropicSystemMessage `json:"system,omitempty"`
Stream bool `json:"stream,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice interface{} `json:"tool_choice,omitempty"`
}
type ModelsResponse struct {
Object string `json:"object"`
Data []ModelInfo `json:"data"`
}
type ModelInfo struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
OwnedBy string `json:"owned_by"`
}
type GradeRequest struct {
Messages []AnthropicMessage `json:"messages"`
SystemMessages []AnthropicSystemMessage `json:"systemMessages"`
RequestID string `json:"requestId,omitempty"`
}
type HealthResponse struct {
Status string `json:"status"`
Timestamp time.Time `json:"timestamp"`
}
type ErrorResponse struct {
Error string `json:"error"`
Details string `json:"details,omitempty"`
}
type StreamingEvent struct {
Type string `json:"type"`
Index *int `json:"index,omitempty"`
Delta *Delta `json:"delta,omitempty"`
ContentBlock *ContentBlock `json:"content_block,omitempty"`
}
type Delta struct {
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
}
type ContentBlock struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
Text string `json:"text,omitempty"`
}
// Dashboard stats structures
type DashboardStats struct {
DailyStats []DailyTokens `json:"dailyStats"`
}
type HourlyStatsResponse struct {
HourlyStats []HourlyTokens `json:"hourlyStats"`
TodayTokens int64 `json:"todayTokens"`
TodayRequests int `json:"todayRequests"`
AvgResponseTime int64 `json:"avgResponseTime"`
}
type ModelStatsResponse struct {
ModelStats []ModelTokens `json:"modelStats"`
}
type DailyTokens struct {
Date string `json:"date"`
Tokens int64 `json:"tokens"`
Requests int `json:"requests"`
Models map[string]ModelStats `json:"models,omitempty"` // Per-model breakdown
}
type HourlyTokens struct {
Hour int `json:"hour"`
Tokens int64 `json:"tokens"`
Requests int `json:"requests"`
Models map[string]ModelStats `json:"models,omitempty"` // Per-model breakdown
}
type ModelStats struct {
Tokens int64 `json:"tokens"`
Requests int `json:"requests"`
}
type ModelTokens struct {
Model string `json:"model"`
Tokens int64 `json:"tokens"`
Requests int `json:"requests"`
}