From da210a28bb59800785a9a151bb7f0239ac347cce Mon Sep 17 00:00:00 2001 From: MoheyElDin Badr Date: Thu, 23 May 2024 02:38:43 +0300 Subject: [PATCH 1/3] change the success message as some opensource models like empower-functions-medium (can be tested with baseUrl: https://app.empower.dev/api/v1/functions/) accepts Tool Message as Json only --- .../io/quarkiverse/langchain4j/deployment/ToolProcessor.java | 2 +- .../langchain4j/runtime/tool/QuarkusToolExecutor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java index a3405eb93..6e9d3d2b9 100644 --- a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java +++ b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java @@ -292,7 +292,7 @@ private static String generateInvoker(MethodInfo methodInfo, ClassOutput classOu boolean toolReturnsVoid = methodInfo.returnType().kind() == Type.Kind.VOID; if (toolReturnsVoid) { - invokeMc.returnValue(invokeMc.load("Success")); + invokeMc.returnValue(invokeMc.load("\\\"Success\\\"")); } else { invokeMc.returnValue(result); } diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java index 126ea21a5..bfb772f39 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java @@ -61,7 +61,7 @@ public String execute(ToolExecutionRequest toolExecutionRequest, Object memoryId private static String handleResult(ToolInvoker invokerInstance, Object invocationResult) { if (invokerInstance.methodMetadata().isReturnsVoid()) { - return "Success"; + return "\\\"Success\\\""; } return Json.toJson(invocationResult); } From 72354c24c7e9343d6b5b7681cc7f63cb6e16621e Mon Sep 17 00:00:00 2001 From: MoheyEl-DinBadr <56153924+MoheyEl-DinBadr@users.noreply.github.com> Date: Sat, 25 May 2024 17:56:31 +0300 Subject: [PATCH 2/3] Update ToolProcessor.java Fix the success message --- .../io/quarkiverse/langchain4j/deployment/ToolProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java index 6e9d3d2b9..47220e7a6 100644 --- a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java +++ b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java @@ -292,7 +292,7 @@ private static String generateInvoker(MethodInfo methodInfo, ClassOutput classOu boolean toolReturnsVoid = methodInfo.returnType().kind() == Type.Kind.VOID; if (toolReturnsVoid) { - invokeMc.returnValue(invokeMc.load("\\\"Success\\\"")); + invokeMc.returnValue(invokeMc.load("\"Success\"")); } else { invokeMc.returnValue(result); } From 4a5aad98b9fdcf135006ae636ead4582f522af8c Mon Sep 17 00:00:00 2001 From: MoheyEl-DinBadr <56153924+MoheyEl-DinBadr@users.noreply.github.com> Date: Sat, 25 May 2024 17:57:26 +0300 Subject: [PATCH 3/3] Update QuarkusToolExecutor.java --- .../langchain4j/runtime/tool/QuarkusToolExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java index bfb772f39..d8cb88c36 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/tool/QuarkusToolExecutor.java @@ -61,7 +61,7 @@ public String execute(ToolExecutionRequest toolExecutionRequest, Object memoryId private static String handleResult(ToolInvoker invokerInstance, Object invocationResult) { if (invokerInstance.methodMetadata().isReturnsVoid()) { - return "\\\"Success\\\""; + return "\"Success\""; } return Json.toJson(invocationResult); }