mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-29 14:46:38 +08:00
110 lines
4.3 KiB
Go
110 lines
4.3 KiB
Go
package types
|
|
|
|
type ChatCompletionMessage struct {
|
|
Role string `json:"role"`
|
|
Content any `json:"content"`
|
|
Name *string `json:"name,omitempty"`
|
|
FunctionCall any `json:"function_call,omitempty"`
|
|
ToolCalls any `json:"tool_calls,omitempty"`
|
|
ToolCallID string `json:"tool_call_id,omitempty"`
|
|
}
|
|
|
|
func (m ChatCompletionMessage) StringContent() string {
|
|
content, ok := m.Content.(string)
|
|
if ok {
|
|
return content
|
|
}
|
|
contentList, ok := m.Content.([]any)
|
|
if ok {
|
|
var contentStr string
|
|
for _, contentItem := range contentList {
|
|
contentMap, ok := contentItem.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if contentMap["type"] == "text" {
|
|
if subStr, ok := contentMap["text"].(string); ok {
|
|
contentStr += subStr
|
|
}
|
|
}
|
|
}
|
|
return contentStr
|
|
}
|
|
return ""
|
|
}
|
|
|
|
type ChatMessageImageURL struct {
|
|
URL string `json:"url,omitempty"`
|
|
Detail string `json:"detail,omitempty"`
|
|
}
|
|
|
|
type ChatMessagePart struct {
|
|
Type string `json:"type,omitempty"`
|
|
Text string `json:"text,omitempty"`
|
|
ImageURL *ChatMessageImageURL `json:"image_url,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionResponseFormat struct {
|
|
Type string `json:"type,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionRequest struct {
|
|
Model string `json:"model"`
|
|
Messages []ChatCompletionMessage `json:"messages"`
|
|
MaxTokens int `json:"max_tokens,omitempty"`
|
|
Temperature float64 `json:"temperature,omitempty"`
|
|
TopP float64 `json:"top_p,omitempty"`
|
|
N int `json:"n,omitempty"`
|
|
Stream bool `json:"stream,omitempty"`
|
|
Stop []string `json:"stop,omitempty"`
|
|
PresencePenalty float64 `json:"presence_penalty,omitempty"`
|
|
ResponseFormat *ChatCompletionResponseFormat `json:"response_format,omitempty"`
|
|
Seed *int `json:"seed,omitempty"`
|
|
FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
|
|
LogitBias any `json:"logit_bias,omitempty"`
|
|
User string `json:"user,omitempty"`
|
|
Functions any `json:"functions,omitempty"`
|
|
FunctionCall any `json:"function_call,omitempty"`
|
|
Tools any `json:"tools,omitempty"`
|
|
ToolChoice any `json:"tool_choice,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionChoice struct {
|
|
Index int `json:"index"`
|
|
Message ChatCompletionMessage `json:"message"`
|
|
FinishReason any `json:"finish_reason,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionResponse struct {
|
|
ID string `json:"id"`
|
|
Object string `json:"object"`
|
|
Created int64 `json:"created"`
|
|
Model string `json:"model"`
|
|
Choices []ChatCompletionChoice `json:"choices"`
|
|
Usage *Usage `json:"usage,omitempty"`
|
|
SystemFingerprint string `json:"system_fingerprint,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionStreamChoiceDelta struct {
|
|
Content string `json:"content,omitempty"`
|
|
Role string `json:"role,omitempty"`
|
|
FunctionCall any `json:"function_call,omitempty"`
|
|
ToolCalls any `json:"tool_calls,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionStreamChoice struct {
|
|
Index int `json:"index"`
|
|
Delta ChatCompletionStreamChoiceDelta `json:"delta"`
|
|
FinishReason any `json:"finish_reason"`
|
|
ContentFilterResults any `json:"content_filter_results,omitempty"`
|
|
}
|
|
|
|
type ChatCompletionStreamResponse struct {
|
|
ID string `json:"id"`
|
|
Object string `json:"object"`
|
|
Created int64 `json:"created"`
|
|
Model string `json:"model"`
|
|
Choices []ChatCompletionStreamChoice `json:"choices"`
|
|
PromptAnnotations any `json:"prompt_annotations,omitempty"`
|
|
}
|