1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { getModelBuilder } from "https://esm.town/v/webup/getModelBuilder";
export const parserSampleListCustom = (async () => {
const { PromptTemplate } = await import("npm:langchain/prompts");
const { CustomListOutputParser } = await import(
"npm:langchain/output_parsers"
);
// With a `CustomListOutputParser`, we can parse a list with a specific length and separator.
const parser = new CustomListOutputParser({ length: 3, separator: "\n" });
const formatInstructions = parser.getFormatInstructions();
const prompt = new PromptTemplate({
template: "Provide a list of {subject}.\n{format_instructions}",
inputVariables: ["subject"],
partialVariables: { format_instructions: formatInstructions },
});
const builder = await getModelBuilder();
const model = await builder();
const input = await prompt.format({
subject: "great fiction books (book, author)",
});
const response = await model.call(input);
console.log(response);
return await parser.parse(response);
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023