Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ollama tools is not compatible with a json shema containing an array in a "type" field (kotlin) #2047

Open
PheelTi opened this issue Jan 6, 2025 · 0 comments

Comments

@PheelTi
Copy link

PheelTi commented Jan 6, 2025

Bug description
When generating a json schema for a function callback input type in Kotlin, if a property is nullable in the Kotlin language like this field1 :

    class MyFunction() : java.util.function.Function<MyFunction.Request, String?> {
        @JvmRecord
        data class Request(
            val field1: Int?)

        override fun apply(r: Request): String {
            return "OK"
        }
    }

    @Bean
    fun myFunctionBean(): FunctionCallback =
        FunctionCallback.builder()
            .function("myFunctionBean", MyFunction())
            .inputType(MyFunction.Request::class.java)
            .description("description of my function")
            .build()

the json schema generated will be like :

{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "type" : "object",
  "properties" : {
    "field1" : {
      "type" : [ "integer", "null" ],
      "format" : "int32",
    }
  }
}

But all Ollama calls will fail in a HTTP 400 error with this message :
[400] Bad Request - {"error":"json: cannot unmarshal array into Go struct field .tools.function.parameters.properties.type of type string"}

I also tried to add @field:NotNull annotation, or set a default value val field1: Int? = null without success.

Environment
Spring AI version : 1.0.0-M5
Kotlin version : 1.9.25

Steps to reproduce

see bug description

Expected behavior

The json schema should look like below.:

{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "type" : "object",
  "properties" : {
    "field1" : {
      "type" : "integer",
      "format" : "int32",
    }
  }
}

More generally, providing easy customization of json schema generation could be great... But there's quite lot of work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant