From 43ca4c914b580c0aecb9b9bad19bdddb7d44ac87 Mon Sep 17 00:00:00 2001 From: Fu Cheng Date: Wed, 15 May 2024 20:47:59 +0800 Subject: [PATCH] add Java code executor config --- .../JavaCodeExecutionConfig.java | 28 ++++++++++++++++++- .../JavaCodeExecutionTool.kt | 12 ++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/java/src/main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionConfig.java b/java/src/main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionConfig.java index 0f09bcd..f2e7eb2 100644 --- a/java/src/main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionConfig.java +++ b/java/src/main/java/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionConfig.java @@ -2,5 +2,31 @@ public class JavaCodeExecutionConfig { - + private String executable = "java"; + + private String workingDirectory; + + public String getExecutable() { + return executable; + } + + public void setExecutable(String executable) { + this.executable = executable; + } + + public String getWorkingDirectory() { + return workingDirectory; + } + + public void setWorkingDirectory(String workingDirectory) { + this.workingDirectory = workingDirectory; + } + + @Override + public String toString() { + return "JavaCodeExecutionConfig{" + + "executable='" + executable + '\'' + + ", workingDirectory='" + workingDirectory + '\'' + + '}'; + } } diff --git a/java/src/main/kotlin/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionTool.kt b/java/src/main/kotlin/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionTool.kt index 83da8ff..c576e69 100644 --- a/java/src/main/kotlin/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionTool.kt +++ b/java/src/main/kotlin/io/github/llmagentbuilder/tool/javacodeexecution/JavaCodeExecutionTool.kt @@ -7,13 +7,14 @@ import org.slf4j.LoggerFactory const val toolName = "executeJavaCode" -object JavaCodeExecutor : NonSandboxedCodeExecutor() { +class JavaCodeExecutor(private val config: JavaCodeExecutionConfig) : + NonSandboxedCodeExecutor() { override fun executable(): String { - return "java" + return config.executable } override fun workingDirectory(): String? { - return null + return config.workingDirectory } override fun args(input: String): List { @@ -25,10 +26,11 @@ object JavaCodeExecutor : NonSandboxedCodeExecutor() { /** * Tool to execute Java code */ -class JavaCodeExecutionTool(private val config: JavaCodeExecutionConfig) : +class JavaCodeExecutionTool(config: JavaCodeExecutionConfig) : ConfigurableAgentTool { private val logger = LoggerFactory.getLogger(javaClass) + private val codeExecutor = JavaCodeExecutor(config) init { logger.info("Created with config: $config") @@ -36,7 +38,7 @@ class JavaCodeExecutionTool(private val config: JavaCodeExecutionConfig) : override fun apply(request: JavaCodeExecutionRequest): JavaCodeExecutionResponse { return JavaCodeExecutionResponse( - JavaCodeExecutor.execute(request.code) + codeExecutor.execute(request.code) ) }