mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-28 17:18:49 -04:00
* feat: add OpenAI Decisions adapter with validated ordered answers Share SystemOne execution and preserve ordered, typed Decisions answers. Reject null probabilities and derive scores from the emitted distribution. Cover conversion and handler contracts using a valid generated PNG fixture. Assisted-by: nib:gpt-6-astra Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: preserve Decisions choice types and empty score labels Keep canonical JSON values in model-visible choice criteria and represent probability label presence explicitly. Add conversion and serialization regressions. Assisted-by: nib:gpt-6-astra Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat: wire the OpenAI Decisions route Expose the adapter through the shared Decisions feature gate and usage middleware. Test real route registration with a fake backend, including unauthenticated access, user permissions, and exact usage accounting. Assisted-by: nib:gpt-6-astra Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs: document OpenAI-compatible decisions and discovery Describe the shared local execution contract, typed questions, image limits, and backend accounting. Publish the Decisions route in Swagger and retain the existing SystemOne discovery tag. Use documented loose object placeholders for JSON unions that Swagger 2 cannot express. Assisted-by: nib:gpt-6-astra Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
73 lines
3.1 KiB
Go
73 lines
3.1 KiB
Go
// SPDX-License-Identifier: MIT
|
|
package schema
|
|
|
|
import "encoding/json"
|
|
|
|
// DecisionsRequest is the OpenAI Decisions wire contract, distinct from SystemOne.
|
|
type DecisionsRequest struct {
|
|
Model string `json:"model"`
|
|
// Input is a text string or an array of user messages. Swagger 2 uses a loose object placeholder for this union.
|
|
Input json.RawMessage `json:"input" swaggertype:"object"`
|
|
Questions []DecisionQuestion `json:"questions"`
|
|
SafetyIdentifier *string `json:"safety_identifier,omitempty"`
|
|
}
|
|
|
|
type DecisionQuestion struct {
|
|
Type string `json:"type"`
|
|
Name *string `json:"name,omitempty"`
|
|
Instructions *string `json:"instructions"`
|
|
Choices []DecisionChoice `json:"choices,omitempty"`
|
|
Levels []DecisionLevel `json:"levels,omitempty"`
|
|
}
|
|
type DecisionChoice struct {
|
|
// Value is a string or boolean choice. Swagger 2 uses a loose object placeholder for this union.
|
|
Value json.RawMessage `json:"value" swaggertype:"object"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
type DecisionLevel struct {
|
|
Label *string `json:"label"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
type DecisionInputMessage struct {
|
|
Type string `json:"type,omitempty"`
|
|
Role string `json:"role"`
|
|
// Content is a text string or an array of input_text/input_image parts. Swagger 2 uses a loose object placeholder for this union.
|
|
Content json.RawMessage `json:"content" swaggertype:"object"`
|
|
}
|
|
type DecisionInputPart struct {
|
|
Type string `json:"type"`
|
|
Text *string `json:"text,omitempty"`
|
|
ImageURL string `json:"image_url,omitempty"`
|
|
Detail *string `json:"detail,omitempty"`
|
|
}
|
|
type DecisionsResponse struct {
|
|
Model string `json:"model"`
|
|
Answers []DecisionAnswer `json:"answers"`
|
|
Usage DecisionUsage `json:"usage"`
|
|
}
|
|
type DecisionAnswer struct {
|
|
Type string `json:"type"`
|
|
Name *string `json:"name,omitempty"`
|
|
Probability *float64 `json:"probability,omitempty"`
|
|
// Choice preserves the selected string or boolean value. Swagger 2 uses a loose object placeholder for this union.
|
|
Choice json.RawMessage `json:"choice,omitempty" swaggertype:"object"`
|
|
Score *float64 `json:"score,omitempty"`
|
|
Confidence *float64 `json:"confidence,omitempty"`
|
|
Probabilities []DecisionProbability `json:"probabilities,omitempty"`
|
|
}
|
|
type DecisionProbability struct {
|
|
// Value is a string or boolean for choices, or a zero-based integer for score levels. Swagger 2 uses a loose object placeholder for this union.
|
|
Value json.RawMessage `json:"value" swaggertype:"object"`
|
|
Label *string `json:"label,omitempty"`
|
|
Probability float64 `json:"probability"`
|
|
}
|
|
|
|
// Unknown accounting details are omitted, not invented as zero counts.
|
|
type DecisionUsage struct {
|
|
InputTokens int `json:"input_tokens"`
|
|
OutputTokens int `json:"output_tokens"`
|
|
TotalTokens int `json:"total_tokens"`
|
|
InputTokensDetails map[string]int `json:"input_tokens_details"`
|
|
OutputTokensDetails map[string]int `json:"output_tokens_details"`
|
|
}
|