feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import dotenv from "dotenv";
|
||||
import readline from "readline";
|
||||
import { createAgent } from "./agent.js";
|
||||
import { addDocument } from "./vectorstore.js";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const COLLECTION = "faq_collection";
|
||||
|
||||
async function main() {
|
||||
// Optional: add some sample documents
|
||||
await addDocument(
|
||||
COLLECTION,
|
||||
"What is the return policy?",
|
||||
{ source: "FAQ" }
|
||||
);
|
||||
await addDocument(
|
||||
COLLECTION,
|
||||
"How can I track my order?",
|
||||
{ source: "FAQ" }
|
||||
);
|
||||
|
||||
const agent = await createAgent(COLLECTION);
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
prompt: "You: ",
|
||||
});
|
||||
|
||||
console.log("FAQ Bot is ready. Type your question and press Enter.");
|
||||
rl.prompt();
|
||||
|
||||
rl.on("line", async (line) => {
|
||||
const question = line.trim();
|
||||
if (!question) {
|
||||
rl.prompt();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await agent.call({ input: question });
|
||||
console.log(`Bot: ${result.output}`);
|
||||
} catch (err) {
|
||||
console.error("Error:", err);
|
||||
}
|
||||
rl.prompt();
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((err) => console.error(err));
|
||||
Reference in New Issue
Block a user