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
Here is the issue (coming from simple-openai). This specific instance happened during tool calls.
Oct 30 18:01:37.882
i-0c37647db12b51de5
invisible
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.LocalDate` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
Oct 30 18:01:37.882
i-0c37647db12b51de5
invisible
... 51 more
Oct 30 18:01:37.882
i-0c37647db12b51de5
invisible
at io.github.sashirestela.openai.common.function.FunctionExecutor.execute(FunctionExecutor.java:81)
In our code we always do this when we need to handle dates
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
...
private static final ObjectMapper mapper =
new ObjectMapper()
.registerModule(new JavaTimeModule())
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
Cleverclient shouldn't do that, because it may not always be needed and other use cases may require other module.
Instead it should be possible to pass an external ObjectMapper that will be passed to JsonUtilobjectToMap()
I suggest to add another objectToMap() method that takes an external ObjectMapper like so:
public static <T> Map<String, Object> objectToMap(T object) {
try {
return objectMapperStrict.convertValue(object, new TypeReference<>() {
});
} catch (IllegalArgumentException e) {
throw new CleverClientException("Cannot convert object {0} to Map.", object, e);
}
}
public static <T> Map<String, Object> objectToMap(T object, ObjectMapper objectMapper) {
try {
return objectMapper.convertValue(object, new TypeReference<>() {
});
} catch (IllegalArgumentException e) {
throw new CleverClientException("Cannot convert object {0} to Map.", object, e);
}
}
The original objectToMap() can just call it then with the static object mapper like so:
public static <T> Map<String, Object> objectToMap(T object) {
return objectToMap(object, objectMapperStrict);
}
public static <T> Map<String, Object> objectToMap(T object, ObjectMapper objectMapper) {
try {
return objectMapper.convertValue(object, new TypeReference<>() {
});
} catch (IllegalArgumentException e) {
throw new CleverClientException("Cannot convert object {0} to Map.", object, e);
}
}
There is a similar situation with jsonToXXX() methods, which use internally the objectReaderIgnoringUnknown.
private static final ObjectReader objectReaderIgnoringUnknown = objectMapperStrict.reader()
.without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
They need to support an external ObjectReader too. For example:
public static <T> T jsonToObject(String json, Class<T> clazz, ObjectReader objectReader) {
try {
return objectReader.readValue(json, clazz);
} catch (IOException e) {
throw new CleverClientException("Cannot convert the Json {0} to class {1}.", json, clazz.getName(), e);
}
}
I opened a corresponding issue in simple-openai, becuase once this is implemented, so simple-openai should be able to be configured with an external object mapper and/or object reader and use it when calling JsonUtil methods.
the-gigi
changed the title
Cleverclient uses an internal ObjectMapper in JsonUtils that fails to handle dates
Cleverclient uses an internal ObjectMapper in JsonUtils that fails to deserialize dates
Oct 31, 2024
sashirestela
changed the title
Cleverclient uses an internal ObjectMapper in JsonUtils that fails to deserialize dates
Support for using external Json ObjectMapper
Nov 18, 2024
Here is the issue (coming from simple-openai). This specific instance happened during tool calls.
In our code we always do this when we need to handle dates
Cleverclient shouldn't do that, because it may not always be needed and other use cases may require other module.
Instead it should be possible to pass an external ObjectMapper that will be passed to JsonUtilobjectToMap()
I suggest to add another objectToMap() method that takes an external ObjectMapper like so:
The original objectToMap() can just call it then with the static object mapper like so:
There is a similar situation with jsonToXXX() methods, which use internally the
objectReaderIgnoringUnknown
.They need to support an external ObjectReader too. For example:
I opened a corresponding issue in simple-openai, becuase once this is implemented, so simple-openai should be able to be configured with an external object mapper and/or object reader and use it when calling JsonUtil methods.
sashirestela/simple-openai#205
The text was updated successfully, but these errors were encountered: