diff --git a/agents-flex-core/src/test/java/com/agentsflex/core/test/PromptTemplateTest.java b/agents-flex-core/src/test/java/com/agentsflex/core/test/PromptTemplateTest.java new file mode 100644 index 0000000..01e24ee --- /dev/null +++ b/agents-flex-core/src/test/java/com/agentsflex/core/test/PromptTemplateTest.java @@ -0,0 +1,50 @@ +package com.agentsflex.core.test; + +import com.agentsflex.core.prompt.template.TextPromptTemplate; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class PromptTemplateTest { + + @Test + public void test001() { + Map map = new HashMap<>(); + map.put("x", "abc"); + TextPromptTemplate promptTemplate = TextPromptTemplate.of("你好,{} 今天是星期 :{{x}}{{ x }}--xx--{{x }---{{ x }}--}}--{ x} }"); + String string = promptTemplate + .format(map).toString(); + System.out.println(string); + + } + + @Test + public void test002() { + Map map = new HashMap<>(); + map.put("useName", "Michael"); + map.put("aaa", "星期3"); + TextPromptTemplate promptTemplate = TextPromptTemplate.of("你好,{{ useName }} 今天是星期 :{{aaa }}}----- {a}aa"); + String string = promptTemplate.formatToString(map); + System.out.println(string); + } + + + @Test + public void test003() { + String templateStr = "你好 {{ user.name ?? '匿名' }},欢迎来到 {{ site ?? 'AgentsFlex.com' }}!"; + TextPromptTemplate template = new TextPromptTemplate(templateStr); + + Map params = new HashMap<>(); + Map user = new HashMap<>(); + user.put("name", "Michael"); + params.put("user", user); + params.put("site", "AIFlowy.tech"); + + System.out.println(template.format(params)); + // 输出:你好 Michael,欢迎来到 AIFlowy.tech! + + System.out.println(template.format(new HashMap<>())); + // 输出:你好 匿名,欢迎来到 AgentsFlex.com! + } +}