forked from neurodock/NeuroDock
refactor: me.zacharias.chat → me.neurodock, org rename cleanup
- Renamed package from me.zacharias.chat to me.neurodock across all 8 modules - Updated Gradle group from me.zacharias.neurodock to me.neurodock - Updated README and other files to reflect new Gitea org URL (Chat_things → neurodock) Dev note: 95 files touched. The Great Refactor is complete, long may it rest.
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
package me.neurodock.display;
|
||||
|
||||
import me.neurodock.core.Core;
|
||||
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.zacharias.chat.ollama.*;
|
||||
import me.neurodock.ollama.utils.SystemMessage;
|
||||
import me.neurodock.genius.GeniusTools;
|
||||
import me.neurodock.wikipedia.WikipediaTool;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static me.neurodock.core.Core.writeLog;
|
||||
|
||||
/**
|
||||
* The main class of the Display.<br>
|
||||
* This is the main class for running as a Terminal application.<br>
|
||||
* Somewhat meant to be used as a Debug tool for testing your API.
|
||||
*/
|
||||
public class Display {
|
||||
|
||||
/**
|
||||
* The Core instance.
|
||||
*/
|
||||
Core core = new Core(new PrintMessageHandler() {
|
||||
@Override
|
||||
public void printMessage(String message) {
|
||||
System.out.println(">> "+message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean color() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a new instance of Display.<br>
|
||||
* This Creates the OllamaObject and adds the tools to it. as well as handles the display of the messages. and the input from the user.
|
||||
*/
|
||||
public Display()
|
||||
{
|
||||
|
||||
core.setOllamaObject/*NoMemory*/(OllamaObject.builder()
|
||||
.setModel("llama3.1:8b")
|
||||
.keep_alive(10)
|
||||
//.stream(false)
|
||||
.addFileTools(FileHandlerLocation.DATA_FILES)
|
||||
.addMessages(new SystemMessage("You need to emulate feelings and emotions."))
|
||||
.build());
|
||||
|
||||
core.enablePlugins(Core.PLUGIN_DIRECTORY);
|
||||
|
||||
core.addTool(new TimeTool(), Core.Source.INTERNAL);
|
||||
// TODO: Well Docker failes when luanched.... Fuck
|
||||
core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
|
||||
core.addTools(new MALAPITool().getOllamaTools());
|
||||
core.addTools(new GeniusTools().getGeniusTools());
|
||||
core.addTools(new WikipediaTool().getWikipediaToolsInstance());
|
||||
|
||||
//APIApplication.start();
|
||||
|
||||
//core.getOllamaObject().addMessage(new OllamaMessage(OllamaMessageRole.SYSTEM, "Have a nice tone and use formal wording"));
|
||||
|
||||
writeLog("Creating base OllamaObject with model: "+core.getOllamaObject().getModel());
|
||||
|
||||
System.out.println("Installed tools");
|
||||
writeLog("Tools installed in this instance");
|
||||
|
||||
for(Pair<OllamaFunctionTool, String> funtion : core.getFuntionTools())
|
||||
{
|
||||
StringBuilder args = new StringBuilder();
|
||||
OllamaPerameter perameter = funtion.getKey().parameters();
|
||||
if(perameter != null) {
|
||||
JSONObject obj = perameter.getProperties();
|
||||
for (String name : obj.keySet()) {
|
||||
args.append(args.toString().isBlank() ? "" : ", ").append(obj.getJSONObject(name).getString("type")).append(Arrays.stream(perameter.getRequired()).anyMatch(str -> str.equalsIgnoreCase(name)) ? "" : "?").append(" ").append(name);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("> Function: "+funtion.getKey().name()+"("+args+") ["+funtion.getValue()+"]");
|
||||
writeLog("Function: "+funtion.getKey().name()+"("+args+") ["+funtion.getValue()+"]");
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
System.out.println("Message Transcription:");
|
||||
try {
|
||||
while (true) {
|
||||
System.out.print("> ");
|
||||
StringBuilder message = new StringBuilder(br.readLine());
|
||||
while (br.ready()) {
|
||||
message.append("\n").append(br.readLine());
|
||||
}
|
||||
if (message.toString().startsWith("/")) {
|
||||
switch (message.substring(1)) {
|
||||
case "help":
|
||||
System.out.print("""
|
||||
Available commands:
|
||||
/help Prints this help message.
|
||||
/bye Exits the program.
|
||||
/write Flushes the current log stream to file.
|
||||
/list Lists all available tools.
|
||||
/corelist Lists all tools according to the OllamaObject.
|
||||
/working Prints the current working directories.
|
||||
/peek Peeks the current memory.
|
||||
""");
|
||||
break;
|
||||
case "bye":
|
||||
writeLog("Exiting program...");
|
||||
System.out.println("Bye!");
|
||||
System.exit(0);
|
||||
return;
|
||||
case "write":
|
||||
Core.flushLog();
|
||||
break;
|
||||
case "peek":
|
||||
CoreMemory coreMemory = CoreMemory.getInstance();
|
||||
StringBuilder buffer = new StringBuilder("[");
|
||||
ArrayList<String> memory = new ArrayList<>(coreMemory.getMemoriesArray());
|
||||
for(int i = 0; i < memory.size(); i++) {
|
||||
String mem = memory.get(i);
|
||||
buffer.append("\"").append(mem).append("\"");
|
||||
if(i+1 < memory.size()) {
|
||||
buffer.append(", ");
|
||||
}
|
||||
}
|
||||
buffer.append("]");
|
||||
writeLog("Memory peek: "+buffer.toString());
|
||||
System.out.println(buffer.toString());
|
||||
break;
|
||||
case "list":
|
||||
writeLog("Tools installed in this instance");
|
||||
|
||||
for(Pair<OllamaFunctionTool, String> funtion : core.getFuntionTools()) {
|
||||
StringBuilder args = new StringBuilder();
|
||||
OllamaPerameter perameter = funtion.getKey().parameters();
|
||||
if (perameter != null) {
|
||||
JSONObject obj = perameter.getProperties();
|
||||
for (String name : obj.keySet()) {
|
||||
args.append(args.toString().isBlank() ? "" : ", ").append(obj.getJSONObject(name).getString("type")).append(Arrays.stream(perameter.getRequired()).anyMatch(str -> str.equalsIgnoreCase(name)) ? "" : "?").append(" ").append(name);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("> Function: " + funtion.getKey().name() + "(" + args + ") [" + funtion.getValue() + "]");
|
||||
writeLog("Function: " + funtion.getKey().name() + "(" + args + ") [" + funtion.getValue() + "]");
|
||||
}
|
||||
break;
|
||||
case "corelist":
|
||||
writeLog("Tools installed in this instance acording to the coire OllamaObject");
|
||||
|
||||
for(Pair<OllamaTool, String> funtion : core.getOllamaObject().getTools()) {
|
||||
System.out.println("> Function: " + funtion.getKey().toString());
|
||||
writeLog("Function: " + funtion.getKey().toString());
|
||||
}
|
||||
break;
|
||||
case "working":
|
||||
System.out.println("Working directories:\n" +
|
||||
" Data: " + Core.DATA_DIR.getAbsolutePath() + "\n" +
|
||||
" DateFiles: " + FileHandlerLocation.DATA_FILES + "\n" +
|
||||
" Plugins: " + Core.PLUGIN_DIRECTORY.getAbsolutePath());
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unknown command: " + message);
|
||||
}
|
||||
} else {
|
||||
writeLog("User: " + message);
|
||||
core.getOllamaObject().addMessage(new OllamaMessage(OllamaMessageRole.USER, message.toString()));
|
||||
//System.out.println(ollamaObject.toString());
|
||||
core.handleResponce(core.qurryOllama());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Exiting due to exception");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user