Add test for prompt copy
This commit is contained in:
@@ -23,11 +23,14 @@ import java.util.Set;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.chat.prompt.PromptTemplate;
|
||||
import org.springframework.ai.chat.prompt.SystemPromptTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
class PromptTests {
|
||||
@@ -130,4 +133,21 @@ class PromptTests {
|
||||
.hasMessage("The template string is not valid.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPromptCopy() {
|
||||
String template = "Hello, {name}! Your age is {age}.";
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
model.put("name", "Alice");
|
||||
model.put("age", 30);
|
||||
PromptTemplate promptTemplate = new PromptTemplate(template, model);
|
||||
ChatOptions chatOptions = ChatOptionsBuilder.builder().withTemperature(0.5).withMaxTokens(100).build();
|
||||
|
||||
Prompt prompt = promptTemplate.create(model, chatOptions);
|
||||
|
||||
Prompt copiedPrompt = prompt.copy();
|
||||
assertNotSame(prompt, copiedPrompt);
|
||||
assertNotSame(prompt.getOptions(), copiedPrompt.getOptions());
|
||||
assertNotSame(prompt.getInstructions(), copiedPrompt.getInstructions());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user