forked from Chat_things/NeuroDock
Mitt arbete är för att man ska skriva in en film titel och man får en overview av den filmen Men det finns små fel som kom nu i slutet och jag har inte hunit fixa det änu :(
This commit is contained in:
4
.idea/gradle.xml
generated
4
.idea/gradle.xml
generated
@@ -12,8 +12,10 @@
|
|||||||
<option value="$PROJECT_DIR$/API" />
|
<option value="$PROJECT_DIR$/API" />
|
||||||
<option value="$PROJECT_DIR$/Core" />
|
<option value="$PROJECT_DIR$/Core" />
|
||||||
<option value="$PROJECT_DIR$/Display" />
|
<option value="$PROJECT_DIR$/Display" />
|
||||||
|
<option value="$PROJECT_DIR$/GeniusAPI" />
|
||||||
<option value="$PROJECT_DIR$/MALAPITool" />
|
<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" />
|
<option value="$PROJECT_DIR$/launcher" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -7,7 +7,7 @@
|
|||||||
<component name="FrameworkDetectionExcludesConfiguration">
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
<file type="web" url="file://$PROJECT_DIR$" />
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -52,7 +52,7 @@ public class Core {
|
|||||||
/**
|
/**
|
||||||
* The IP of the Ollama API.
|
* 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.
|
* The port of the Ollama API.
|
||||||
*/
|
*/
|
||||||
@@ -402,7 +402,7 @@ public class Core {
|
|||||||
if(jsonObject.has("function"))
|
if(jsonObject.has("function"))
|
||||||
{
|
{
|
||||||
JSONObject function = jsonObject.getJSONObject("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()) {
|
if(functions.isEmpty()) {
|
||||||
ollamaObject.addMessage(new OllamaToolError("Function '"+function.getString("name")+"' does not exist"));
|
ollamaObject.addMessage(new OllamaToolError("Function '"+function.getString("name")+"' does not exist"));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ dependencies {
|
|||||||
implementation project(":GeniusAPI")
|
implementation project(":GeniusAPI")
|
||||||
implementation project(":API")
|
implementation project(":API")
|
||||||
implementation project(":WikipediaTool")
|
implementation project(":WikipediaTool")
|
||||||
|
implementation project(":MovieSugest")
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package me.zacharias.chat.display;
|
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.Core;
|
||||||
import me.zacharias.chat.core.Pair;
|
import me.zacharias.chat.core.Pair;
|
||||||
import me.zacharias.chat.core.PrintMessageHandler;
|
import me.zacharias.chat.core.PrintMessageHandler;
|
||||||
@@ -47,10 +48,10 @@ public class Display {
|
|||||||
public Display()
|
public Display()
|
||||||
{
|
{
|
||||||
|
|
||||||
core.setOllamaObject/*NoMemory*/(OllamaObject.builder()
|
core.setOllamaObjectNoMemory(OllamaObject.builder()
|
||||||
//.setModel("llama3.2")
|
.setModel("llama3.2")
|
||||||
//.setModel("gemma3:12b")
|
//.setModel("gemma3:12b")
|
||||||
.setModel("qwen3:8b")
|
// .setModel("qwen3:8b")
|
||||||
.keep_alive(10)
|
.keep_alive(10)
|
||||||
//.stream(false)
|
//.stream(false)
|
||||||
//.addFileTools(FileHandlerLocation.DATA_FILES)
|
//.addFileTools(FileHandlerLocation.DATA_FILES)
|
||||||
@@ -62,11 +63,12 @@ public class Display {
|
|||||||
core.addTool(new TimeTool(), Core.Source.INTERNAL);
|
core.addTool(new TimeTool(), Core.Source.INTERNAL);
|
||||||
// TODO: Well Docker failes when luanched.... Fuck
|
// TODO: Well Docker failes when luanched.... Fuck
|
||||||
// core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
|
// core.addTool(new PythonRunner(core), Core.Source.INTERNAL);
|
||||||
core.addTools(new MALAPITool().getOllamaTools());
|
// core.addTools(new MALAPITool().getOllamaTools());
|
||||||
core.addTools(new GeniusTools().getGeniusTools());
|
// core.addTools(new GeniusTools().getGeniusTools());
|
||||||
core.addTools(new WikipediaTool().getWikipediaToolsInstance());
|
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"));
|
//core.getOllamaObject().addMessage(new OllamaMessage(OllamaMessageRole.SYSTEM, "Have a nice tone and use formal wording"));
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class GetAnimeDetails extends MALEndpointTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OllamaPerameter parameters() {
|
public OllamaPerameter parameters() {
|
||||||
return OllamaPerameter.builder()
|
return OllamaPerameter.builder()
|
||||||
.addProperty("id", OllamaPerameter.OllamaPerameterBuilder.Type.INT, "The id of the anime", true)
|
.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\"]")
|
.addProperty("fields", OllamaPerameter.OllamaPerameterBuilder.Type.ARRAY, "The fields to return, defaults to [\"id\", \"title\", \"synopsis\", \"genres\"]")
|
||||||
|
|||||||
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,4 +4,6 @@ include 'API', 'Core', 'Display', 'launcher'
|
|||||||
|
|
||||||
include 'MALAPITool'
|
include 'MALAPITool'
|
||||||
include 'GeniusAPI'
|
include 'GeniusAPI'
|
||||||
include 'WikipediaTool'
|
include 'WikipediaTool'
|
||||||
|
include 'MovieSugest'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user