diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index b1c23af..18c6fd9 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -12,8 +12,10 @@
+
-
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 3a83431..4b6a6d0 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -7,7 +7,7 @@
-
+
\ No newline at end of file
diff --git a/Core/src/main/java/me/zacharias/chat/core/Core.java b/Core/src/main/java/me/zacharias/chat/core/Core.java
index 33a3f99..22904b5 100644
--- a/Core/src/main/java/me/zacharias/chat/core/Core.java
+++ b/Core/src/main/java/me/zacharias/chat/core/Core.java
@@ -52,7 +52,7 @@ public class Core {
/**
* The IP of the Ollama API.
*/
- private String ollamaIP = "192.168.5.178";//"192.168.5.184";
+ private String ollamaIP = "localhost";//"192.168.5.184";
/**
* The port of the Ollama API.
*/
@@ -402,7 +402,7 @@ public class Core {
if(jsonObject.has("function"))
{
JSONObject function = jsonObject.getJSONObject("function");
- List> functions = funtionTools.stream().filter(func -> (func.getKey().name()+func.getValue()).equalsIgnoreCase(function.getString("name"))).toList();
+ List> functions = funtionTools.stream().filter(func -> (func.getKey().name()).equalsIgnoreCase(function.getString("name"))).toList();
if(functions.isEmpty()) {
ollamaObject.addMessage(new OllamaToolError("Function '"+function.getString("name")+"' does not exist"));
diff --git a/Display/build.gradle b/Display/build.gradle
index f3d6c25..7916767 100644
--- a/Display/build.gradle
+++ b/Display/build.gradle
@@ -11,6 +11,7 @@ dependencies {
implementation project(":GeniusAPI")
implementation project(":API")
implementation project(":WikipediaTool")
+ implementation project(":MovieSugest")
}
test {
diff --git a/Display/src/main/java/me/zacharias/chat/display/Display.java b/Display/src/main/java/me/zacharias/chat/display/Display.java
index a266614..c8be385 100644
--- a/Display/src/main/java/me/zacharias/chat/display/Display.java
+++ b/Display/src/main/java/me/zacharias/chat/display/Display.java
@@ -1,6 +1,7 @@
package me.zacharias.chat.display;
-import me.zacharias.chat.api.APIApplication;
+//import me.zacharias.chat.api.APIApplication;
+import me.noah.movie.sugest.MovieSugestTool;
import me.zacharias.chat.core.Core;
import me.zacharias.chat.core.Pair;
import me.zacharias.chat.core.PrintMessageHandler;
@@ -47,10 +48,10 @@ public class Display {
public Display()
{
- core.setOllamaObject/*NoMemory*/(OllamaObject.builder()
- //.setModel("llama3.2")
+ core.setOllamaObjectNoMemory(OllamaObject.builder()
+ .setModel("llama3.2")
//.setModel("gemma3:12b")
- .setModel("qwen3:8b")
+// .setModel("qwen3:8b")
.keep_alive(10)
//.stream(false)
//.addFileTools(FileHandlerLocation.DATA_FILES)
@@ -62,11 +63,12 @@ public class Display {
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 MALAPITool().getOllamaTools());
+// core.addTools(new GeniusTools().getGeniusTools());
core.addTools(new WikipediaTool().getWikipediaToolsInstance());
+ core.addTools(new MovieSugestTool().getMovieSugestTools());
- APIApplication.start();
+// APIApplication.start();
//core.getOllamaObject().addMessage(new OllamaMessage(OllamaMessageRole.SYSTEM, "Have a nice tone and use formal wording"));
diff --git a/MALAPITool/src/main/java/me/zacharias/chat/mal/api/endpoints/GetAnimeDetails.java b/MALAPITool/src/main/java/me/zacharias/chat/mal/api/endpoints/GetAnimeDetails.java
index 08c4383..9cf5924 100644
--- a/MALAPITool/src/main/java/me/zacharias/chat/mal/api/endpoints/GetAnimeDetails.java
+++ b/MALAPITool/src/main/java/me/zacharias/chat/mal/api/endpoints/GetAnimeDetails.java
@@ -30,7 +30,7 @@ public class GetAnimeDetails extends MALEndpointTool {
}
@Override
- public OllamaPerameter parameters() {
+public OllamaPerameter parameters() {
return OllamaPerameter.builder()
.addProperty("id", OllamaPerameter.OllamaPerameterBuilder.Type.INT, "The id of the anime", true)
.addProperty("fields", OllamaPerameter.OllamaPerameterBuilder.Type.ARRAY, "The fields to return, defaults to [\"id\", \"title\", \"synopsis\", \"genres\"]")
diff --git a/MovieSugest/build.gradle b/MovieSugest/build.gradle
new file mode 100644
index 0000000..f64fe3e
--- /dev/null
+++ b/MovieSugest/build.gradle
@@ -0,0 +1,20 @@
+plugins {
+ id 'java'
+}
+
+group = 'me.zacharias'
+version = '1.0-SNAPSHOT'
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ testImplementation platform('org.junit:junit-bom:5.10.0')
+ testImplementation 'org.junit.jupiter:junit-jupiter'
+ implementation project(":Core")
+}
+
+test {
+ useJUnitPlatform()
+}
\ No newline at end of file
diff --git a/MovieSugest/src/main/java/me/noah/movie/sugest/MovieSugestTool.java b/MovieSugest/src/main/java/me/noah/movie/sugest/MovieSugestTool.java
new file mode 100644
index 0000000..512b8ff
--- /dev/null
+++ b/MovieSugest/src/main/java/me/noah/movie/sugest/MovieSugestTool.java
@@ -0,0 +1,86 @@
+package me.noah.movie.sugest;
+
+import me.noah.movie.sugest.endpoints.GetMovieByTitle;
+import me.zacharias.chat.core.Core;
+import me.zacharias.chat.ollama.OllamaFunctionTools;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashMap;
+
+public class MovieSugestTool {
+ private OllamaFunctionTools movieSugestTools;
+
+ private static final String BASE_URL = "https://api.themoviedb.org/3";
+
+ private String authentication;
+
+ public MovieSugestTool(){
+ this.movieSugestTools = OllamaFunctionTools.builder()
+ .addTool(new GetMovieByTitle(this), Core.Source.INTERNAL)
+ .build();
+ try {
+ JSONObject obj = new JSONObject(Files.readString(Path.of(Core.DATA_DIR + "/movieapi.json")));
+ this.authentication = obj.getString("API-key");
+ //this.Client_Secret = obj.getString("client_secret");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public OllamaFunctionTools getMovieSugestTools() {
+ return movieSugestTools;
+ }
+
+ public JSONObject APIRequest(String endpoint, HashMap params) {
+ try {
+
+ String urlParams = ParameterStringBuilder.getParamsString(params);
+
+ URL url = new URI(this.BASE_URL + endpoint + "?" + urlParams).toURL();
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setRequestProperty("Content-Type", "application/json");
+ connection.setRequestProperty("api_key", this.authentication);
+ connection.setDoOutput(true);
+ connection.setConnectTimeout(80 * 1000);
+
+ int responseCode = connection.getResponseCode();
+
+ // HTTP_OK or 200 response code generally means that the server ran successfully without any errors
+ StringBuilder response = new StringBuilder();
+
+ // Read response content
+ // connection.getInputStream() purpose is to obtain an input stream for reading the server's response.
+ try (
+ BufferedReader reader = new BufferedReader( new InputStreamReader( connection.getInputStream()))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ response.append(line); // Adds every line to response till the end of file.
+ }
+ }
+
+ if (responseCode == HttpURLConnection.HTTP_OK) {
+
+
+ connection.disconnect();
+ return new JSONObject(response.toString());
+ }
+ else {
+ connection.disconnect();
+ System.err.println("Error: HTTP Response code - " + responseCode + "\n"+response.toString());
+ throw new RuntimeException("HTTP Response code - " + responseCode);
+ }
+ }catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("Error: " + e.getMessage());
+ }
+ }
+}
diff --git a/MovieSugest/src/main/java/me/noah/movie/sugest/ParameterStringBuilder.java b/MovieSugest/src/main/java/me/noah/movie/sugest/ParameterStringBuilder.java
new file mode 100644
index 0000000..0ce8629
--- /dev/null
+++ b/MovieSugest/src/main/java/me/noah/movie/sugest/ParameterStringBuilder.java
@@ -0,0 +1,27 @@
+package me.noah.movie.sugest;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+
+public class ParameterStringBuilder {
+ public static String getParamsString(Map params)
+ throws UnsupportedEncodingException {
+ if(params == null)
+ return "";
+ StringBuilder result = new StringBuilder();
+
+ for (Map.Entry entry : params.entrySet()) {
+ result.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8));
+ result.append("=");
+ result.append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8));
+ result.append("&");
+ }
+
+ String resultString = result.toString();
+ return !resultString.isEmpty()
+ ? resultString.substring(0, resultString.length() - 1)
+ : resultString;
+ }
+}
\ No newline at end of file
diff --git a/MovieSugest/src/main/java/me/noah/movie/sugest/endpoints/GetMovieByTitle.java b/MovieSugest/src/main/java/me/noah/movie/sugest/endpoints/GetMovieByTitle.java
new file mode 100644
index 0000000..f8dcefc
--- /dev/null
+++ b/MovieSugest/src/main/java/me/noah/movie/sugest/endpoints/GetMovieByTitle.java
@@ -0,0 +1,63 @@
+package me.noah.movie.sugest.endpoints;
+
+import me.noah.movie.sugest.MovieSugestTool;
+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 me.zacharias.chat.ollama.exceptions.OllamaToolErrorException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class GetMovieByTitle extends OllamaFunctionTool{
+ private final MovieSugestTool instance;
+
+ public GetMovieByTitle(MovieSugestTool instance) {
+ this.instance = instance;
+ }
+
+ @Override
+ public String name() {
+ return "movie_description";
+ }
+
+ @Override
+ public String description() {
+ return "get the details of movie";
+ }
+
+ @Override
+ public OllamaPerameter parameters() {
+ return OllamaPerameter.builder()
+ .addProperty("query", OllamaPerameter.OllamaPerameterBuilder.Type.STRING, "Movie or sereis title", true)
+ .build();
+ }
+
+ @Override
+ public OllamaToolRespnce function(OllamaFunctionArgument... args) {
+ String query = null;
+
+ if (args.length > 0){
+ query = (String) args[0] .value();
+ }
+ else {
+ throw new OllamaToolErrorException(name(), "query most be specefied");
+ }
+ HashMap < String, String > map = new HashMap<>();
+ map.put("query", query);
+ map.put("include_adult", "true");
+
+ JSONObject obj = instance.APIRequest("search/movie", map);
+
+ ArrayList < String > overviews = new ArrayList<>();
+ for (Object obj1: obj.getJSONArray("results")){
+ if (obj instanceof JSONObject result){
+ overviews.add(result.getString("overview"));
+ }
+ }
+
+ return new OllamaToolRespnce(name(), overviews.toString());
+ }
+}
diff --git a/settings.gradle b/settings.gradle
index 4db86ea..871379c 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -4,4 +4,6 @@ include 'API', 'Core', 'Display', 'launcher'
include 'MALAPITool'
include 'GeniusAPI'
-include 'WikipediaTool'
\ No newline at end of file
+include 'WikipediaTool'
+include 'MovieSugest'
+