1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { getLangSmithBuilder } from "https://esm.town/v/webup/getLangSmithBuilder";
import { getModelBuilder } from "https://esm.town/v/webup/getModelBuilder";
export const pipeSampleLLM = (async () => {
const { PromptTemplate } = await import("npm:langchain/prompts");
const { RunnableSequence } = await import("npm:langchain/schema/runnable");
const { StringOutputParser } = await import(
"npm:langchain/schema/output_parser"
);
const builder = await getModelBuilder();
const model = await builder();
const promptTemplate = PromptTemplate.fromTemplate(
"Tell me a joke about {topic}",
);
const outputParser = new StringOutputParser();
const tb = await getLangSmithBuilder();
const tracer = await tb();
const chain = RunnableSequence.from([promptTemplate, model, outputParser]);
const result = await chain.invoke({ topic: "bears" }, {
callbacks: [tracer],
});
return result;
})();
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!
v4
October 23, 2023