forked from Chat_things/NeuroDock
Honestly speaking... No clue what the updates are :/
This commit is contained in:
3
.idea/gradle.xml
generated
3
.idea/gradle.xml
generated
@@ -12,8 +12,9 @@
|
|||||||
<option value="$PROJECT_DIR$/API" />
|
<option value="$PROJECT_DIR$/API" />
|
||||||
<option value="$PROJECT_DIR$/Core" />
|
<option value="$PROJECT_DIR$/Core" />
|
||||||
<option value="$PROJECT_DIR$/Display" />
|
<option value="$PROJECT_DIR$/Display" />
|
||||||
|
<option value="$PROJECT_DIR$/GeniusAPI" />
|
||||||
<option value="$PROJECT_DIR$/MALAPITool" />
|
<option value="$PROJECT_DIR$/MALAPITool" />
|
||||||
<option value="$PROJECT_DIR$/Plugin" />
|
<option value="$PROJECT_DIR$/WikipediaTool" />
|
||||||
<option value="$PROJECT_DIR$/launcher" />
|
<option value="$PROJECT_DIR$/launcher" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-webflux'
|
implementation 'org.springframework.boot:spring-boot-starter-webflux'
|
||||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
|
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.0-M1'
|
||||||
//implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
//implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ dependencies {
|
|||||||
implementation project(":GeniusAPI")
|
implementation project(":GeniusAPI")
|
||||||
implementation project(":API")
|
implementation project(":API")
|
||||||
implementation project(":WikipediaTool")
|
implementation project(":WikipediaTool")
|
||||||
|
|
||||||
|
implementation("com.github.docker-java:docker-java-core:3.6.0")
|
||||||
|
implementation("com.github.docker-java:docker-java-transport-httpclient5:3.6.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class Display {
|
|||||||
|
|
||||||
core.addTool(new TimeTool(), Core.Source.INTERNAL);
|
core.addTool(new TimeTool(), Core.Source.INTERNAL);
|
||||||
// TODO: Well Docker failes when luanched.... Fuck
|
// TODO: Well Docker failes when luanched.... Fuck
|
||||||
// core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
|
//core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
|
||||||
core.addTools(new MALAPITool().getOllamaTools());
|
core.addTools(new MALAPITool().getOllamaTools());
|
||||||
core.addTools(new GeniusTools().getGeniusTools());
|
core.addTools(new GeniusTools().getGeniusTools());
|
||||||
core.addTools(new WikipediaTool().getWikipediaToolsInstance());
|
core.addTools(new WikipediaTool().getWikipediaToolsInstance());
|
||||||
|
|||||||
@@ -8,19 +8,23 @@ import com.github.dockerjava.api.model.BuildResponseItem;
|
|||||||
import com.github.dockerjava.api.model.Frame;
|
import com.github.dockerjava.api.model.Frame;
|
||||||
import com.github.dockerjava.api.model.Statistics;
|
import com.github.dockerjava.api.model.Statistics;
|
||||||
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
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.Core;
|
||||||
import me.zacharias.chat.core.Pair;
|
import me.zacharias.chat.core.Pair;
|
||||||
import me.zacharias.chat.ollama.*;
|
import me.zacharias.chat.ollama.*;
|
||||||
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -112,13 +116,48 @@ public class PythonRunner extends OllamaFunctionTool {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultDockerClientConfig.Builder config
|
DefaultDockerClientConfig config
|
||||||
= DefaultDockerClientConfig.createDefaultConfigBuilder()
|
= DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||||
.withDockerHost("tcp://localhost:2375")
|
.withDockerHost("tcp://localhost:2375")
|
||||||
.withDockerTlsVerify(false);
|
.withDockerTlsVerify(false)
|
||||||
dockerClient = DockerClientBuilder
|
.withDockerCertPath("~/.docker")
|
||||||
.getInstance(config)
|
|
||||||
.build();
|
.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
|
@Override
|
||||||
@@ -142,6 +181,10 @@ public class PythonRunner extends OllamaFunctionTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
|
public OllamaToolRespnce function(OllamaFunctionArgument... args) {
|
||||||
|
if(dockerClient == null)
|
||||||
|
{
|
||||||
|
return new OllamaToolRespnce(name(), "Docker is disabled");
|
||||||
|
}
|
||||||
if(args.length == 0)
|
if(args.length == 0)
|
||||||
{
|
{
|
||||||
throw new OllamaToolErrorException(name(), "Missing code argument");
|
throw new OllamaToolErrorException(name(), "Missing code argument");
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.hc.client5.http.ssl;
|
||||||
|
|
||||||
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLEngine;
|
||||||
|
import javax.net.ssl.SSLParameters;
|
||||||
|
|
||||||
|
import org.apache.hc.core5.annotation.Contract;
|
||||||
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
|
import org.apache.hc.core5.function.Factory;
|
||||||
|
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
|
||||||
|
import org.apache.hc.core5.reactor.ssl.SSLBufferMode;
|
||||||
|
import org.apache.hc.core5.reactor.ssl.TlsDetails;
|
||||||
|
import org.apache.hc.core5.ssl.SSLContexts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TLS upgrade strategy for non-blocking client connections.
|
||||||
|
*
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||||
|
public class DefaultClientTlsStrategy extends AbstractClientTlsStrategy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public static DefaultClientTlsStrategy createDefault() {
|
||||||
|
return new DefaultClientTlsStrategy(
|
||||||
|
SSLContexts.createDefault(),
|
||||||
|
HostnameVerificationPolicy.BOTH,
|
||||||
|
HttpsSupport.getDefaultHostnameVerifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public static DefaultClientTlsStrategy createSystemDefault() {
|
||||||
|
return new DefaultClientTlsStrategy(
|
||||||
|
SSLContexts.createSystemDefault(),
|
||||||
|
HttpsSupport.getSystemProtocols(),
|
||||||
|
HttpsSupport.getSystemCipherSuits(),
|
||||||
|
SSLBufferMode.STATIC,
|
||||||
|
HostnameVerificationPolicy.BOTH,
|
||||||
|
HttpsSupport.getDefaultHostnameVerifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #createDefault()}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static TlsStrategy getDefault() {
|
||||||
|
return createDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #createSystemDefault()}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static TlsStrategy getSystemDefault() {
|
||||||
|
return createSystemDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated To be removed.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
private Factory<SSLEngine, TlsDetails> tlsDetailsFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link DefaultClientTlsStrategy#DefaultClientTlsStrategy(SSLContext, String[], String[], SSLBufferMode, HostnameVerifier)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public DefaultClientTlsStrategy(
|
||||||
|
final SSLContext sslContext,
|
||||||
|
final String[] supportedProtocols,
|
||||||
|
final String[] supportedCipherSuites,
|
||||||
|
final SSLBufferMode sslBufferManagement,
|
||||||
|
final HostnameVerifier hostnameVerifier,
|
||||||
|
final Factory<SSLEngine, TlsDetails> tlsDetailsFactory) {
|
||||||
|
super(sslContext, supportedProtocols, supportedCipherSuites, sslBufferManagement, HostnameVerificationPolicy.CLIENT, hostnameVerifier);
|
||||||
|
this.tlsDetailsFactory = tlsDetailsFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public DefaultClientTlsStrategy(
|
||||||
|
final SSLContext sslContext,
|
||||||
|
final String[] supportedProtocols,
|
||||||
|
final String[] supportedCipherSuites,
|
||||||
|
final SSLBufferMode sslBufferManagement,
|
||||||
|
final HostnameVerificationPolicy hostnameVerificationPolicy,
|
||||||
|
final HostnameVerifier hostnameVerifier) {
|
||||||
|
super(sslContext, supportedProtocols, supportedCipherSuites, sslBufferManagement, hostnameVerificationPolicy, hostnameVerifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultClientTlsStrategy(
|
||||||
|
final SSLContext sslContext,
|
||||||
|
final String[] supportedProtocols,
|
||||||
|
final String[] supportedCipherSuites,
|
||||||
|
final SSLBufferMode sslBufferManagement,
|
||||||
|
final HostnameVerifier hostnameVerifier) {
|
||||||
|
this(sslContext, supportedProtocols, supportedCipherSuites, sslBufferManagement, HostnameVerificationPolicy.CLIENT, hostnameVerifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultClientTlsStrategy(
|
||||||
|
final SSLContext sslContext,
|
||||||
|
final HostnameVerifier hostnameVerifier) {
|
||||||
|
this(sslContext, null, null, SSLBufferMode.STATIC, hostnameVerifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public DefaultClientTlsStrategy(
|
||||||
|
final SSLContext sslContext,
|
||||||
|
final HostnameVerificationPolicy hostnameVerificationPolicy,
|
||||||
|
final HostnameVerifier hostnameVerifier) {
|
||||||
|
this(sslContext, null, null, SSLBufferMode.STATIC, hostnameVerificationPolicy, hostnameVerifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultClientTlsStrategy(final SSLContext sslContext) {
|
||||||
|
this(sslContext, HttpsSupport.getDefaultHostnameVerifier());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void applyParameters(final SSLEngine sslEngine, final SSLParameters sslParameters, final String[] appProtocols) {
|
||||||
|
sslParameters.setApplicationProtocols(appProtocols);
|
||||||
|
sslEngine.setSSLParameters(sslParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecated")
|
||||||
|
TlsDetails createTlsDetails(final SSLEngine sslEngine) {
|
||||||
|
return tlsDetailsFactory != null ? tlsDetailsFactory.create(sslEngine) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.apache.hc.client5.http.ssl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hostname verification policy.
|
||||||
|
*
|
||||||
|
* @see javax.net.ssl.HostnameVerifier
|
||||||
|
* @see DefaultHostnameVerifier
|
||||||
|
*
|
||||||
|
* @since 5.4
|
||||||
|
*/
|
||||||
|
public enum HostnameVerificationPolicy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hostname verification is delegated to the JSSE provider, usually executed during the TLS handshake.
|
||||||
|
*/
|
||||||
|
BUILTIN,
|
||||||
|
/**
|
||||||
|
* Hostname verification is executed by HttpClient post TLS handshake.
|
||||||
|
*/
|
||||||
|
CLIENT,
|
||||||
|
/**
|
||||||
|
* Hostname verification is executed by the JSSE provider and by HttpClient post TLS handshake.
|
||||||
|
*/
|
||||||
|
BOTH
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.apache.hc.client5.http.ssl;
|
||||||
|
|
||||||
|
import org.apache.hc.core5.annotation.Contract;
|
||||||
|
import org.apache.hc.core5.annotation.ThreadingBehavior;
|
||||||
|
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLSocket;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
|
||||||
|
@Contract(threading = ThreadingBehavior.STATELESS)
|
||||||
|
public interface TlsSocketStrategy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrades the given plain socket and executes the TLS handshake over it.
|
||||||
|
*
|
||||||
|
* @param socket the existing plain socket
|
||||||
|
* @param target the name of the target host.
|
||||||
|
* @param port the port to connect to on the target host.
|
||||||
|
* @param context the actual HTTP context.
|
||||||
|
* @param attachment connect request attachment.
|
||||||
|
* @return socket upgraded to TLS.
|
||||||
|
*/
|
||||||
|
SSLSocket upgrade(
|
||||||
|
Socket socket,
|
||||||
|
String target,
|
||||||
|
int port,
|
||||||
|
Object attachment,
|
||||||
|
HttpContext context) throws IOException;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package me.zacharias.neuro.dock.genius;
|
package me.zacharias.neuro.dock.genius;
|
||||||
|
|
||||||
import com.google.common.reflect.ClassPath;
|
|
||||||
import io.github.classgraph.ClassGraph;
|
import io.github.classgraph.ClassGraph;
|
||||||
import io.github.classgraph.ClassInfo;
|
import io.github.classgraph.ClassInfo;
|
||||||
import io.github.classgraph.ClassInfoList;
|
import io.github.classgraph.ClassInfoList;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ subprojects {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.json:json:20250107")
|
implementation("org.json:json:20250107")
|
||||||
implementation("com.github.docker-java:docker-java:3.4.1")
|
|
||||||
implementation("org.jetbrains:annotations:23.1.0")
|
implementation("org.jetbrains:annotations:23.1.0")
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class Launcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "--api" -> {
|
case "--api" -> {
|
||||||
System.out.println("API available at https://server.4zellen.se:3000/Zacharias/chat_thing/wiki/API-Docs");
|
System.out.println("API available at https://git.server.4zellen.se/Zacharias/chat_thing/wiki/API-Docs");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case "--help", "-h" -> {
|
case "--help", "-h" -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user