43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package llm
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/sashabaranov/go-openai"
|
|
)
|
|
|
|
type ChatRequest openai.ChatCompletionRequest
|
|
|
|
type ChatResponse openai.ChatCompletionResponse
|
|
|
|
type StreamChatResponse openai.ChatCompletionStreamResponse
|
|
|
|
type ChatMessage openai.ChatCompletionMessage
|
|
|
|
type TokenUsage struct {
|
|
Model string `json:"model"`
|
|
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
|
|
}
|