Files
Luminary/internal/prediction/defaults.go
T
renjue a4274be444
CI / docker (push) Successful in 4m52s
Split ingress keys into text/image protocols with Replicate model listing.
Text keys use OpenAI routes; image keys use predictions with ingress Model ID,
owner/name or short name resolution, OpenAPI input schemas, editable workflows
with per-field defaults, protocol-aware admin whitelist, and in-app API docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 23:32:13 +08:00

58 lines
1.2 KiB
Go

package prediction
import (
"encoding/json"
"fmt"
"github.com/rose_cat707/luminary/internal/model"
)
func ParseInputDefaults(raw string) (map[string]any, error) {
if raw == "" || raw == "{}" {
return map[string]any{}, nil
}
var out map[string]any
if err := json.Unmarshal([]byte(raw), &out); err != nil {
return nil, err
}
if out == nil {
return map[string]any{}, nil
}
return out, nil
}
func effectiveDefault(d ParamDef, overrides map[string]any) (any, bool) {
if overrides != nil {
if v, ok := overrides[d.Name]; ok {
return v, true
}
}
if d.Default != nil {
return d.Default, true
}
return nil, false
}
func ValidateInputWithDefaults(wt model.WorkflowType, input map[string]any, overrides map[string]any) (map[string]any, error) {
defs := ParamsForWorkflowType(wt)
out := make(map[string]any, len(defs))
for _, d := range defs {
v, ok := input[d.Name]
if !ok || v == nil {
if d.Required {
return nil, fmt.Errorf("missing required field: %s", d.Name)
}
if def, has := effectiveDefault(d, overrides); has {
out[d.Name] = def
}
continue
}
coerced, err := coerceValue(d, v)
if err != nil {
return nil, fmt.Errorf("%s: %w", d.Name, err)
}
out[d.Name] = coerced
}
return out, nil
}