import { baserun } from "baserun";
import fs from "node:fs/promises";
import {VectorStoreIndex, Document} from "llamaindex";
async function llama() {
// load documents
const dir = "recipes"
const documents: Document[] = []
for (const path of await fs.readdir(dir)) {
const recipe = await fs.readFile(dir + "/" + path, "utf-8");
const document = new Document({ text: recipe, id_: path });
documents.push(document)
}
// create index
const index = await VectorStoreIndex.fromDocuments(documents);
// make a query
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
query: "I have flour, sugar and butter. What am I missing if I want to bake oatmeal cookies?",
});
console.log(response.toString());
}
async function main() {
await baserun.init();
await baserun.trace(async () => {
await llama();
})();
}
main();