2023-08-20 12:04:45 +00:00
|
|
|
package schema
|
2023-07-14 23:19:43 +00:00
|
|
|
|
|
|
|
import (
|
2023-07-24 21:10:54 +00:00
|
|
|
"context"
|
2023-08-07 20:39:10 +00:00
|
|
|
|
2024-06-23 08:24:36 +00:00
|
|
|
functions "github.com/mudler/LocalAI/pkg/functions"
|
2023-07-14 23:19:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// APIError provides error information returned by the OpenAI API.
|
|
|
|
type APIError struct {
|
|
|
|
Code any `json:"code,omitempty"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
Param *string `json:"param,omitempty"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorResponse struct {
|
|
|
|
Error *APIError `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpenAIUsage struct {
|
|
|
|
PromptTokens int `json:"prompt_tokens"`
|
|
|
|
CompletionTokens int `json:"completion_tokens"`
|
|
|
|
TotalTokens int `json:"total_tokens"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Item struct {
|
|
|
|
Embedding []float32 `json:"embedding"`
|
|
|
|
Index int `json:"index"`
|
|
|
|
Object string `json:"object,omitempty"`
|
|
|
|
|
|
|
|
// Images
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
B64JSON string `json:"b64_json,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpenAIResponse struct {
|
|
|
|
Created int `json:"created,omitempty"`
|
|
|
|
Object string `json:"object,omitempty"`
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Model string `json:"model,omitempty"`
|
|
|
|
Choices []Choice `json:"choices,omitempty"`
|
|
|
|
Data []Item `json:"data,omitempty"`
|
|
|
|
|
|
|
|
Usage OpenAIUsage `json:"usage"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Choice struct {
|
2023-07-21 22:53:52 +00:00
|
|
|
Index int `json:"index"`
|
2024-02-24 10:51:59 +00:00
|
|
|
FinishReason string `json:"finish_reason"`
|
2023-07-14 23:19:43 +00:00
|
|
|
Message *Message `json:"message,omitempty"`
|
|
|
|
Delta *Message `json:"delta,omitempty"`
|
|
|
|
Text string `json:"text,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-11-11 12:14:59 +00:00
|
|
|
type Content struct {
|
|
|
|
Type string `json:"type" yaml:"type"`
|
|
|
|
Text string `json:"text" yaml:"text"`
|
|
|
|
ImageURL ContentURL `json:"image_url" yaml:"image_url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentURL struct {
|
|
|
|
URL string `json:"url" yaml:"url"`
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
type Message struct {
|
|
|
|
// The message role
|
|
|
|
Role string `json:"role,omitempty" yaml:"role"`
|
2024-02-17 09:00:34 +00:00
|
|
|
|
|
|
|
// The message name (used for tools calls)
|
|
|
|
Name string `json:"name,omitempty" yaml:"name"`
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
// The message content
|
2023-11-11 12:14:59 +00:00
|
|
|
Content interface{} `json:"content" yaml:"content"`
|
|
|
|
|
|
|
|
StringContent string `json:"string_content,omitempty" yaml:"string_content,omitempty"`
|
|
|
|
StringImages []string `json:"string_images,omitempty" yaml:"string_images,omitempty"`
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
// A result of a function call
|
|
|
|
FunctionCall interface{} `json:"function_call,omitempty" yaml:"function_call,omitempty"`
|
2024-02-17 09:00:34 +00:00
|
|
|
|
|
|
|
ToolCalls []ToolCall `json:"tool_calls,omitempty" yaml:"tool_call,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ToolCall struct {
|
|
|
|
Index int `json:"index"`
|
|
|
|
ID string `json:"id"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
FunctionCall FunctionCall `json:"function"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type FunctionCall struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Arguments string `json:"arguments"`
|
2023-07-14 23:19:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type OpenAIModel struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Object string `json:"object"`
|
|
|
|
}
|
|
|
|
|
2024-05-29 12:40:54 +00:00
|
|
|
type ImageGenerationResponseFormat string
|
|
|
|
|
2023-11-15 18:36:23 +00:00
|
|
|
type ChatCompletionResponseFormatType string
|
|
|
|
|
|
|
|
type ChatCompletionResponseFormat struct {
|
|
|
|
Type ChatCompletionResponseFormatType `json:"type,omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
type OpenAIRequest struct {
|
2024-03-01 15:19:53 +00:00
|
|
|
PredictionOptions
|
2023-07-14 23:19:43 +00:00
|
|
|
|
2024-04-18 20:43:12 +00:00
|
|
|
Context context.Context `json:"-"`
|
2024-03-01 15:19:53 +00:00
|
|
|
Cancel context.CancelFunc `json:"-"`
|
2023-07-24 21:10:54 +00:00
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
// whisper
|
|
|
|
File string `json:"file" validate:"required"`
|
|
|
|
//whisper/image
|
2024-05-29 12:40:54 +00:00
|
|
|
ResponseFormat interface{} `json:"response_format,omitempty"`
|
2023-07-14 23:19:43 +00:00
|
|
|
// image
|
|
|
|
Size string `json:"size"`
|
|
|
|
// Prompt is read only by completion/image API calls
|
|
|
|
Prompt interface{} `json:"prompt" yaml:"prompt"`
|
|
|
|
|
|
|
|
// Edit endpoint
|
|
|
|
Instruction string `json:"instruction" yaml:"instruction"`
|
|
|
|
Input interface{} `json:"input" yaml:"input"`
|
|
|
|
|
|
|
|
Stop interface{} `json:"stop" yaml:"stop"`
|
|
|
|
|
|
|
|
// Messages is read only by chat/completion API calls
|
|
|
|
Messages []Message `json:"messages" yaml:"messages"`
|
|
|
|
|
|
|
|
// A list of available functions to call
|
2024-04-18 20:43:12 +00:00
|
|
|
Functions functions.Functions `json:"functions" yaml:"functions"`
|
|
|
|
FunctionCall interface{} `json:"function_call" yaml:"function_call"` // might be a string or an object
|
2023-07-14 23:19:43 +00:00
|
|
|
|
2024-04-18 20:43:12 +00:00
|
|
|
Tools []functions.Tool `json:"tools,omitempty" yaml:"tools"`
|
|
|
|
ToolsChoice interface{} `json:"tool_choice,omitempty" yaml:"tool_choice"`
|
2024-02-17 09:00:34 +00:00
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
Stream bool `json:"stream"`
|
|
|
|
|
|
|
|
// Image (not supported by OpenAI)
|
|
|
|
Mode int `json:"mode"`
|
|
|
|
Step int `json:"step"`
|
|
|
|
|
|
|
|
// A grammar to constrain the LLM output
|
|
|
|
Grammar string `json:"grammar" yaml:"grammar"`
|
|
|
|
|
2024-05-11 23:13:22 +00:00
|
|
|
JSONFunctionGrammarObject *functions.JSONFunctionStructureFunction `json:"grammar_json_functions" yaml:"grammar_json_functions"`
|
|
|
|
JSONFunctionGrammarObjectName *functions.JSONFunctionStructureName `json:"grammar_json_name" yaml:"grammar_json_name"`
|
2023-08-07 20:39:10 +00:00
|
|
|
|
|
|
|
Backend string `json:"backend" yaml:"backend"`
|
|
|
|
|
|
|
|
// AutoGPTQ
|
|
|
|
ModelBaseName string `json:"model_base_name" yaml:"model_base_name"`
|
2023-07-14 23:19:43 +00:00
|
|
|
}
|