You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to see @JsonProperty style of enums with BeanOutputConverter - it'd be great to have an ability to give AI assistant a range of constant values, which aren't just Java String names. That is, I'd love to see something like:
@PostConstructpublicvoiddoSomething() {
varmyWrapper = ChatClient.create(chatModel)
.prompt("Select randomly either \"value.a\" or \"value.b\"")
.call()
.entity(MyWrapper.class);
System.out.println(myWrapper.values);
}
publicrecordMyWrapper(EnumValuesvalues) {
}
publicenumEnumValues {
@JsonProperty("value.a")
A,
@JsonProperty("value.b")
B
}
being a correct way to use structured outputs
Current Behavior
As far as I can see, BeanOutputConverter is not really that much customizable. All the parametrization is done inside of a private method (generateSchema). In theory, one could even use @JsonProperty - it is recognized by the underling Jackson, but not by the schema generator, leading to interesting problems.
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `xyz.SpringAiTest$EnumValues` from String "A": not one of the values accepted for Enum class: [value.a, value.b]
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 2, column: 13] (through reference chain: xyz.SpringAiTest$MyWrapper["values"])
at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:67) ~[jackson-databind-2.18.2.jar:2.18.2]
Context
I wanted to integrate with a service that uses non-standard constants directly, and to select values using AI assistant.
There are other ways this can be done, but as far as I understand, they either include:
Copying BeanOutputConverter and modifying its code
Implementing your own StructuredOutputConverter. For a similar case, I've tried to modify the generated schema myself to account for @JsonProperties and it works, but it's very manual and brittle
Mapping this enum to a String via some different code. Not the worst thing in the world, but it means that I need to refer in the conversations with the AI to the values using Java enum values, as well, as also having some code to map them.
The text was updated successfully, but these errors were encountered:
Expected Behavior
I'd like to see
@JsonProperty
style of enums withBeanOutputConverter
- it'd be great to have an ability to give AI assistant a range of constant values, which aren't just Java String names. That is, I'd love to see something like:being a correct way to use structured outputs
Current Behavior
As far as I can see,
BeanOutputConverter
is not really that much customizable. All the parametrization is done inside of a private method (generateSchema
). In theory, one could even use@JsonProperty
- it is recognized by the underling Jackson, but not by the schema generator, leading to interesting problems.Generated schema for the code above:
Stack trace:
Context
I wanted to integrate with a service that uses non-standard constants directly, and to select values using AI assistant.
There are other ways this can be done, but as far as I understand, they either include:
BeanOutputConverter
and modifying its codeStructuredOutputConverter
. For a similar case, I've tried to modify the generated schema myself to account for@JsonProperties
and it works, but it's very manual and brittleThe text was updated successfully, but these errors were encountered: