Started work on API and remembrance fuction

This commit is contained in:
2025-02-21 13:31:13 +01:00
parent 9daae9211f
commit da2cb69b1b
11 changed files with 331 additions and 42 deletions

View File

@@ -6,11 +6,9 @@ import com.github.dockerjava.api.command.LogContainerCmd;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientBuilder;
import me.zacharias.chat.ollama.OllamaFunctionArgument;
import me.zacharias.chat.ollama.OllamaFuntionTool;
import me.zacharias.chat.ollama.OllamaPerameter;
import me.zacharias.chat.ollama.OllamaToolRespnce;
import me.zacharias.chat.ollama.*;
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
import org.apache.http.conn.HttpHostConnectException;
import java.io.*;
import java.nio.charset.StandardCharsets;
@@ -105,38 +103,43 @@ public class PythonRunner extends OllamaFuntionTool {
}catch(IOException e) {}
}
String containerId = dockerClient.createContainerCmd("python").withCmd("python", name).exec().getId();
dockerClient.copyArchiveToContainerCmd(containerId)
.withHostResource(pythonFile.getPath())
//.withRemotePath("~/")
.exec();
dockerClient.startContainerCmd(containerId).exec();
try {
String containerId = dockerClient.createContainerCmd("python").withCmd("python", name).exec().getId();
dockerClient.copyArchiveToContainerCmd(containerId)
.withHostResource(pythonFile.getPath())
//.withRemotePath("~/")
.exec();
GetContainerLog log = new GetContainerLog(dockerClient, containerId);
dockerClient.startContainerCmd(containerId).exec();
List<String> logs = new ArrayList<>();
GetContainerLog log = new GetContainerLog(dockerClient, containerId);
do {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
List<String> logs = new ArrayList<>();
do {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
logs.addAll(log.getDockerLogs());
}
logs.addAll(log.getDockerLogs());
while (logs.isEmpty());
StringBuilder output = new StringBuilder();
for (String s : logs) {
output.append(s).append("\n");
}
//writeLog("Result from python: " + output.toString());
return new OllamaToolRespnce(name(), output.toString());
}
while (logs.isEmpty());
StringBuilder output = new StringBuilder();
for(String s : logs)
{
output.append(s).append("\n");
catch (Exception e) {
throw new OllamaToolErrorException(name(), "Docker unavalible");
}
//writeLog("Result from python: " + output.toString());
return new OllamaToolRespnce(name(), output.toString());
}
public class GetContainerLog {