Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add start command for stackblitz #1577

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"typescript": "^5.7.2"
},
"scripts": {
"lint": "eslint ."
"lint": "eslint .",
"start": "tsx ./starter.ts"
},
"stackblitz": {
"startCommand": "npm start"
Expand Down
16 changes: 11 additions & 5 deletions examples/starter.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Loading