Extracted the external tool base for python runner
build / build (push) Has been cancelled

Fixed URL building in APITool.java.
Updated libraries for API, Launcher.
Started applying NotNull annotation to methods and arguments in Core.java.
Started handeling the big init block in Core.java.
Added overloaded constructor for Core.java and made Core.ollamaIP a variabled that's definible
Updated Tool.addTool return for 400 error.
This commit is contained in:
2026-05-04 14:23:26 +02:00
parent 943c8470a5
commit 96a6ed169e
9 changed files with 83 additions and 48 deletions
@@ -59,6 +59,8 @@ public class PythonRunner extends OllamaFunctionTool {
public PythonRunner(Core core) {
this.core = core;
generateExternalTools();
try {
serverSocket = new ServerSocket(6050);
Thread thread = new Thread(() -> {
@@ -350,27 +352,22 @@ public class PythonRunner extends OllamaFunctionTool {
* Generates the external_tools.py file.<br>
* This is meant to provide the python code with all ExternalTools defined in the OllamaObject.
* @return The generated external_tools.py file
* @throws IllegalStateException This is thrown when the external_tool_base.py can not be read, this should be handled by disabling the python runner.
*/
private String generateExternalTools() {
private String generateExternalTools() throws IllegalStateException{
StringBuilder code = new StringBuilder();
code.append("""
import socket
import json
HOST = "host.docker.internal"
PORT = 6050
def connect(data):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
data = data + "\\n"
s.sendall(data.encode("utf-8"))
responce = s.recv(4096)
return responce.decode("utf-8")
""");
try (InputStream in = getClass().getResourceAsStream("/external_tool_base.py");
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
String tmp = null;
while((tmp = reader.readLine()) != null)
{
code.append(tmp).append('\n');
}
}catch (Exception ex)
{
throw new IllegalStateException("Can not read the base external tools file, this is a fetal error for the python runner!");
}
for(Pair<OllamaFunctionTool, String> funtionTool : core.getFuntionTools())
{