Bug Description
The parameterized render(Map<String, Object> additionalVariables)
method of the org.springframework.ai.chat.prompt.PromptTemplate
class lacks handling for Resource-type variables in this.variables
, resulting in inconsistent behavior compared to the no-arg render()
method.
Environment - Java Version: OpenJdk 22.0.2 - Spring AI Version: 1.0.2
Steps to Reproduce
1. Create a classpath resource file templates/tem.txt
with the content: Zhang San
(note: this is the expected value to be rendered).
2. Run the following test code:
@Test
public void testPromptTemplate() throws IOException {
// Load the classpath resource (content: "Zhang San")
Resource resource = new ClassPathResource("templates/tem.txt");
// Build PromptTemplate: bind the Resource to "name" in this.variables
PromptTemplate promptTemplate = PromptTemplate.builder()
.template("hello {name}")
.variables(Map.of("name", resource))
.build();
/*
* Actual Output: hello class path resource [templates/tem.txt]
* Expected Output: hello Zhang San
*/
System.out.println(promptTemplate.render(Map.of())); // Call parameterized render with empty additional variables
}
Comment From: elmahdi43
Hello, I just checked your bug. It was fixed in the commit 0fd9fd5 I think you can close this one @ilayaperumalg