one-api/types/common.go
Buer ef041e28a1
♻️ refactor: provider refactor (#41)
* ♻️ refactor: provider refactor
* 完善百度/讯飞的函数调用,现在可以在`lobe-chat`中正常调用函数了
2024-01-19 02:47:10 +08:00

37 lines
777 B
Go

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"`
}
type OpenAIErrorResponse struct {
Error OpenAIError `json:"error,omitempty"`
}