Fixed some errors with the System prompt

Chaged java version to make this more compadible
This commit is contained in:
2026-07-20 18:03:31 +02:00
parent 4cd4367a19
commit 330d7df389
4 changed files with 40 additions and 29 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ plugins {
id 'java-library' id 'java-library'
} }
version = '1.9.0' version = '1.9.5'
dependencies { dependencies {
implementation project(":Plugin-API") implementation project(":Plugin-API")
@@ -137,7 +137,7 @@ public class LLMSystemPrompt {
for (Pair<OllamaTool, String> tool : ollamaObject.getTools()) { for (Pair<OllamaTool, String> tool : ollamaObject.getTools()) {
if(tool.getKey() instanceof OllamaFunctionTool funcTool) { if(tool.getKey() instanceof OllamaFunctionTool funcTool) {
String llmName = funcTool.name() + "_" + (funcTool.getSource() != null ? funcTool.getSource() : ""); 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 // fall back to description() if no explicit routing hint was set
String line = hint != null ? hint : funcTool.description(); String line = hint != null ? hint : funcTool.description();
@@ -56,6 +56,10 @@ public class OllamaObject {
* The keep alive of the Ollama Object. * The keep alive of the Ollama Object.
*/ */
String keep_alive; String keep_alive;
/**
* The system prompt object used to re-generate the system prompt.
*/
LLMSystemPrompt systemPrompt;
/** /**
* Creates a new instance of OllamaObject. * 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 options The options of the Ollama Object. see {@link OllamaObject#options}
* @param stream If the Ollama Object is streamed. see {@link OllamaObject#stream} * @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 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<OllamaMessage> messages, ArrayList<Pair<OllamaTool, String>> tools, JSONObject format, Map<String, Object> options, boolean stream, String keep_alive, LLMSystemPrompt prompt) { private OllamaObject(String model, ArrayList<OllamaMessage> messages, ArrayList<Pair<OllamaTool, String>> tools, JSONObject format, Map<String, Object> options, boolean stream, String keep_alive, LLMSystemPrompt prompt) {
this.model = model; this.model = model;
this.messages = messages; 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. // 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<OllamaTool, String> tool : tools) for(Pair<OllamaTool, String> tool : tools)
@@ -135,34 +141,39 @@ public class OllamaObject {
} }
} }
if(prompt == null) { if(prompt != null) {
// Do nothing prompt.generateCapabilities(this);
} if (!this.messages.isEmpty()) {
else if(!this.messages.isEmpty()) OllamaMessage systemPrompt = this.messages.getFirst();
{ if (systemPrompt.getRole() != OllamaMessageRole.SYSTEM) {
OllamaMessage systemPrompt = this.messages.getFirst(); System.out.println("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt");
if(systemPrompt.getRole() != OllamaMessageRole.SYSTEM) Core.writeLog("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt");
{ ArrayList<OllamaMessage> newMessages = new ArrayList<>();
System.out.println("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt"); newMessages.add(prompt.generateSystemPrompt());
Core.writeLog("FIRST MESSAGE ISN'T A SYSTEM PROMPT!. Pushing all messages forward and injecting the system prompt"); newMessages.addAll(messages);
ArrayList<OllamaMessage> newMessages = new ArrayList<>(); this.messages = newMessages;
newMessages.add(prompt.generateSystemPrompt()); } else {
newMessages.addAll(messages); System.out.println("Replacing System prompt...");
this.messages = newMessages; Core.writeLog("Replacing System prompt...");
} systemPrompt = prompt.generateSystemPrompt();
else this.messages.set(0, systemPrompt);
{ }
System.out.println("Replacing System prompt..."); } else {
Core.writeLog("Replacing System prompt..."); System.out.println("No old prompts. Inserting system prompt...");
systemPrompt = prompt.generateSystemPrompt(); Core.writeLog("No old prompts. Inserting system prompt...");
this.messages.set(0, systemPrompt); this.messages.add(prompt.generateSystemPrompt());
} }
} }
else }
{
System.out.println("No old prompts. Inserting system prompt..."); /**
Core.writeLog("No old prompts. Inserting system prompt..."); * Re-generates and sets the system promp according to the {@link LLMSystemPrompt} stored as {@link OllamaObject#systemPrompt}
this.messages.add(prompt.generateSystemPrompt()); */
public void reGenerateSystemPrompt()
{
if(systemPrompt != null) {
systemPrompt.generateCapabilities(this);
setSystemPrompt(systemPrompt);
} }
} }
+1 -1
View File
@@ -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. # 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 useAPI = true
javaVersion = 26 javaVersion = 25