Basicly refactord the entire project into a modular nature
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
package me.zacharias.chat.display;
|
||||
|
||||
import me.zacharias.chat.core.Core;
|
||||
import me.zacharias.chat.core.PrintMessageHandler;
|
||||
import me.zacharias.chat.ollama.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static me.zacharias.chat.core.Core.writeLog;
|
||||
|
||||
public class Display {
|
||||
|
||||
Core core = new Core(new PrintMessageHandler() {
|
||||
@Override
|
||||
public void printMessage(String message) {
|
||||
System.out.println(">> "+message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean color() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
public Display()
|
||||
{
|
||||
|
||||
core.setOllamaObject(OllamaObject.builder()
|
||||
.setModel("llama3-AI")
|
||||
.keep_alive(10)
|
||||
.addTool(new TimeTool())
|
||||
.addTool(new PythonRunner())
|
||||
.stream(false)
|
||||
.build());
|
||||
|
||||
writeLog("Creating base OllamaObject with model: "+core.getOllamaObject().getModel());
|
||||
|
||||
System.out.println("Installed tools");
|
||||
writeLog("Tools installed in this instance");
|
||||
|
||||
for(OllamaTool tool : core.getOllamaObject().getTools())
|
||||
{
|
||||
if(tool instanceof OllamaFuntionTool funtion)
|
||||
{
|
||||
StringBuilder args = new StringBuilder();
|
||||
OllamaPerameter perameter = funtion.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.name()+"("+args+")");
|
||||
writeLog("Function: "+funtion.name()+"("+args+")");
|
||||
core.addFuntionTool(funtion);
|
||||
}
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
System.out.println("Message Trsnscription:");
|
||||
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.
|
||||
""");
|
||||
break;
|
||||
case "bye":
|
||||
writeLog("Exiting program...");
|
||||
System.out.println("Bye!");
|
||||
System.exit(0);
|
||||
return;
|
||||
case "write":
|
||||
core.flushLog();
|
||||
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