Updated OllamaFunctionTool.toString to reflect what the Ollama API actually wants
build / build (push) Has been cancelled
build / build (push) Has been cancelled
Added @NotNull annotation to OllamaFunctionTool.name and OllamaFunctionTool.parameters since the documentation reports as these being required Made sure that OllamaFunctionTool.description is actually optional as the Ollama API docs define
This commit is contained in:
@@ -6,6 +6,7 @@ import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
@@ -13,7 +14,7 @@ import java.nio.file.Path;
|
||||
public class ReadFileTool extends OllamaFunctionTool {
|
||||
FileHandler fs = FileHandler.getInstance();
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return "read_file";
|
||||
}
|
||||
|
||||
@@ -23,7 +24,7 @@ public class ReadFileTool extends OllamaFunctionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
public @NotNull OllamaPerameter parameters() {
|
||||
return OllamaPerameter.builder()
|
||||
.addProperty("file_path", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The path to the file to be read")
|
||||
.build();
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Provides the add_memory function.<br>
|
||||
@@ -17,7 +18,7 @@ public class AddMemoryFunction extends OllamaFunctionTool {
|
||||
CoreMemory memory = CoreMemory.getInstance();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return "add_memory";
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ public class AddMemoryFunction extends OllamaFunctionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
public @NotNull OllamaPerameter parameters() {
|
||||
return OllamaPerameter.builder()
|
||||
.addProperty("memory", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The memory to remember", true)
|
||||
.addProperty("identity", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The identity of the memory to remember", true)
|
||||
|
||||
@@ -4,10 +4,11 @@ import me.zacharias.chat.ollama.OllamaFunctionArgument;
|
||||
import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GetMemoriesFunction extends OllamaFunctionTool {
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return "get_memories";
|
||||
}
|
||||
|
||||
@@ -17,7 +18,7 @@ public class GetMemoriesFunction extends OllamaFunctionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
public @NotNull OllamaPerameter parameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import me.zacharias.chat.ollama.OllamaFunctionArgument;
|
||||
import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Provides the get_memory function.<br>
|
||||
@@ -18,7 +17,7 @@ public class GetMemoryFunction extends OllamaFunctionTool {
|
||||
CoreMemory memory = CoreMemory.getInstance();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return "get_memory";
|
||||
}
|
||||
|
||||
@@ -28,7 +27,7 @@ public class GetMemoryFunction extends OllamaFunctionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
public @NotNull OllamaPerameter parameters() {
|
||||
return OllamaPerameter.builder()
|
||||
.addProperty("identity", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The identity of the memory to retrieve", true)
|
||||
.build();
|
||||
|
||||
@@ -4,13 +4,14 @@ import me.zacharias.chat.ollama.OllamaFunctionArgument;
|
||||
import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONArray;
|
||||
|
||||
public class GetMemoryIdentitiesFunction extends OllamaFunctionTool {
|
||||
CoreMemory memory = CoreMemory.getInstance();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return "get_memory_identities";
|
||||
}
|
||||
|
||||
@@ -20,7 +21,7 @@ public class GetMemoryIdentitiesFunction extends OllamaFunctionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
public @NotNull OllamaPerameter parameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.zacharias.chat.ollama.OllamaFunctionTool;
|
||||
import me.zacharias.chat.ollama.OllamaPerameter;
|
||||
import me.zacharias.chat.ollama.OllamaToolRespnce;
|
||||
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Provides the remove_memory function.<br>
|
||||
@@ -17,7 +18,7 @@ public class RemoveMemoryFunction extends OllamaFunctionTool {
|
||||
CoreMemory memory = CoreMemory.getInstance();
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public @NotNull String name() {
|
||||
return "remove_memory";
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ public class RemoveMemoryFunction extends OllamaFunctionTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OllamaPerameter parameters() {
|
||||
public @NotNull OllamaPerameter parameters() {
|
||||
return OllamaPerameter.builder()
|
||||
.addProperty("identity", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "The identity of the memory to forget", true)
|
||||
.build();
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.zacharias.chat.ollama;
|
||||
|
||||
import me.zacharias.chat.core.Core;
|
||||
import me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
@@ -9,16 +10,22 @@ import org.json.JSONObject;
|
||||
*/
|
||||
public abstract class OllamaFunctionTool implements OllamaTool {
|
||||
|
||||
/**
|
||||
* This field is set via Reflection injection from {@link OllamaObject#addTool(OllamaTool, String)}.
|
||||
* As is, it will be over written. Do not set it yourself.
|
||||
*/
|
||||
protected String source = "";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("tool", "function");
|
||||
ret.put("type", "function");
|
||||
|
||||
JSONObject function = new JSONObject();
|
||||
function.put("name", name()+(source != null ? source : ""));
|
||||
function.put("description", description());
|
||||
if(description() != null) {
|
||||
function.put("description", description());
|
||||
}
|
||||
function.put("parameters", (parameters() == null?
|
||||
new JSONObject() : new JSONObject(parameters().toString())));
|
||||
|
||||
@@ -32,6 +39,7 @@ public abstract class OllamaFunctionTool implements OllamaTool {
|
||||
* This is used by Ollama to know what the tool is
|
||||
* @return The name of the tool
|
||||
*/
|
||||
@NotNull
|
||||
abstract public String name();
|
||||
|
||||
/**
|
||||
@@ -39,14 +47,18 @@ public abstract class OllamaFunctionTool implements OllamaTool {
|
||||
* This is used by Ollama to know what the tool does
|
||||
* @return The description of the tool
|
||||
*/
|
||||
abstract public String description();
|
||||
public String description(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The parameters of the tool
|
||||
* This is used by Ollama to know what parameters the tool takes
|
||||
* If null, the tool does not take any parameters
|
||||
*
|
||||
* @return The parameters of the tool or null if the tool does not take any parameters
|
||||
*/
|
||||
@NotNull
|
||||
abstract public OllamaPerameter parameters();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user