From 330d7df389cd75851ad32dc87f07a0ae8944a09b Mon Sep 17 00:00:00 2001 From: Zacharias Date: Mon, 20 Jul 2026 18:03:31 +0200 Subject: [PATCH] Fixed some errors with the System prompt Chaged java version to make this more compadible --- Core/build.gradle | 2 +- .../me/neurodock/core/LLMSystemPrompt.java | 2 +- .../me/neurodock/ollama/OllamaObject.java | 63 +++++++++++-------- gradle.properties | 2 +- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/Core/build.gradle b/Core/build.gradle index 14a6b25..7fe01bf 100644 --- a/Core/build.gradle +++ b/Core/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' } -version = '1.9.0' +version = '1.9.5' dependencies { implementation project(":Plugin-API") diff --git a/Core/src/main/java/me/neurodock/core/LLMSystemPrompt.java b/Core/src/main/java/me/neurodock/core/LLMSystemPrompt.java index fa29ba4..8674c38 100644 --- a/Core/src/main/java/me/neurodock/core/LLMSystemPrompt.java +++ b/Core/src/main/java/me/neurodock/core/LLMSystemPrompt.java @@ -137,7 +137,7 @@ public class LLMSystemPrompt { for (Pair tool : ollamaObject.getTools()) { if(tool.getKey() instanceof OllamaFunctionTool funcTool) { String llmName = funcTool.name() + "_" + (funcTool.getSource() != null ? funcTool.getSource() : ""); - String hint = capabilities.getUsageHints().get(tool.getClass()); + String hint = capabilities.getUsageHints().get(funcTool.getClass()); // fall back to description() if no explicit routing hint was set String line = hint != null ? hint : funcTool.description(); diff --git a/Core/src/main/java/me/neurodock/ollama/OllamaObject.java b/Core/src/main/java/me/neurodock/ollama/OllamaObject.java index 14c03b6..d32587c 100644 --- a/Core/src/main/java/me/neurodock/ollama/OllamaObject.java +++ b/Core/src/main/java/me/neurodock/ollama/OllamaObject.java @@ -56,6 +56,10 @@ public class OllamaObject { * The keep alive of the Ollama Object. */ String keep_alive; + /** + * The system prompt object used to re-generate the system prompt. + */ + LLMSystemPrompt systemPrompt; /** * Creates a new instance of OllamaObject. @@ -66,10 +70,12 @@ public class OllamaObject { * @param options The options of the Ollama Object. see {@link OllamaObject#options} * @param stream If the Ollama Object is streamed. see {@link OllamaObject#stream} * @param keep_alive The keep alive of the Ollama Object. see {@link OllamaObject#keep_alive} + * @param prompt The system prompt object of the Ollama Object. See {@link OllamaObject#systemPrompt} */ private OllamaObject(String model, ArrayList messages, ArrayList> tools, JSONObject format, Map options, boolean stream, String keep_alive, LLMSystemPrompt prompt) { this.model = model; this.messages = messages; + this.systemPrompt = prompt; // Reflecting the reflection injection for ALL tools that was added in the OllamaObjectBuilder, etc, etc comment.. its past midnignt and i'm tired. for(Pair tool : tools) @@ -135,34 +141,39 @@ public class OllamaObject { } } - if(prompt == null) { - // Do nothing - } - else if(!this.messages.isEmpty()) - { - OllamaMessage systemPrompt = this.messages.getFirst(); - if(systemPrompt.getRole() != OllamaMessageRole.SYSTEM) - { - System.out.println("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt"); - Core.writeLog("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt"); - ArrayList newMessages = new ArrayList<>(); - newMessages.add(prompt.generateSystemPrompt()); - newMessages.addAll(messages); - this.messages = newMessages; - } - else - { - System.out.println("Replacing System prompt..."); - Core.writeLog("Replacing System prompt..."); - systemPrompt = prompt.generateSystemPrompt(); - this.messages.set(0, systemPrompt); + if(prompt != null) { + prompt.generateCapabilities(this); + if (!this.messages.isEmpty()) { + OllamaMessage systemPrompt = this.messages.getFirst(); + if (systemPrompt.getRole() != OllamaMessageRole.SYSTEM) { + System.out.println("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt"); + Core.writeLog("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt"); + ArrayList newMessages = new ArrayList<>(); + newMessages.add(prompt.generateSystemPrompt()); + newMessages.addAll(messages); + this.messages = newMessages; + } else { + System.out.println("Replacing System prompt..."); + Core.writeLog("Replacing System prompt..."); + systemPrompt = prompt.generateSystemPrompt(); + this.messages.set(0, systemPrompt); + } + } else { + System.out.println("No old prompts. Inserting system prompt..."); + Core.writeLog("No old prompts. Inserting system prompt..."); + this.messages.add(prompt.generateSystemPrompt()); } } - else - { - System.out.println("No old prompts. Inserting system prompt..."); - Core.writeLog("No old prompts. Inserting system prompt..."); - this.messages.add(prompt.generateSystemPrompt()); + } + + /** + * Re-generates and sets the system promp according to the {@link LLMSystemPrompt} stored as {@link OllamaObject#systemPrompt} + */ + public void reGenerateSystemPrompt() + { + if(systemPrompt != null) { + systemPrompt.generateCapabilities(this); + setSystemPrompt(systemPrompt); } } diff --git a/gradle.properties b/gradle.properties index a660a34..fc9a6ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ # This is used in sub-project that dosent explicitly require the API sub-project to only include if thay shuld be included project wide. useAPI = true -javaVersion = 26 \ No newline at end of file +javaVersion = 25 \ No newline at end of file