Back to packages list

Vals using langchain/tools

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?",
});
})();
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] });
})();
1
Next