forked from Chat_things/NeuroDock
Honestly speaking... No clue what the updates are :/
This commit is contained in:
@@ -8,19 +8,23 @@ import com.github.dockerjava.api.model.BuildResponseItem;
|
||||
import com.github.dockerjava.api.model.Frame;
|
||||
import com.github.dockerjava.api.model.Statistics;
|
||||
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
||||
import com.github.dockerjava.core.DockerClientBuilder;
|
||||
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient;
|
||||
import com.github.dockerjava.transport.DockerHttpClient;
|
||||
import me.zacharias.chat.core.Core;
|
||||
import me.zacharias.chat.core.Pair;
|
||||
import me.zacharias.chat.ollama.*;
|
||||
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -112,13 +116,48 @@ public class PythonRunner extends OllamaFunctionTool {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DefaultDockerClientConfig.Builder config
|
||||
DefaultDockerClientConfig config
|
||||
= DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||
.withDockerHost("tcp://localhost:2375")
|
||||
.withDockerTlsVerify(false);
|
||||
dockerClient = DockerClientBuilder
|
||||
.getInstance(config)
|
||||
.withDockerTlsVerify(false)
|
||||
.withDockerCertPath("~/.docker")
|
||||
.build();
|
||||
DockerHttpClient dockerHttpClient = new ApacheDockerHttpClient.Builder()
|
||||
.dockerHost(config.getDockerHost())
|
||||
.maxConnections(10)
|
||||
.connectionTimeout(Duration.ofSeconds(100))
|
||||
.responseTimeout(Duration.ofSeconds(100))
|
||||
.sslConfig(config.getSSLConfig())
|
||||
.build();
|
||||
|
||||
DockerHttpClient.Request ping = DockerHttpClient.Request.builder()
|
||||
.method(DockerHttpClient.Request.Method.GET)
|
||||
.path("/_ping")
|
||||
.build();
|
||||
|
||||
try(DockerHttpClient.Response response = dockerHttpClient.execute(ping))
|
||||
{
|
||||
if(!(response.getStatusCode() == 200))
|
||||
{
|
||||
writeLog("Failed to ping docker");
|
||||
System.out.println("Failed to ping docker. Docker components is disabled.");
|
||||
dockerClient = null;
|
||||
return;
|
||||
}
|
||||
if(!(IOUtils.toString(response.getBody(), Charset.defaultCharset()).equals("OK")))
|
||||
{
|
||||
writeLog("Failed to ping docker");
|
||||
System.out.println("Failed to ping docker. Docker components is disabled.");
|
||||
dockerClient = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
writeLog("Failed to ping docker");
|
||||
System.out.println("Failed to ping docker. Docker components is disabled.");
|
||||
dockerClient = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +181,10 @@ public class PythonRunner extends OllamaFunctionTool {
|
||||
|
||||
@Override
|
||||
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
|
||||
if(dockerClient == null)
|
||||
{
|
||||
return new OllamaToolRespnce(name(), "Docker is disabled");
|
||||
}
|
||||
if(args.length == 0)
|
||||
{
|
||||
throw new OllamaToolErrorException(name(), "Missing code argument");
|
||||
|
||||
Reference in New Issue
Block a user