Compare commits

...

2 Commits

Author SHA1 Message Date
thucpn d751af3ba1 fix: use tsx 2024-12-20 17:15:41 +07:00
thucpn 6e0bf26566 fix: add start command for stackblitz 2024-12-20 17:11:32 +07:00
2 changed files with 13 additions and 6 deletions
+2 -1
View File
@@ -33,7 +33,8 @@
"typescript": "^5.7.2"
},
"scripts": {
"lint": "eslint ."
"lint": "eslint .",
"start": "tsx ./starter.ts"
},
"stackblitz": {
"startCommand": "npm start"
+11 -5
View File
@@ -1,16 +1,22 @@
import { SimpleDirectoryReader, VectorStoreIndex } from "llamaindex";
import { Document, VectorStoreIndex } from "llamaindex";
import fs from "node:fs/promises";
import { createInterface } from "node:readline/promises";
async function main() {
const reader = new SimpleDirectoryReader();
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 documents = await reader.loadData("./data");
const index = await VectorStoreIndex.fromDocuments(documents);
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({