refactor(Core): decompose handleResponse and add ToolCallingRender system
build / build (push) Has been cancelled
build / build (push) Has been cancelled
- Extract handleResponse into focused helpers: processToolCall, findTool, reportToolNotFound, renderToolCalling, executeToolCall - Introduce ToolCallingRender sealed interface (Suppress/Default/Custom) allowing tools to control how their invocations are rendered - Add printToolCalling to PrintAdvanceMessageHandler contract - Implement default tool calling rendering in PrintMessageHandler (blue text) - Add WriteFileTool for file writing capabilities - Fix "responce" → "response" typo across Java and Python files - Improve PythonRunner docker error handling and output messages - Update Gradle test configuration (maxHeapSize, test logging) Signed-off-by: zacharias <alienfromdia@proton.me>
This commit is contained in:
@@ -5,11 +5,8 @@ import me.neurodock.core.Pair;
|
||||
import me.neurodock.core.PrintMessageHandler;
|
||||
import me.neurodock.core.files.FileHandlerLocation;
|
||||
import me.neurodock.core.memory.CoreMemory;
|
||||
import me.neurodock.mal.api.MALAPITool;
|
||||
import me.neurodock.ollama.*;
|
||||
import me.neurodock.ollama.utils.SystemMessage;
|
||||
import me.neurodock.genius.GeniusTools;
|
||||
import me.neurodock.wikipedia.WikipediaTool;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
@@ -172,7 +169,7 @@ public class Display {
|
||||
writeLog("User: " + message);
|
||||
core.getOllamaObject().addMessage(new OllamaMessage(OllamaMessageRole.USER, message.toString()));
|
||||
//System.out.println(ollamaObject.toString());
|
||||
core.handleResponce(core.qurryOllama());
|
||||
core.handleResponse(core.qurryOllama());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jspecify.annotations.NonNull;
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
@@ -194,11 +195,27 @@ public class PythonRunner extends OllamaFunctionTool {
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException re)
|
||||
{
|
||||
if(re.getCause() instanceof SocketException) {
|
||||
writeLog("Failed to ping docker: " + re.getMessage());
|
||||
System.out.println("Failed to ping docker. Docker component is disabled.");
|
||||
dockerClient = null;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
writeLog("Failed to ping docker: " + re.getMessage());
|
||||
re.printStackTrace();
|
||||
System.out.println("Failed to ping docker. Docker component is disabled.");
|
||||
dockerClient = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
writeLog("Failed to ping docker: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
System.out.println("Failed to ping docker. Docker components is disabled.");
|
||||
System.out.println("Failed to ping docker. Docker component is disabled.");
|
||||
dockerClient = null;
|
||||
return;
|
||||
}
|
||||
@@ -445,7 +462,7 @@ public class PythonRunner extends OllamaFunctionTool {
|
||||
|
||||
dockerClient.removeContainerCmd(containerId).exec();
|
||||
|
||||
return new OllamaToolResponse(name(), output.isEmpty() ? "Code ran successfully with no output" : output);
|
||||
return new OllamaToolResponse(name(), output.isEmpty() ? "Python script names "+name+" ran successfully with no output" : "Python script names "+name+" output: "+output);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new OllamaToolErrorException(name(), "Docker unavailable");
|
||||
|
||||
@@ -10,8 +10,8 @@ def connect(data):
|
||||
s.connect((HOST, PORT))
|
||||
data = data + "\n"
|
||||
s.sendall(data.encode("utf-8"))
|
||||
responce = s.recv(4096)
|
||||
return responce.decode("utf-8")
|
||||
response = s.recv(4096)
|
||||
return response.decode("utf-8")
|
||||
|
||||
def print_output(text):
|
||||
data = {"function": "print_output", "container_id": CONTAINER_ID, "text": text}
|
||||
|
||||
Reference in New Issue
Block a user