Skip to content

Commit

Permalink
Added Record test for output parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp authored and markpollack committed Sep 27, 2023
1 parent a6fba7a commit 6554bde
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,27 @@ void beanOutputParser() {
System.out.println(actorsFilms);
}

record ActorsFilmsRecord(String actor, List<String> movies) {
}

@Test
void beanOutputParserRecords() {

BeanOutputParser<ActorsFilmsRecord> outputParser = new BeanOutputParser<>(ActorsFilmsRecord.class);

String format = outputParser.getFormat();
String template = """
Generate the filmography of 5 movies for Tom Hanks.
{format}
""";
PromptTemplate promptTemplate = new PromptTemplate(template, Map.of("format", format));
Prompt prompt = new Prompt(promptTemplate.createMessage());
Generation generation = openAiClient.generate(prompt).getGeneration();

ActorsFilmsRecord actorsFilms = outputParser.parse(generation.getText());
System.out.println(actorsFilms);
assertThat(actorsFilms.actor()).isEqualTo("Tom Hanks");
assertThat(actorsFilms.movies()).hasSize(5);
}

}

0 comments on commit 6554bde

Please sign in to comment.