Find answers from the community

Updated 2 months ago

I want to use llama to create an AI

I want to use llama to create an AI chatbot for PDFs. I've tried to start with the documentation example but nothing.. i've understand how llama works but it cause openaiapikey error..how can i solve this?
i've copied this
// example.ts
import fs from "fs/promises";
import { Document, VectorStoreIndex } from "llamaindex";

async function main() {
// Load essay from abramov.txt in Node
const essay = await fs.readFile(
"node_modules/llamaindex/examples/abramov.txt",
"utf-8"
);

// Create Document object with essay
const document = new Document({ text: essay });

// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.fromDocuments([document]);

// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
);

// Output response
console.log(response.toString());
}

main();
AND THIS IS THE PROBLEM AuthenticationError: Incorrect API key provided: sk-pgr1k***NI0x.
right
what does it means?
export OPENAI_API_KEY="sk-......" # Replace with your key from https://platform.openai.com/account/api-keys
OpenAI Platform
Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.
where i have to put my OPENAI_API_KEY??
Please, if you can, help me
R
L
5 comments
Export are basically a non windows thing, for windows you can basically run it on command line or set it via the ui
this is the way to set it temporarily
Attachment
image.png
but if you are doing javascript/typescript thing, i really recomend you setting it on .env file and use loadenv to load it via code (https://www.npmjs.com/package/loadenv)
Sadly I can't really advice you much further, since I am mainly using llamaindex with python rather then javascript though πŸ˜…
You can also set the key manually in python. Not very secure though

Plain Text
import os
import openai

os.environ["OPENAI_API_KEY"] = "..."
openai.api_key = os.environ["OPENAI_API_KEY"]
Add a reply
Sign up and join the conversation on Discord