Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
add Java code executor config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed May 15, 2024
1 parent 12d23ba commit 43ca4c9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand All @@ -25,18 +26,19 @@ object JavaCodeExecutor : NonSandboxedCodeExecutor() {
/**
* Tool to execute Java code
*/
class JavaCodeExecutionTool(private val config: JavaCodeExecutionConfig) :
class JavaCodeExecutionTool(config: JavaCodeExecutionConfig) :
ConfigurableAgentTool<JavaCodeExecutionRequest, JavaCodeExecutionResponse, JavaCodeExecutionConfig> {

private val logger = LoggerFactory.getLogger(javaClass)
private val codeExecutor = JavaCodeExecutor(config)

init {
logger.info("Created with config: $config")
}

override fun apply(request: JavaCodeExecutionRequest): JavaCodeExecutionResponse {
return JavaCodeExecutionResponse(
JavaCodeExecutor.execute(request.code)
codeExecutor.execute(request.code)
)
}

Expand Down

0 comments on commit 43ca4c9

Please sign in to comment.