|
23 | 23 | import org.assertj.core.api.Assertions;
|
24 | 24 | import org.junit.jupiter.api.Test;
|
25 | 25 |
|
| 26 | +import org.springframework.ai.chat.prompt.ChatOptions; |
| 27 | +import org.springframework.ai.chat.prompt.ChatOptionsBuilder; |
26 | 28 | import org.springframework.ai.chat.prompt.Prompt;
|
27 | 29 | import org.springframework.ai.chat.prompt.PromptTemplate;
|
28 | 30 | import org.springframework.ai.chat.prompt.SystemPromptTemplate;
|
29 | 31 |
|
30 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
| 33 | +import static org.junit.Assert.assertNotSame; |
31 | 34 |
|
32 | 35 | @SuppressWarnings("unchecked")
|
33 | 36 | class PromptTests {
|
@@ -130,4 +133,21 @@ void testBadFormatOfTemplateString() {
|
130 | 133 | .hasMessage("The template string is not valid.");
|
131 | 134 | }
|
132 | 135 |
|
| 136 | + @Test |
| 137 | + public void testPromptCopy() { |
| 138 | + String template = "Hello, {name}! Your age is {age}."; |
| 139 | + Map<String, Object> model = new HashMap<>(); |
| 140 | + model.put("name", "Alice"); |
| 141 | + model.put("age", 30); |
| 142 | + PromptTemplate promptTemplate = new PromptTemplate(template, model); |
| 143 | + ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.5).withMaxTokens(100).build(); |
| 144 | + |
| 145 | + Prompt prompt = promptTemplate.create(model, chatOptions); |
| 146 | + |
| 147 | + Prompt copiedPrompt = prompt.copy(); |
| 148 | + assertNotSame(prompt, copiedPrompt); |
| 149 | + assertNotSame(prompt.getOptions(), copiedPrompt.getOptions()); |
| 150 | + assertNotSame(prompt.getInstructions(), copiedPrompt.getInstructions()); |
| 151 | + } |
| 152 | + |
133 | 153 | }
|
0 commit comments