Well lot's in this

Some API modifications/additions

Starting the implementation of a local file system for the AI to use

Staring to try to migrate the ./cache, ./logs, ./messages, and ./pythonFiles to more appropiet locations depenidng on OS
This commit is contained in:
2025-03-25 23:25:29 +01:00
parent 01de196d82
commit 9b3c6c20b8
20 changed files with 568 additions and 174 deletions

View File

@@ -67,6 +67,39 @@ public class Core {
*/
private boolean supportColor;
public static final String DATA;
public static final File DATA_DIR;
static {
String data;
if(System.getenv("AI-CHAT-DEBUG") != null) {
data = "./data";
}
else if(System.getProperty("os.name").toLowerCase().contains("windows")) {
String localappdata = System.getenv("LOCALAPPDATA");
if(localappdata == null) {
localappdata = System.getenv("APPDATA");
}
data = localappdata + "/AI-CHAT";
}
else if (System.getProperty("os.name").toLowerCase().contains("linux")) {
data = System.getenv("HOME") + "/.local/share/AI-CHAT";
}
else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
data = System.getProperty("user.home") + "/Library/Application Support/AI-CHAT";
}
else {
data = "./data";
}
DATA = data;
DATA_DIR = new File(DATA);
if(!DATA_DIR.exists()) {
DATA_DIR.mkdirs();
}
}
{
File dir = new File("./logs/");
if (!dir.exists()) {

View File

@@ -18,8 +18,10 @@ public class LaunchOptions {
private boolean loadOld = true;
private boolean autoAccept;
private boolean serverMode;
private boolean serverCredentialsEnabled;
private int port = 39075;
private String redirectOutput;
private String serverCredentials;
/**
* Sets the singleton instance of the LaunchOptions class.
@@ -109,4 +111,36 @@ public class LaunchOptions {
public void setServerMode(boolean serverMode) {
this.serverMode = serverMode;
}
/**
* Gets weather or not the API Server requires credentials
* @return if credentials is required
*/
public boolean isServerCredentialsEnabled() {
return serverCredentialsEnabled;
}
/**
* Sets weather credentials are needed for the API Server
* @param serverCredentialsEnabled a boolean indicating if the APIServer needs credentials from clients
*/
public void setServerCredentialsEnabled(boolean serverCredentialsEnabled) {
this.serverCredentialsEnabled = serverCredentialsEnabled;
}
/**
* get the credentials for the API Server
* @return the credentials
*/
public String getServerCredentials() {
return serverCredentials;
}
/**
* Sets the credentials used by the API Server
* @param serverCredentials a String of the API Server
*/
public void setServerCredentials(String serverCredentials) {
this.serverCredentials = serverCredentials;
}
}

View File

@@ -0,0 +1,77 @@
package me.zacharias.chat.core.files;
import me.zacharias.chat.core.Core;
import org.intellij.lang.annotations.MagicConstant;
import java.io.*;
import java.util.Arrays;
/**
* Base class responsible for the {@link me.zacharias.chat.core.files} related systems
*/
public class FileHandler {
/**
* The current instance of {@link FileHandler}
*/
private static FileHandler instance;
/**
* The directory used as base for this instance of {@link FileHandler}. This is where all files that can be read or writen will be located
*/
private final File directory;
/**
* Creates a new instance as well as setting the {@link #instance} to this new one
* @param baseDirectory the directory to be used as base directory
*/
public FileHandler(@MagicConstant(valuesFromClass = FileHandlerLocation.class) String baseDirectory) {
directory = new File(baseDirectory);
if(!directory.exists())
directory.mkdirs();
instance = this;
}
/**
*
* @param filename
* @return
* @throws FileHandlerException
*/
public String readFile(String filename) throws FileHandlerException {
if(filename.contains(".."))
{
throw new FileHandlerException("File \"" + filename + "\" tries to retrace path");
}
File file = new File(directory, filename);
if(file.exists())
{
try{
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder data = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
{
data.append(line);
}
return data.toString();
} catch(FileNotFoundException e){
Core.writeLog(e.getMessage());
for(StackTraceElement st : e.getStackTrace())
{
Core.writeLog(st.toString());
}
throw new FileHandlerException("Cant find file \""+filename+"\"");
} catch (IOException e) {
Core.writeLog(e.getMessage());
for(StackTraceElement st : e.getStackTrace())
{
Core.writeLog(st.toString());
}
throw new FileHandlerException(e.getMessage());
}
}
throw new FileHandlerException("Cant find file \""+filename+"\"");
}
}

View File

@@ -0,0 +1,7 @@
package me.zacharias.chat.core.files;
public class FileHandlerException extends RuntimeException {
public FileHandlerException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,7 @@
package me.zacharias.chat.core.files;
import me.zacharias.chat.core.Core;
public class FileHandlerLocation {
public static final String DATA_FILES = Core.DATA+"/files";
}

View File

@@ -0,0 +1,4 @@
package me.zacharias.chat.core.files;
public class ListFiles {
}

View File

@@ -23,13 +23,13 @@ public class AddMemoryFunction extends OllamaFunctionTool {
@Override
public String description() {
return "Add to the memory";
return "Remember somthing";
}
@Override
public OllamaPerameter parameters() {
return OllamaPerameter.builder()
.addProperty("memory", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The memory to store", true)
.addProperty("memory", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The memory to remember", true)
.build();
}

View File

@@ -24,7 +24,7 @@ public class GetMemoryFunction extends OllamaFunctionTool {
@Override
public String description() {
return "Retrives all the memory";
return "Retrieves all the memory's";
}
@Override

View File

@@ -23,13 +23,13 @@ public class RemoveMemoryFunction extends OllamaFunctionTool {
@Override
public String description() {
return "Remove from the memory";
return "Forget a memory";
}
@Override
public OllamaPerameter parameters() {
return OllamaPerameter.builder()
.addProperty("memory", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The memory to remove", true)
.addProperty("memory", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The memory to forget", true)
.build();
}

View File

@@ -2,6 +2,10 @@ package me.zacharias.chat.ollama;
import me.zacharias.chat.core.Core;
import me.zacharias.chat.core.LaunchOptions;
import me.zacharias.chat.core.files.FileHandlerLocation;
import me.zacharias.chat.core.files.FileHandler;
import org.intellij.lang.annotations.MagicConstant;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -365,6 +369,14 @@ public class OllamaObject {
this.model = model;
return this;
}
public OllamaObjectBuilder addFileTools(@MagicConstant(valuesFromClass = FileHandlerLocation.class) String baseDirectory)
{
FileHandler fileHandler = new FileHandler(baseDirectory);
if(false);
return this;
}
/**
* Builds the {@link OllamaObject}