mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-22 15:25:31 -04:00
30 lines
1016 B
TypeScript
30 lines
1016 B
TypeScript
import { Document, VectorStoreIndex } from "llamaindex";
|
|
import fs from "node:fs/promises";
|
|
import { createInterface } from "node:readline/promises";
|
|
|
|
async function main() {
|
|
const path = "node_modules/llamaindex/examples/abramov.txt";
|
|
const essay = await fs.readFile(path, "utf-8");
|
|
const document = new Document({ text: essay, id_: path });
|
|
|
|
const index = await VectorStoreIndex.fromDocuments([document]);
|
|
const queryEngine = index.asQueryEngine();
|
|
|
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
|
|
console.log(
|
|
"Try asking a question about the essay: https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/examples/abramov.txt",
|
|
"\nExample: When did the author graduate from high school?",
|
|
"\n==============================\n",
|
|
);
|
|
while (true) {
|
|
const query = await rl.question("Query: ");
|
|
const response = await queryEngine.query({
|
|
query,
|
|
});
|
|
console.log(response.toString());
|
|
}
|
|
}
|
|
|
|
main().catch(console.error);
|