Public
Script
Forked from webup/pipeSampleLLMTool
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { getModelBuilder } from "https://esm.town/v/webup/getModelBuilder?v=9";
import process from "node:process";
export const pipeSampleLLMTool = (async () => {
const { SerpAPI } = await import("npm:langchain/tools");
const { PromptTemplate } = await import("npm:langchain/prompts");
const { StringOutputParser } = await import(
"npm:langchain/schema/output_parser"
);
const search = new SerpAPI(process.env.SERPAPI_KEY);
const prompt = PromptTemplate.fromTemplate(
`Turn the following user input into a search query for a search engine:
{input}`,
);
const builder = await getModelBuilder();
const model = await builder();
const chain = prompt.pipe(model).pipe(new StringOutputParser()).pipe(search);
return await chain.invoke({
input: "Who is the current prime minister of Malaysia?",
});
})();
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