-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefinitions.go
More file actions
278 lines (231 loc) · 8.26 KB
/
Copy pathdefinitions.go
File metadata and controls
278 lines (231 loc) · 8.26 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package openrouterapigo
// Request represents the main request structure.
type Request struct {
Messages []MessageRequest `json:"messages,omitempty"`
Prompt string `json:"prompt,omitempty"`
Model string `json:"model,omitempty"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
Stop []string `json:"stop,omitempty"`
Stream bool `json:"stream,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice *ToolChoice `json:"tool_choice,omitempty"`
Seed int `json:"seed,omitempty"`
TopP float64 `json:"top_p,omitempty"`
TopK int `json:"top_k,omitempty"`
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
PresencePenalty float64 `json:"presence_penalty,omitempty"`
RepetitionPenalty float64 `json:"repetition_penalty,omitempty"`
LogitBias map[int]float64 `json:"logit_bias,omitempty"`
TopLogprobs int `json:"top_logprobs,omitempty"`
MinP float64 `json:"min_p,omitempty"`
TopA float64 `json:"top_a,omitempty"`
Prediction *Prediction `json:"prediction,omitempty"`
Transforms []string `json:"transforms,omitempty"`
Models []string `json:"models,omitempty"`
Route string `json:"route,omitempty"`
Provider *ProviderPreferences `json:"provider,omitempty"`
IncludeReasoning bool `json:"include_reasoning,omitempty"`
Plugins []Plugin `json:"plugins,omitempty"`
}
type Plugin struct {
Id int `json:"id"`
Pdf PdfPlugin `json:"pdf"`
}
type PdfPlugin struct {
Engine string `json:"engine"`
}
// ResponseFormat represents the response format structure.
type ResponseFormat struct {
Type string `json:"type"`
}
// Prediction represents the prediction structure.
type Prediction struct {
Type string `json:"type"`
Content string `json:"content"`
}
// ProviderPreferences represents the provider preferences structure.
type ProviderPreferences struct {
RefererURL string `json:"referer_url,omitempty"`
SiteName string `json:"site_name,omitempty"`
}
type MessageRequest struct {
Role MessageRole `json:"role"`
Content []ContentPart `json:"content,omitempty"`
Name string `json:"name,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
func (req MessageRequest) GetRole() MessageRole {
return req.Role
}
func (req MessageRequest) GetContentPart() []ContentPart {
return req.Content
}
func (req MessageRequest) GetToolCalls() []ToolCall {
return req.ToolCalls
}
func (req MessageRequest) GetReasoning() string {
return ""
}
func (req MessageRequest) GetToolCallId() string {
return req.ToolCallID
}
func (req MessageRequest) GetName() string {
return req.Name
}
type MessageRole string
const (
RoleSystem MessageRole = "system"
RoleUser MessageRole = "user"
RoleAssistant MessageRole = "assistant"
RoleTool MessageRole = "tool"
)
// ContentPart represents the content part structure.
type ContentPart struct {
Type ContnetType `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *ImageURL `json:"image_url,omitempty"`
File *FileURL `json:"file,omitempty"`
}
// TextContent creates a text-only content slice for convenience.
func TextContent(text string) []ContentPart {
return []ContentPart{
{
Type: ContentTypeText,
Text: text,
},
}
}
type ContnetType string
const (
ContentTypeText ContnetType = "text"
ContentTypeImage ContnetType = "image_url"
ContentTypePDF ContnetType = "file"
)
type FileURL struct {
Filename string `json:"filename"`
FileData string `json:"file_data"`
}
// ImageURL represents the image URL structure.
type ImageURL struct {
URL string `json:"url"`
Detail string `json:"detail,omitempty"`
}
type FunctionParamType string
const (
StringFunctionParamType FunctionParamType = "string"
IntegerFunctionParamType FunctionParamType = "integer"
NumberFunctionParamType FunctionParamType = "number"
BooleanFunctionParamType FunctionParamType = "boolean"
ArrayFunctionParamType FunctionParamType = "array"
ObjectFunctionParamType FunctionParamType = "object"
)
type FunctionParam struct {
Type FunctionParamType `json:"type"` // "string", "integer", "number", "boolean", "array", "object"
Description string `json:"description,omitempty"`
Enum []string `json:"enum,omitempty"`
Items *FunctionParamItems `json:"items,omitempty"`
Properties map[string]FunctionParam `json:"properties,omitempty"`
}
type FunctionParamItems struct {
Type string `json:"type"` // "string", "integer",
}
type FunctionParametersType string
const DefaultFunctionParametersType FunctionParametersType = "object"
type FunctionParameters struct {
Type FunctionParametersType `json:"type"`
Properties map[string]FunctionParam `json:"properties"`
Required []string `json:"required,omitempty"`
}
// FunctionDescription represents the function description structure.
type FunctionDescription struct {
Description string `json:"description,omitempty"`
Name string `json:"name"`
Parameters map[string]interface{} `json:"parameters"`
}
type ToolType string
const DefaultToolType ToolType = "function"
// Tool represents the tool structure.
type Tool struct {
Type ToolType `json:"type"`
Function FunctionDescription `json:"function"`
}
// ToolChoice represents the tool choice structure.
type ToolChoice struct {
Type string `json:"type"`
Function struct {
Name string `json:"name"`
} `json:"function"`
}
type Response struct {
ID string `json:"id"`
Choices []Choice `json:"choices"`
Created int64 `json:"created"`
Model string `json:"model"`
Object string `json:"object"`
SystemFingerprint *string `json:"system_fingerprint,omitempty"`
Usage *ResponseUsage `json:"usage,omitempty"`
}
type ResponseUsage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
type Choice struct {
FinishReason string `json:"finish_reason"`
Text string `json:"text,omitempty"`
Message *MessageResponse `json:"message,omitempty"`
Delta *Delta `json:"delta,omitempty"`
Error *ErrorResponse `json:"error,omitempty"`
}
type MessageResponse struct {
Content string `json:"content"`
Role MessageRole `json:"role"`
Reasoning string `json:"reasoning,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
func (res MessageResponse) GetRole() MessageRole {
return res.Role
}
func (res MessageResponse) GetContentPart() []ContentPart {
return []ContentPart{
{
Type: ContentTypeText,
Text: res.Content,
},
}
}
func (res MessageResponse) GetToolCalls() []ToolCall {
return res.ToolCalls
}
func (res MessageResponse) GetReasoning() string {
return res.Reasoning
}
func (res MessageResponse) GetToolCallId() string {
return ""
}
func (res MessageResponse) GetName() string {
return ""
}
type Delta struct {
Content string `json:"content"`
Role string `json:"role,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
type ErrorResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function ToolCallFunction `json:"function,omitempty"`
}
type ToolCallFunction struct {
Name string `json:"name,omitempty"`
Arguments string `json:"arguments,omitempty"`
}