Skip to content
Snippets Groups Projects
Unverified Commit d1db2189 authored by Marcus Schiesser's avatar Marcus Schiesser Committed by GitHub
Browse files

docs: update starter to ask for api key (#1661)

parent 2c5b4030
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,18 @@ import fs from "node:fs/promises"; ...@@ -3,6 +3,18 @@ import fs from "node:fs/promises";
import { createInterface } from "node:readline/promises"; import { createInterface } from "node:readline/promises";
async function main() { async function main() {
const rl = createInterface({ input: process.stdin, output: process.stdout });
if (!process.env.OPENAI_API_KEY) {
console.log("OpenAI API key not found in environment variables.");
console.log(
"You can get an API key at https://platform.openai.com/account/api-keys",
);
process.env.OPENAI_API_KEY = await rl.question(
"Please enter your OpenAI API key: ",
);
}
const path = "node_modules/llamaindex/examples/abramov.txt"; const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8"); const essay = await fs.readFile(path, "utf-8");
const document = new Document({ text: essay, id_: path }); const document = new Document({ text: essay, id_: path });
...@@ -10,8 +22,6 @@ async function main() { ...@@ -10,8 +22,6 @@ async function main() {
const index = await VectorStoreIndex.fromDocuments([document]); const index = await VectorStoreIndex.fromDocuments([document]);
const queryEngine = index.asQueryEngine(); const queryEngine = index.asQueryEngine();
const rl = createInterface({ input: process.stdin, output: process.stdout });
console.log( console.log(
"Try asking a question about the essay: https://github.com/run-llama/LlamaIndexTS/blob/main/packages/llamaindex/examples/abramov.txt", "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?", "\nExample: When did the author graduate from high school?",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment