Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/lipgloss v0.8.0
github.com/cli/browser v1.3.0
github.com/getkin/kin-openapi v0.123.0
github.com/getkin/kin-openapi v0.125.0
github.com/mattn/go-isatty v0.0.20
github.com/replicate/replicate-go v0.18.1
github.com/schollz/progressbar/v3 v3.13.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8=
github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/getkin/kin-openapi v0.125.0 h1:jyQCyf2qXS1qvs2U00xQzkGCqYPhEhZDmSmVt65fXno=
github.com/getkin/kin-openapi v0.125.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/swag v0.22.8 h1:/9RjDSQ0vbFR+NyjGMkFTsA1IA0fmhKSThmfGZjicbw=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/model/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func printModelVersionSchema(version *replicate.ModelVersion) error {
if outputSchema != nil {
fmt.Println("Output:")
fmt.Printf("- type: %s\n", outputSchema.Type)
if outputSchema.Type == "array" {
if outputSchema.Type.Is("array") {
fmt.Printf("- items: %s %s\n", outputSchema.Items.Value.Type, outputSchema.Items.Value.Format)
}
fmt.Println()
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/prediction/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ var CreateCmd = &cobra.Command{
shouldWait := (cmd.Flags().Changed("wait") || !cmd.Flags().Changed("no-wait"))

canStream := (outputSchema != nil &&
outputSchema.Type == "array" &&
outputSchema.Items.Value.Type == "string" &&
outputSchema.Type.Is("array") &&
outputSchema.Items.Value.Type.Is("string") &&
outputSchema.Extensions["x-cog-array-type"] == "iterator" &&
outputSchema.Extensions["x-cog-array-display"] == "concatenate")
shouldStream := canStream && !cmd.Flags().Changed("wait") &&
Expand Down
42 changes: 23 additions & 19 deletions internal/util/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,19 @@ func coerceType(input string, schema *openapi3.Schema) (interface{}, error) {
return input, nil
}

switch schema.Type {
case "integer":
if schema.Type.Is("integer") {
return convertToInt(input)
case "number":
}
if schema.Type.Is("number") {
return convertToFloat(input)
case "boolean":
}
if schema.Type.Is("boolean") {
return convertToBool(input)
case "string":
}
if schema.Type.Is("string") {
return convertToString(input)
case "array":
}
if schema.Type.Is("array") {
var value []interface{}
err := json.Unmarshal([]byte(input), &value)
if err != nil {
Expand All @@ -130,21 +133,22 @@ func coerceType(input string, schema *openapi3.Schema) (interface{}, error) {
}

return value, nil
default:
// If the property has a default value, attempt to convert to that type
switch schema.Default.(type) {
case int:
return convertToInt(input)
case float64:
return convertToFloat(input)
case bool:
return convertToBool(input)
case string:
return convertToString(input)
}
}

return nil, fmt.Errorf("unknown type %s", schema.Type)
// If the property has a default value, attempt to convert to that type
switch schema.Default.(type) {
case int:
return convertToInt(input)
case float64:
return convertToFloat(input)
case bool:
return convertToBool(input)
case string:
return convertToString(input)
}

return nil, fmt.Errorf("unknown type %s", schema.Type)

}

// convertToString is a no-op
Expand Down
14 changes: 7 additions & 7 deletions internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,34 @@ func TestParseInputs(t *testing.T) {

func TestCoerceTypesWithSchema(t *testing.T) {
schema := openapi3.NewSchema()
schema.Type = "object"
schema.Type = &openapi3.Types{openapi3.TypeObject}
schema.Properties = map[string]*openapi3.SchemaRef{
"integer": {
Value: &openapi3.Schema{
Type: "integer",
Type: &openapi3.Types{openapi3.TypeInteger},
},
},
"number": {
Value: &openapi3.Schema{
Type: "number",
Type: &openapi3.Types{openapi3.TypeNumber},
},
},
"boolean": {
Value: &openapi3.Schema{
Type: "boolean",
Type: &openapi3.Types{openapi3.TypeBoolean},
},
},
"string": {
Value: &openapi3.Schema{
Type: "string",
Type: &openapi3.Types{openapi3.TypeString},
},
},
"array_of_integers": {
Value: &openapi3.Schema{
Type: "array",
Type: &openapi3.Types{openapi3.TypeArray},
Items: &openapi3.SchemaRef{
Value: &openapi3.Schema{
Type: "integer",
Type: &openapi3.Types{openapi3.TypeInteger},
},
},
},
Expand Down