Closed the-gigi closed 3 days ago
Setting an ObjectMapper
on the SimpleOpenAI.Builder
would be helpful, preferred actually. When using SimpleOpenAI
from Kotlin you generally want "everything" to include the Kotlin module.
Setting an
ObjectMapper
on theSimpleOpenAI.Builder
would be helpful, preferred actually. When usingSimpleOpenAI
from Kotlin you generally want "everything" to include the Kotlin module.
The issue is that for different calls to jsonToObject() you may want a different ObjectReader. If it is set at the SimpleOpenAI level then whenever you need a different ObjectReader you'll have to create a new instance of SimpleOpenAI (which means passing around the API key + other initialization data).
My use of preferred
was in reference to our situation, needing to register a single mapper to make "anything" work. I wasn't discounting your suggestion. It seems easy enough to provide both!
Agreed. Both options can be useful for different workflows.
@the-gigi Due to my limited time availability, I prefer the option proposed by @kdubb, which involves less change. I think it could cover your requirements, but I would like to know if you agree, so I can start working on this change.
@sashirestela Yes. We can make it work for our requirements. We can aggregate the custom data types we need across all use cases into one big unified ObjectMapper that can serialize everything we need.
Thanks for adding this important capability.
@sashirestela I'm also happy to see the usage of simple-openai growing and more and more requests are coming in. Let me know if I can help with a PR or anything else.
Here is the issue. This specific instance happened during tool calls.
The FunctionExecutor calls Cleverclient's JsonUtil to deserialize JSON objects.
If the functional class contains types that are not registered by the vanilla object mapper / object reader in Cleverclient's JsonUtil we have a problem.
Since the ObjectReader is generated from a vanilla ObjectMapper that doesn't register the
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
it can't handle dates. That's fine. Cleverclient shouldn't register any possible module. But, it should be possible to pass an external ObjectMapper/ObjectReader to all the methods in JsonUtil.I opened an issue for Cleverclient: https://github.com/sashirestela/cleverclient/issues/77
Once, it is possible to provide a custom object mapper/object reader to JsonUtil, then, the FunctionExecutor should be able to pass a custom ObjectReader to Cleverclient's
JsonUtil.jsonToObject()
methodProbably overload the
execute()
andexecuteAll()
methods like so: