47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package llm
|
|
|
|
import (
|
|
"fmt"
|
|
"opencatd-open/internal/model"
|
|
|
|
"github.com/sashabaranov/go-openai"
|
|
)
|
|
|
|
type ChatRequest openai.ChatCompletionRequest
|
|
|
|
type ChatResponse openai.ChatCompletionResponse
|
|
|
|
type StreamChatResponse openai.ChatCompletionStreamResponse
|
|
|
|
type ChatMessage openai.ChatCompletionMessage
|
|
|
|
type TokenUsage struct {
|
|
User *model.User
|
|
TokenID int64
|
|
Model string `json:"model"`
|
|
Stream bool
|
|
PromptTokens int `json:"prompt_tokens"`
|
|
CompletionTokens int `json:"completion_tokens"`
|
|
ToolsTokens int `json:"tools_tokens"`
|
|
TotalTokens int `json:"total_tokens"`
|
|
}
|
|
|
|
type ErrorResponse struct {
|
|
Err struct {
|
|
Message string `json:"message,omitempty"`
|
|
Type string `json:"type,omitempty"`
|
|
Param string `json:"param,omitempty"`
|
|
Code string `json:"code,omitempty"`
|
|
} `json:"error,omitempty"`
|
|
HTTPStatusCode int `json:"-"`
|
|
HTTPStatus string `json:"-"`
|
|
}
|
|
|
|
func (e ErrorResponse) Error() string {
|
|
if e.HTTPStatusCode > 0 {
|
|
return fmt.Sprintf("error, status code: %d, status: %s, message: %s", e.HTTPStatusCode, e.HTTPStatus, e.Err.Message)
|
|
}
|
|
|
|
return e.Err.Message
|
|
}
|