结构化输出:是将大模型返回的文本信息转化为结构型数据,例如json,对象等。
实现方式3种:
1.利用prompt
2.prompt+json mode
3.大模型等JSON Schema
java
public interface AiCodeService {
@SystemMessage(fromResource = "ai.txt")
Report chatForReportWithMemoryId(@MemoryId String memoryId, @UserMessage String userMessage);
// 定义一个类:学习报告
record Report(String name, List<String> suggestionList) {
};
}
@Test
void chatForReportWithMemoryId() {
String user1 = "user-001";
AiCodeService.Report report = aiCodeService.chatForReportWithMemoryId(user1, "你好,我是程序员吴彦祖");
System.out.println("report = " + report);
}