-
Notifications
You must be signed in to change notification settings - Fork 2
/
runBot.js
32 lines (27 loc) · 1014 Bytes
/
runBot.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
import dotenv from "dotenv";
import { ChatOpenAI } from "@langchain/openai";
import { createStuffDocumentsChain } from "langchain/chains/combine_documents";
import createPrompt from "./llmBot/prompUtility.js";
import generateContextRetreiver from "./llmBot/contextRetreiver.js";
dotenv.config();
const llm = new ChatOpenAI({ model: "gpt-4o" });
const prompt = await createPrompt();
const ragChain = await createStuffDocumentsChain({llm,prompt});
const retriever = await generateContextRetreiver();
try {
const USER_QUESTION = `
How Amazon overcome the fact that many physical stores were closed during the pandemic ?
`;
const retrievedChunks = await retriever.invoke(USER_QUESTION);
const response = await ragChain.invoke({
question: USER_QUESTION.trim(),
context: retrievedChunks,
});
console.log(response);
for (const doc of retrievedChunks) {
const src = doc.metadata.source;
console.log(src);
}
} catch (e) {
console.log(e);
}