From 057ee146bd7bc93889c0f882ef6c11f274fc8804 Mon Sep 17 00:00:00 2001
From: Thuc Pham <51660321+thucpn@users.noreply.github.com>
Date: Sat, 21 Dec 2024 14:55:33 +0700
Subject: [PATCH] fix: add start command for stackblitz (#1577)

---
 examples/package.json |  3 ++-
 examples/starter.ts   | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/examples/package.json b/examples/package.json
index d044cb724..e0bf64435 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -33,7 +33,8 @@
     "typescript": "^5.7.2"
   },
   "scripts": {
-    "lint": "eslint ."
+    "lint": "eslint .",
+    "start": "tsx ./starter.ts"
   },
   "stackblitz": {
     "startCommand": "npm start"
diff --git a/examples/starter.ts b/examples/starter.ts
index 371575a9a..e73e8dee8 100644
--- a/examples/starter.ts
+++ b/examples/starter.ts
@@ -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({
-- 
GitLab