From f2b299f3da16c8d3510a726c839d4f504ce85319 Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Fri, 28 Jul 2023 21:17:07 -0400 Subject: [PATCH] prompt reworking --- .../ai/core/prompts/AiPromptTemplate.java | 1 - .../ai/core/prompts/ChatPromptTemplate.java | 2 -- .../core/prompts/FunctionPromptTemplate.java | 2 -- .../ai/core/prompts/PromptTemplate.java | 1 + .../ai/core/prompts/SystemPromptTemplate.java | 2 +- .../ai/core/prompts/messages/Message.java | 3 +- .../ai/core/prompts/ChatTests.java | 30 +++++++++---------- .../ai/core/prompts/PromptTests.java | 5 ++-- 8 files changed, 21 insertions(+), 25 deletions(-) diff --git a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/AiPromptTemplate.java b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/AiPromptTemplate.java index 9343e94cb..665ca6ab6 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/AiPromptTemplate.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/AiPromptTemplate.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.springframework.ai.core.prompts; import java.util.Map; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/ChatPromptTemplate.java b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/ChatPromptTemplate.java index 6176dc75a..86c04029f 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/ChatPromptTemplate.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/ChatPromptTemplate.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.springframework.ai.core.prompts; import java.util.Map; @@ -44,5 +43,4 @@ public class ChatPromptTemplate extends PromptTemplate { return new Prompt(new ChatMessage(render(model), this.role)); } - } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/FunctionPromptTemplate.java b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/FunctionPromptTemplate.java index d27a9132b..881db0948 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/FunctionPromptTemplate.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/FunctionPromptTemplate.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.springframework.ai.core.prompts; public class FunctionPromptTemplate extends PromptTemplate { @@ -25,5 +24,4 @@ public class FunctionPromptTemplate extends PromptTemplate { super(template); } - } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/PromptTemplate.java b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/PromptTemplate.java index 73cb172ed..1e9595a08 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/PromptTemplate.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/PromptTemplate.java @@ -107,4 +107,5 @@ public class PromptTemplate extends AbstractPromptTemplate { "All template variables were not replaced. Missing variable names are " + missingEntries); } } + } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/SystemPromptTemplate.java b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/SystemPromptTemplate.java index 9a7783ffd..f992b4e45 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/SystemPromptTemplate.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/SystemPromptTemplate.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.springframework.ai.core.prompts; import java.util.Map; @@ -36,4 +35,5 @@ public class SystemPromptTemplate extends PromptTemplate { public Prompt create(Map model) { return new Prompt(new SystemMessage(render(model))); } + } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/messages/Message.java b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/messages/Message.java index 79511222c..4b98e9349 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/messages/Message.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/core/prompts/messages/Message.java @@ -22,7 +22,8 @@ public interface Message { String getContent(); - //TODO investigate use of "function_name" and "name" - maybe cna be first class representation vs. map. + // TODO investigate use of "function_name" and "name" - maybe cna be first class + // representation vs. map. Map getProperties(); MessageType getMessageType(); diff --git a/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/ChatTests.java b/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/ChatTests.java index a9518154a..20c75558e 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/ChatTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/ChatTests.java @@ -14,25 +14,25 @@ * limitations under the License. */ - package org.springframework.ai.core.prompts; import org.junit.jupiter.api.Test; public class ChatTests { -// @Test -// void testChat() { -// -// String customerStyle = "American English in a calm and respectful tone"; -// String customerEmail = "Arrr, I be fuming that me blender lid " -// + "flew off and splattered me kitchen walls " -// + "with smoothie! And to make matters worse, " -// + "the warranty don't cover the cost of " -// + "cleaning up me kitchen. I need yer help " -// + "right now, matey!"; -// ChatOpenAi chatOpenAi = new ChatOpenAi(); -// chatOpenAi -// -// } + // @Test + // void testChat() { + // + // String customerStyle = "American English in a calm and respectful tone"; + // String customerEmail = "Arrr, I be fuming that me blender lid " + // + "flew off and splattered me kitchen walls " + // + "with smoothie! And to make matters worse, " + // + "the warranty don't cover the cost of " + // + "cleaning up me kitchen. I need yer help " + // + "right now, matey!"; + // ChatOpenAi chatOpenAi = new ChatOpenAi(); + // chatOpenAi + // + // } + } diff --git a/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/PromptTests.java b/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/PromptTests.java index 39c9bd224..3d67b4bde 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/PromptTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/core/prompts/PromptTests.java @@ -56,8 +56,6 @@ class PromptTests { assertThat(prompt.getMessages()).isNotEmpty().hasSize(1); System.out.println(prompt.getContents()); - - String systemTemplate = "You are a helpful assistant that translates {input_language} to {output_language}."; // system_message_prompt = SystemMessagePromptTemplate.from_template(template) @@ -81,7 +79,8 @@ class PromptTests { PromptTemplate promptTemplate = new SystemPromptTemplate(systemTemplate); Prompt systemPrompt = promptTemplate.create(systemModel); - promptTemplate = new PromptTemplate(humanTemplate); // creates a Prompt with HumanMessage + promptTemplate = new PromptTemplate(humanTemplate); // creates a Prompt with + // HumanMessage Prompt humanPrompt = promptTemplate.create(humanModel); // ChatPromptTemplate chatPromptTemplate = new ChatPromptTemplate(systemPrompt,