diff --git a/examples/together-ai/vector-index.ts b/examples/together-ai/vector-index.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc460ca81d42c45087b306a75897d1685a865ab2 --- /dev/null +++ b/examples/together-ai/vector-index.ts @@ -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); diff --git a/packages/core/package.json b/packages/core/package.json index a80c0081dd2affb48c849e9884fe1bffedd93fda..f3f00897221e8d3e63c9956141b8aabcbbf450a5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -49,7 +49,8 @@ "types": "./dist/index.d.mts", "import": "./dist/index.mjs", "require": "./dist/index.js" - } + }, + "./examples/*": "./examples/*" }, "files": [ "dist",