-
Notifications
You must be signed in to change notification settings - Fork 5
/
01_first_chain.js
39 lines (27 loc) · 974 Bytes
/
01_first_chain.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
37
38
/*
PromptTemplate + LLM = 🔗
⬇
invoke
= input variable(s) ⮕ prompt template ⮕ prompt ⮕ model ⮕ result
*/
import { config } from "dotenv";
config();
import { ChatOpenAI } from "@langchain/openai";
import { PromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
const model = new ChatOpenAI({
modelName: "gpt-3.5-turbo",
temperature: 0
});
const joke = await model.invoke(
"Tell me a Harry Potter joke."
);
const promptTemplate = PromptTemplate.fromTemplate(
"Be very funny when answering questions\nQuestion: {question}"
);
const outputParser = new StringOutputParser();
const chain = promptTemplate.pipe(model).pipe(outputParser);
const result = await chain.invoke({
question: "Who wrote the 'Harry Potter' series book? What's the real name? Why choose that name?",
});
console.log(result);