Split ingress keys into text/image protocols with Replicate model listing.
CI / docker (push) Successful in 3m38s
CI / docker (push) Successful in 3m38s
Add model input defaults (including prompt), workflow model editing, ingress API docs, and fix img2img image upload filenames for signed URLs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -51,6 +51,59 @@ func ParamsForWorkflowType(wt model.WorkflowType) []ParamDef {
|
||||
}
|
||||
}
|
||||
|
||||
func openAPIType(pt ParamType) string {
|
||||
switch pt {
|
||||
case ParamInt:
|
||||
return "integer"
|
||||
case ParamFloat:
|
||||
return "number"
|
||||
default:
|
||||
return "string"
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAPISchemaForWorkflow builds a Replicate-compatible schema with components.schemas.Input.
|
||||
func OpenAPISchemaForWorkflow(wt model.WorkflowType, title, description string, overrides map[string]any) map[string]any {
|
||||
defs := ParamsForWorkflowType(wt)
|
||||
properties := make(map[string]any, len(defs))
|
||||
required := make([]string, 0, len(defs))
|
||||
for i, d := range defs {
|
||||
prop := map[string]any{
|
||||
"type": openAPIType(d.Type),
|
||||
"title": d.Label,
|
||||
"description": d.Label,
|
||||
"x-order": i,
|
||||
}
|
||||
if def, ok := effectiveDefault(d, overrides); ok {
|
||||
prop["default"] = def
|
||||
}
|
||||
properties[d.Name] = prop
|
||||
if d.Required {
|
||||
required = append(required, d.Name)
|
||||
}
|
||||
}
|
||||
inputSchema := map[string]any{
|
||||
"type": "object",
|
||||
"properties": properties,
|
||||
}
|
||||
if len(required) > 0 {
|
||||
inputSchema["required"] = required
|
||||
}
|
||||
return map[string]any{
|
||||
"openapi": "3.0.0",
|
||||
"info": map[string]any{
|
||||
"title": title,
|
||||
"version": "1.0.0",
|
||||
"description": description,
|
||||
},
|
||||
"components": map[string]any{
|
||||
"schemas": map[string]any{
|
||||
"Input": inputSchema,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func RequiredBindings(wt model.WorkflowType) []string {
|
||||
switch wt {
|
||||
case model.WorkflowImg2Img:
|
||||
@@ -61,26 +114,7 @@ func RequiredBindings(wt model.WorkflowType) []string {
|
||||
}
|
||||
|
||||
func ValidateInput(wt model.WorkflowType, input 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 d.Default != nil {
|
||||
out[d.Name] = d.Default
|
||||
}
|
||||
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
|
||||
return ValidateInputWithDefaults(wt, input, nil)
|
||||
}
|
||||
|
||||
func coerceValue(d ParamDef, v any) (any, error) {
|
||||
|
||||
Reference in New Issue
Block a user