Compare commits

...

1 Commits

Author SHA1 Message Date
Alex Yang 01e6daefff feat: add together AI vector index example 2024-01-15 16:48:30 -06:00
2 changed files with 41 additions and 1 deletions
+39
View File
@@ -0,0 +1,39 @@
import fs from "node:fs/promises";
import {
Document,
TogetherEmbedding,
TogetherLLM,
VectorStoreIndex,
serviceContextFromDefaults,
} from "llamaindex";
async function main() {
const apiKey = process.env.TOGETHER_API_KEY;
if (!apiKey) {
throw new Error("Missing TOGETHER_API_KEY");
}
const path = require.resolve("llamaindex/examples/abramov.txt");
const essay = await fs.readFile(path, "utf-8");
const document = new Document({ text: essay, id_: path });
const serviceContext = serviceContextFromDefaults({
llm: new TogetherLLM({ model: "mistralai/Mixtral-8x7B-Instruct-v0.1" }),
embedModel: new TogetherEmbedding(),
});
const index = await VectorStoreIndex.fromDocuments([document], {
serviceContext,
});
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?",
);
console.log(response.toString());
}
main().catch(console.error);
+2 -1
View File
@@ -49,7 +49,8 @@
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"./examples/*": "./examples/*"
},
"files": [
"dist",