gnodet-bot commented on code in PR #27976:
URL: https://github.com/apache/camel/pull/27976#discussion_r4299477023
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/LlmClient.java:
##########
@@ -1711,11 +1734,17 @@ private ChatResponse parseOpenAiChatResponse(JsonObject
response) {
JsonObject function = (JsonObject) tc.get("function");
String id = tc.getString("id");
String name = function.getString("name");
+ // the arguments are JSON text, or an object with some
OpenAI-compatible servers (as with Ollama)
JsonObject args;
- try {
- args = (JsonObject)
Jsoner.deserialize(function.getString("arguments"));
- } catch (Exception e) {
- args = new JsonObject();
+ Object argsObj = function.get("arguments");
+ if (argsObj instanceof JsonObject jo) {
+ args = jo;
+ } else {
+ try {
+ args = (JsonObject) Jsoner.deserialize((String)
argsObj);
+ } catch (Exception e) {
+ args = new JsonObject();
+ }
}
Review Comment:
💡 **Nit:** The `else` branch casts `argsObj` directly to `String`, relying
on the `catch (Exception e)` to handle `null` or non-`String` types. The Ollama
paths in the same file use a three-branch `instanceof` pattern that handles
this explicitly and avoids exception-as-control-flow. Worth aligning for
consistency:
```suggestion
Object argsObj = function.get("arguments");
if (argsObj instanceof JsonObject jo) {
args = jo;
} else if (argsObj instanceof String s) {
try {
args = (JsonObject) Jsoner.deserialize(s);
} catch (Exception e) {
args = new JsonObject();
}
} else {
args = new JsonObject();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]