File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
spring-ai-openai/src/test/java/org/springframework/ai/openai/client Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -100,4 +100,27 @@ void beanOutputParser() {
100100 System .out .println (actorsFilms );
101101 }
102102
103+ record ActorsFilmsRecord (String actor , List <String > movies ) {
104+ }
105+
106+ @ Test
107+ void beanOutputParserRecords () {
108+
109+ BeanOutputParser <ActorsFilmsRecord > outputParser = new BeanOutputParser <>(ActorsFilmsRecord .class );
110+
111+ String format = outputParser .getFormat ();
112+ String template = """
113+ Generate the filmography of 5 movies for Tom Hanks.
114+ {format}
115+ """ ;
116+ PromptTemplate promptTemplate = new PromptTemplate (template , Map .of ("format" , format ));
117+ Prompt prompt = new Prompt (promptTemplate .createMessage ());
118+ Generation generation = openAiClient .generate (prompt ).getGeneration ();
119+
120+ ActorsFilmsRecord actorsFilms = outputParser .parse (generation .getText ());
121+ System .out .println (actorsFilms );
122+ assertThat (actorsFilms .actor ()).isEqualTo ("Tom Hanks" );
123+ assertThat (actorsFilms .movies ()).hasSize (5 );
124+ }
125+
103126}
You can’t perform that action at this time.
0 commit comments