1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { getModelBuilder } from "https://esm.town/v/webup/getModelBuilder";
export const parserSampleJSON = (async () => {
const { PromptTemplate } = await import("npm:langchain/prompts");
const { StructuredOutputParser } = await import(
"npm:langchain/output_parsers"
);
// With a `StructuredOutputParser` we can define a schema for the output.
const parser = StructuredOutputParser.fromNamesAndDescriptions({
answer: "answer to the user's question",
source: "source used to answer the user's question, should be a website.",
});
const formatInstructions = parser.getFormatInstructions();
const prompt = new PromptTemplate({
template:
"Answer the users question as best as possible.\n{format_instructions}\n{question}",
inputVariables: ["question"],
partialVariables: { format_instructions: formatInstructions },
});
const builder = await getModelBuilder();
const model = await builder();
const input = await prompt.format({
question: "What is the capital of France?",
});
const response = await model.call(input);
console.log(input);
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!
September 3, 2024