You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an analogy to make between GenerationTemplate and JdbcTemplate that will help simplify the use of the lower level classes such as AiClient, Prompts, and OutputParsers. Note: AiClient should likely be renamed GenerationClient as it is focused on generation, specifcally text, so perhaps even TextGenerationClient as we haven't yet experimented with multi-modal apis.
DataSource <-> AiClient
String Query with placeholdres <-> Prompt with placeholders
RowMapper <-> OutputParser
The simplest method (which is a default method in AiClient) is string input and string output, that could be removed from the AiClient interface and used in GenerateTemplate instead. Here are a few sample signatures for consideration.
ActorsFilms actorsFilms = generateTemplate.generate("Generate the filmography for the actor {actor}",
ActorsFilms.class, Map.of("actor", "Tom Hanks"));
Simple "chains" for flows can be done with standard Java functional programming, and we can see how our needs for a "chain" or a "flow" evolve over time. e.g. the example of a chain from langchain using functional programming
@Test
void functionalChains() {
Function<String, String> combinedFunction = generateSynopsis.andThen(generateReview);
System.out.println(combinedFunction.apply("Tragedy at sunset on the beach"));
}
private Function<String, String> generateSynopsis = title -> {
String synopsisInput = """
You are a playwright. Given the title of play, it is your job to write a synopsis for that title.
Title: {title}
Playwright: This is a synopsis for the above play:""";
return generateTemplate.generate(synopsisInput, Map.of("title", title));
};
private Function<String, String> generateReview = synopsis -> {
String synopsisInput = """
You are a play critic from the New York Times. Given the synopsis of play, it is your job to write a review for that play.
Play Synopsis:
{synopsis}
Review from a New York Times play critic of the above play:""";
return generateTemplate.generate(synopsisInput, Map.of("synopsis", synopsis));
};
The text was updated successfully, but these errors were encountered:
markpollack
changed the title
Create GenerateTemplate that streamlines usage of AiClient, Prompts, and OutputParsers
Create GenerativeTextTemplate that streamlines usage of AiClient, Prompts, and OutputParsers
Dec 4, 2023
There is an analogy to make between GenerationTemplate and JdbcTemplate that will help simplify the use of the lower level classes such as AiClient, Prompts, and OutputParsers. Note: AiClient should likely be renamed GenerationClient as it is focused on generation, specifcally text, so perhaps even TextGenerationClient as we haven't yet experimented with multi-modal apis.
The simplest method (which is a default method in AiClient) is string input and string output, that could be removed from the AiClient interface and used in GenerateTemplate instead. Here are a few sample signatures for consideration.
Example usage
Simple "chains" for flows can be done with standard Java functional programming, and we can see how our needs for a "chain" or a "flow" evolve over time. e.g. the example of a chain from langchain using functional programming
The text was updated successfully, but these errors were encountered: