Added My Anime List API wrapper

for documentation on MAL API check out the [API docs](https://myanimelist.net/apiconfig/references/api/v2)

Display:Display.java
- Switched the AI model to `qwen3:8b`
- some temporary test changes
- switched to using static references when supposed too

MALAPITool
- Module for handling the MAL API

MALAPITool:README.md
- Some general information about the tools

Started adding some base systems for finding API endpoints, will later be added to the API module for the ability to add plugins

.gitignore
- Added so all data folder are ignored. So submodules data folder from testing aren't added to git

Core:OllamaObject.java
- switched location of messages.json from the static location of `./cache/` to the dynamic location of `${Core.DATA_DIR}/messages.json`

Core:OllamaPerameter.java
- Added ENUM and ARRAY values. Incidentally also discover that Ollama supports more than just STRING, INT, and BOOLEAN ad parameters

Core:Core.java
- Added precluding day to the name of logging files, now using the format dd_HH-mm-ss
This commit is contained in:
2025-05-23 15:24:58 +02:00
parent 58c23c5897
commit 5c3efa1376
19 changed files with 678 additions and 18 deletions

View File

@@ -160,7 +160,7 @@ public class Core {
logWriter.close();
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH-mm-ss");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd_HH-mm-ss");
File messagesFile = new File("./messages/"+now.format(formatter)+".json");
@@ -175,7 +175,7 @@ public class Core {
messagesWriter.write(messages.toString());
messagesWriter.close();
File f = new File("./cache/messages.json");
File f = new File("./data/messages.json");
if(f.exists())
{
f.delete();
@@ -236,14 +236,28 @@ public class Core {
/**
* Adds a new tool to the System
* @param funtionTool The tool to add
* @param functionTool The tool to add
* @param source The source of the tool
*/
public void addTool(OllamaFunctionTool funtionTool, @MagicConstant(valuesFromClass = Core.Source.class) String source) {
funtionTools.add(new Pair<>(funtionTool, source));
ollamaObject.addTool(funtionTool);
public void addTool(OllamaFunctionTool functionTool, @MagicConstant(valuesFromClass = Source.class) String source) {
funtionTools.add(new Pair<>(functionTool, source));
ollamaObject.addTool(functionTool);
}
/**
* Adds a list of tools to the System
* @param tools The tools to add
*/
@SuppressWarnings("MagicConstant")
public void addTools(OllamaFunctionTools tools)
{
for(Pair<OllamaFunctionTool, String> tool : tools)
{
addTool(tool.getKey(), tool.getValue());
}
}
/**
* Gets the list of tools added to the System
* @return The list of tools added to the System compressed as Pairs of the tool and the source
@@ -324,6 +338,7 @@ public class Core {
throw new RuntimeException("HTTP Response code - " + responseCode);
}
} catch (IOException e) {
// System.err.println("Error: JSON: "+);
throw new RuntimeException(e);
}
}

View File

@@ -0,0 +1,111 @@
package me.zacharias.chat.ollama;
import me.zacharias.chat.core.Core;
import me.zacharias.chat.core.Pair;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;
public class OllamaFunctionTools implements Iterable<Pair<OllamaFunctionTool, String>> {
/**
* A list of tools for the OllamaObject.
* OPS! Shuld only be ussed to add a set of tools to the OllamaObject, not to be used for storage of tools internaly or externaly
*/
private ArrayList<OllamaFunctionTool> tools;
/**
* A list of source for the tools.
* OPS! Shuld only be ussed to add a set of tools to the OllamaObject, not to be used for storage of tools internaly or externaly
* OPS! most be the same size as the tools list! since each tool matches to a source!
*/
private ArrayList<String> source;
/**
* Gets the tools of the {@link OllamaFunctionTools}
* @param tools A list of {@link OllamaFunctionTool}
* @param source The source of the tools
*/
private OllamaFunctionTools(ArrayList<OllamaFunctionTool> tools, ArrayList<String> source) {
if(source == null || tools == null || source.size() != tools.size() || source.isEmpty())
throw new IllegalArgumentException("The source and tools must be the same size! and not empty!");
this.tools = tools;
this.source = source;
}
/**
* Gets the tools of the {@link OllamaFunctionTools}
* @param tools A list of {@link OllamaFunctionTool}
* @param source The source of the tools
*/
private OllamaFunctionTools(OllamaFunctionTool[] tools, @MagicConstant(valuesFromClass = Core.Source.class) String[] source) {
if(source == null || tools == null || source.length != tools.length || source.length == 0)
throw new IllegalArgumentException("The source and tools must be the same size! and not empty!");
this.tools = new ArrayList<>();
this.source = new ArrayList<>();
for (OllamaFunctionTool tool : tools) {
this.tools.add(tool);
this.source.add(tool.name());
}
for (String s : source) {
if (s.equals(Core.Source.INTERNAL)) {
this.source.add(s);
}
}
}
public static OllamaFunctionToolsBuilder builder() {
return new OllamaFunctionToolsBuilder();
}
@Override
public @NotNull Iterator<Pair<OllamaFunctionTool, String>> iterator() {
ArrayList<Pair<OllamaFunctionTool, String>> pairs = new ArrayList<>();
for (int i = 0; i < tools.size(); i++) {
pairs.add(new Pair<>(tools.get(i), source.get(i)));
}
return pairs.iterator();
}
@Override
public void forEach(Consumer<? super Pair<OllamaFunctionTool, String>> action) {
for (Pair<OllamaFunctionTool, String> pair : this) {
action.accept(pair);
}
}
@Override
public Spliterator<Pair<OllamaFunctionTool, String>> spliterator() {
// TODO: Implement this method
throw new UnsupportedOperationException("Not implemented yet");
//return Iterable.super.spliterator();
}
public static class OllamaFunctionToolsBuilder {
private ArrayList<OllamaFunctionTool> tools = new ArrayList<>();
private ArrayList<String> source = new ArrayList<>();
public OllamaFunctionToolsBuilder addTool(OllamaFunctionTool tool, @MagicConstant(valuesFromClass = Core.Source.class) String source) {
this.tools.add(tool);
this.source.add(source);
return this;
}
public OllamaFunctionToolsBuilder addTools(HashMap<OllamaFunctionTool, String> tools) {
for (OllamaFunctionTool tool : tools.keySet()) {
this.tools.add(tool);
this.source.add(tools.get(tool));
}
return this;
}
public OllamaFunctionTools build() {
return new OllamaFunctionTools(tools, source);
}
}
}

View File

@@ -75,7 +75,7 @@ public class OllamaObject {
LaunchOptions launchOptions = new LaunchOptions();
if(launchOptions.isLoadOld()) {
System.out.println("Loading old data...");
File f = new File("./cache/messages.json");
File f = new File(Core.DATA_DIR+"/messages.json");
if(f.exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(f));
@@ -375,7 +375,8 @@ public class OllamaObject {
FileHandler fileHandler = new FileHandler(baseDirectory);
if(false);
return this;
throw new IllegalArgumentException("FileHandler is not supported yet!");
}
/**

View File

@@ -192,7 +192,15 @@ public class OllamaPerameter {
/**
* Represents a boolean parameter.
*/
BOOLEAN("boolean");
BOOLEAN("boolean"),
/**
* Represents a enum parameter.
*/
ENUM("enum"),
/**
* Represents a array parameter.
*/
ARRAY("array");
/**
* The type of the parameter.