|
1 | 1 | package model |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "slices" |
| 5 | + |
| 6 | + "github.com/bytedance/sonic" |
4 | 7 | "github.com/labring/aiproxy/core/model" |
5 | 8 | ) |
6 | 9 |
|
| 10 | +var nullBytes = []byte("null") |
| 11 | + |
| 12 | +type ResponseArguments string |
| 13 | + |
| 14 | +func (a *ResponseArguments) UnmarshalJSON(data []byte) error { |
| 15 | + var s string |
| 16 | + if err := sonic.ConfigDefault.Unmarshal(data, &s); err == nil { |
| 17 | + *a = ResponseArguments(s) |
| 18 | + return nil |
| 19 | + } |
| 20 | + |
| 21 | + if slices.Equal(data, nullBytes) { |
| 22 | + *a = "" |
| 23 | + return nil |
| 24 | + } |
| 25 | + |
| 26 | + *a = ResponseArguments(data) |
| 27 | + |
| 28 | + return nil |
| 29 | +} |
| 30 | + |
| 31 | +func (a ResponseArguments) MarshalJSON() ([]byte, error) { |
| 32 | + return sonic.ConfigDefault.Marshal(string(a)) |
| 33 | +} |
| 34 | + |
| 35 | +func (a ResponseArguments) String() string { |
| 36 | + return string(a) |
| 37 | +} |
| 38 | + |
7 | 39 | // InputItemType represents the type of an input item |
8 | 40 | type InputItemType = string |
9 | 41 |
|
@@ -179,15 +211,15 @@ type OutputContent struct { |
179 | 211 |
|
180 | 212 | // OutputItem represents an output item in a response |
181 | 213 | type OutputItem struct { |
182 | | - ID string `json:"id"` |
183 | | - Type string `json:"type"` |
184 | | - Status ResponseStatus `json:"status,omitempty"` |
185 | | - Role string `json:"role,omitempty"` |
186 | | - Content []OutputContent `json:"content,omitempty"` |
187 | | - Arguments string `json:"arguments,omitempty"` // For function_call type |
188 | | - CallID string `json:"call_id,omitempty"` // For function_call type |
189 | | - Name string `json:"name,omitempty"` // For function_call type |
190 | | - Summary any `json:"summary,omitempty"` // For reasoning type: []SummaryPart or string |
| 214 | + ID string `json:"id"` |
| 215 | + Type string `json:"type"` |
| 216 | + Status ResponseStatus `json:"status,omitempty"` |
| 217 | + Role string `json:"role,omitempty"` |
| 218 | + Content []OutputContent `json:"content,omitempty"` |
| 219 | + Arguments ResponseArguments `json:"arguments,omitempty"` // For function_call type |
| 220 | + CallID string `json:"call_id,omitempty"` // For function_call type |
| 221 | + Name string `json:"name,omitempty"` // For function_call type |
| 222 | + Summary any `json:"summary,omitempty"` // For reasoning type: []SummaryPart or string |
191 | 223 | } |
192 | 224 |
|
193 | 225 | // InputContent represents content in an input item |
@@ -333,18 +365,18 @@ type InputItemList struct { |
333 | 365 |
|
334 | 366 | // ResponseStreamEvent represents a server-sent event for response streaming |
335 | 367 | type ResponseStreamEvent struct { |
336 | | - Type string `json:"type"` |
337 | | - Response *Response `json:"response,omitempty"` |
338 | | - Error *OpenAIError `json:"error,omitempty"` |
339 | | - OutputIndex *int `json:"output_index,omitempty"` |
340 | | - Item *OutputItem `json:"item,omitempty"` |
341 | | - ItemID string `json:"item_id,omitempty"` |
342 | | - ContentIndex *int `json:"content_index,omitempty"` |
343 | | - Part *OutputContent `json:"part,omitempty"` // For content_part events |
344 | | - Delta string `json:"delta,omitempty"` // For text.delta, function_call_arguments.delta |
345 | | - Text string `json:"text,omitempty"` // For text content |
346 | | - Arguments string `json:"arguments,omitempty"` // For function_call_arguments.done |
347 | | - SequenceNumber int `json:"sequence_number,omitempty"` |
| 368 | + Type string `json:"type"` |
| 369 | + Response *Response `json:"response,omitempty"` |
| 370 | + Error *OpenAIError `json:"error,omitempty"` |
| 371 | + OutputIndex *int `json:"output_index,omitempty"` |
| 372 | + Item *OutputItem `json:"item,omitempty"` |
| 373 | + ItemID string `json:"item_id,omitempty"` |
| 374 | + ContentIndex *int `json:"content_index,omitempty"` |
| 375 | + Part *OutputContent `json:"part,omitempty"` // For content_part events |
| 376 | + Delta string `json:"delta,omitempty"` // For text.delta, function_call_arguments.delta |
| 377 | + Text string `json:"text,omitempty"` // For text content |
| 378 | + Arguments ResponseArguments `json:"arguments,omitempty"` // For function_call_arguments.done |
| 379 | + SequenceNumber int `json:"sequence_number,omitempty"` |
348 | 380 | } |
349 | 381 |
|
350 | 382 | func (r *Response) ToolUsageWebSearchCallCount() int64 { |
|
0 commit comments