Public
Script
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
23
24
25
import { getLangSmithBuilder } from "https://esm.town/v/webup/getLangSmithBuilder";
import { getModelBuilder } from "https://esm.town/v/webup/getModelBuilder";
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.SERP);
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 tb = await getLangSmithBuilder();
const tracer = await tb();
const chain = prompt.pipe(model).pipe(new StringOutputParser()).pipe(search);
return await chain.invoke({
input: "Who is the current prime minister of Malaysia?",
}, { callbacks: [tracer] });
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
October 23, 2023
Sweet!