Files
new-api/dto/openai_response.go

135 lines
4.3 KiB
Go
Raw Normal View History

2024-02-29 01:08:18 +08:00
package dto
2024-03-21 14:29:56 +08:00
type TextResponseWithError struct {
2024-03-21 23:44:39 +08:00
Id string `json:"id"`
2024-03-21 17:39:05 +08:00
Object string `json:"object"`
2024-03-21 23:44:39 +08:00
Created int64 `json:"created"`
Choices []OpenAITextResponseChoice `json:"choices"`
2024-03-21 17:39:05 +08:00
Data []OpenAIEmbeddingResponseItem `json:"data"`
Model string `json:"model"`
2024-03-21 14:29:56 +08:00
Usage `json:"usage"`
Error OpenAIError `json:"error"`
}
type SimpleResponse struct {
Usage `json:"usage"`
Error OpenAIError `json:"error"`
Choices []OpenAITextResponseChoice `json:"choices"`
}
2024-02-29 01:08:18 +08:00
type TextResponse struct {
2024-03-21 23:44:39 +08:00
Id string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
2024-03-21 17:39:05 +08:00
Model string `json:"model"`
2024-03-21 14:29:56 +08:00
Choices []OpenAITextResponseChoice `json:"choices"`
2024-02-29 01:08:18 +08:00
Usage `json:"usage"`
}
type OpenAITextResponseChoice struct {
Index int `json:"index"`
Message `json:"message"`
FinishReason string `json:"finish_reason"`
}
type OpenAITextResponse struct {
Id string `json:"id"`
Model string `json:"model"`
2024-02-29 01:08:18 +08:00
Object string `json:"object"`
Created int64 `json:"created"`
Choices []OpenAITextResponseChoice `json:"choices"`
Usage `json:"usage"`
}
type OpenAIEmbeddingResponseItem struct {
Object string `json:"object"`
Index int `json:"index"`
Embedding []float64 `json:"embedding"`
}
type OpenAIEmbeddingResponse struct {
Object string `json:"object"`
Data []OpenAIEmbeddingResponseItem `json:"data"`
Model string `json:"model"`
Usage `json:"usage"`
}
type ChatCompletionsStreamResponseChoice struct {
2024-04-25 23:57:39 +08:00
Delta ChatCompletionsStreamResponseChoiceDelta `json:"delta,omitempty"`
2024-04-26 02:56:35 +08:00
Logprobs *any `json:"logprobs"`
2024-04-25 23:57:39 +08:00
FinishReason *string `json:"finish_reason"`
2024-04-26 02:56:35 +08:00
Index int `json:"index"`
2024-04-22 16:35:56 +08:00
}
type ChatCompletionsStreamResponseChoiceDelta struct {
2024-04-25 23:57:39 +08:00
Content *string `json:"content,omitempty"`
2024-04-22 16:35:56 +08:00
Role string `json:"role,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}
2024-04-25 23:57:39 +08:00
func (c *ChatCompletionsStreamResponseChoiceDelta) SetContentString(s string) {
c.Content = &s
}
func (c *ChatCompletionsStreamResponseChoiceDelta) GetContentString() string {
if c.Content == nil {
return ""
}
return *c.Content
}
2024-04-22 16:35:56 +08:00
type ToolCall struct {
// Index is not nil only in chat completion chunk object
Index *int `json:"index,omitempty"`
ID string `json:"id"`
Type any `json:"type"`
Function FunctionCall `json:"function"`
}
type FunctionCall struct {
2024-07-18 00:36:05 +08:00
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
2024-04-22 16:35:56 +08:00
// call function with arguments in JSON format
2024-07-18 00:36:05 +08:00
Parameters any `json:"parameters,omitempty"` // request
Arguments string `json:"arguments,omitempty"`
2024-02-29 01:08:18 +08:00
}
type ChatCompletionsStreamResponse struct {
2024-04-26 02:56:35 +08:00
Id string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
SystemFingerprint *string `json:"system_fingerprint"`
Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
2024-07-08 01:45:43 +08:00
Usage *Usage `json:"usage"`
2024-02-29 01:08:18 +08:00
}
2024-07-15 18:04:05 +08:00
func (c *ChatCompletionsStreamResponse) GetSystemFingerprint() string {
if c.SystemFingerprint == nil {
return ""
}
return *c.SystemFingerprint
}
func (c *ChatCompletionsStreamResponse) SetSystemFingerprint(s string) {
c.SystemFingerprint = &s
}
2024-02-29 01:08:18 +08:00
type ChatCompletionsStreamResponseSimple struct {
Choices []ChatCompletionsStreamResponseChoice `json:"choices"`
2024-07-08 01:27:57 +08:00
Usage *Usage `json:"usage"`
2024-02-29 01:08:18 +08:00
}
type CompletionsStreamResponse struct {
Choices []struct {
Text string `json:"text"`
FinishReason string `json:"finish_reason"`
} `json:"choices"`
}
2024-03-08 18:25:57 +08:00
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
}