Groq
Installation
Section titled “Installation”npm i llamaindex @llamaindex/groq
First, create an API key at the Groq Console. Then save it in your environment:
export GROQ_API_KEY=<your-api-key>
The initialize the Groq module.
import { Groq } from "@llamaindex/groq";import { Settings } from "llamaindex";
Settings.llm = new Groq({ // If you do not wish to set your API key in the environment, you may // configure your API key when you initialize the Groq class. // apiKey: "<your-api-key>",});
Load and index documents
Section titled “Load and index documents”For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.
import { Document, VectorStoreIndex } from "llamaindex";
const document = new Document({ text: essay, id_: "essay" });
const index = await VectorStoreIndex.fromDocuments([document]);
const queryEngine = index.asQueryEngine();
const query = "What is the meaning of life?";
const results = await queryEngine.query({ query,});