forked from MartialBE/one-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
41 lines (33 loc) · 889 Bytes
/
common.go
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
package types
import "encoding/json"
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}
type OpenAIError struct {
Code any `json:"code,omitempty"`
Message string `json:"message"`
Param string `json:"param,omitempty"`
Type string `json:"type"`
InnerError any `json:"innererror,omitempty"`
}
func (e *OpenAIError) Error() string {
response := &OpenAIErrorResponse{
Error: *e,
}
// 转换为JSON
bytes, _ := json.Marshal(response)
return string(bytes)
}
type OpenAIErrorWithStatusCode struct {
OpenAIError
StatusCode int `json:"status_code"`
LocalError bool `json:"-"`
}
type OpenAIErrorResponse struct {
Error OpenAIError `json:"error,omitempty"`
}
type StreamOptions struct {
IncludeUsage bool `json:"include_usage,omitempty"`
}