-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
36 lines (28 loc) · 915 Bytes
/
index.js
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
29
30
31
32
33
34
35
36
import { ChatOpenAI } from "@langchain/openai";
import { PromptTemplate } from "@langchain/core/prompts";
import { RunnableSequence } from "@langchain/core/runnables";
import { StringOutputParser } from "@langchain/core/output_parsers";
import "dotenv/config";
const chatModel = new ChatOpenAI();
const prompt1 = PromptTemplate.fromTemplate(
"What town is {restaurant} restaurant in? Respond with the name of one town."
);
const prompt2 = PromptTemplate.fromTemplate(
"what country is the restaurant {restaurant} in? Respond in {language}."
);
const parser = new StringOutputParser();
const chain = prompt1.pipe(chatModel).pipe(parser);
const bigChain = RunnableSequence.from([
{
restaurant: chain,
language: (input) => input.language
},
prompt2,
chatModel,
parser
]);
const response = await bigChain.invoke({
restaurant: "Le Pigeon",
language: "French"
});
console.log(response);