Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8680b1cab |
4
.idea/gradle.xml
generated
4
.idea/gradle.xml
generated
@@ -12,8 +12,10 @@
|
||||
<option value="$PROJECT_DIR$/API" />
|
||||
<option value="$PROJECT_DIR$/Core" />
|
||||
<option value="$PROJECT_DIR$/Display" />
|
||||
<option value="$PROJECT_DIR$/GeniusAPI" />
|
||||
<option value="$PROJECT_DIR$/MALAPITool" />
|
||||
<option value="$PROJECT_DIR$/Plugin" />
|
||||
<option value="$PROJECT_DIR$/MovieSugest" />
|
||||
<option value="$PROJECT_DIR$/WikipediaTool" />
|
||||
<option value="$PROJECT_DIR$/launcher" />
|
||||
</set>
|
||||
</option>
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -7,7 +7,7 @@
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="corretto-21" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -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<Pair<OllamaFunctionTool, String>> functions = funtionTools.stream().filter(func -> (func.getKey().name()+func.getValue()).equalsIgnoreCase(function.getString("name"))).toList();
|
||||
List<Pair<OllamaFunctionTool, String>> 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"));
|
||||
|
||||
@@ -11,6 +11,7 @@ dependencies {
|
||||
implementation project(":GeniusAPI")
|
||||
implementation project(":API")
|
||||
implementation project(":WikipediaTool")
|
||||
implementation project(":MovieSugest")
|
||||
}
|
||||
|
||||
test {
|
||||
|
||||
@@ -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"));
|
||||
|
||||
|
||||
20
MovieSugest/build.gradle
Normal file
20
MovieSugest/build.gradle
Normal file
@@ -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()
|
||||
}
|
||||
@@ -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<String, String> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> params)
|
||||
throws UnsupportedEncodingException {
|
||||
if(params == null)
|
||||
return "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (Map.Entry<String, String> 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;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,5 @@ include 'API', 'Core', 'Display', 'launcher'
|
||||
include 'MALAPITool'
|
||||
include 'GeniusAPI'
|
||||
include 'WikipediaTool'
|
||||
include 'MovieSugest'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user