Skip to content
Snippets Groups Projects
Unverified Commit 3c479100 authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

fix: groq llm (#947)

parent 8f16a179
No related branches found
No related tags found
No related merge requests found
---
"llamaindex": patch
---
fix: groq llm
...@@ -35,4 +35,4 @@ async function main() { ...@@ -35,4 +35,4 @@ async function main() {
console.log(response.response); console.log(response.response);
} }
await main(); main().catch(console.error);
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"dependencies": { "dependencies": {
"ai": "^3.2.1", "ai": "^3.2.1",
"llamaindex": "workspace:*", "llamaindex": "workspace:*",
"next": "14.2.3", "next": "14.2.4",
"react": "18.3.1", "react": "18.3.1",
"react-dom": "18.3.1" "react-dom": "18.3.1"
}, },
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
"dependencies": { "dependencies": {
"llamaindex": "workspace:*", "llamaindex": "workspace:*",
"next": "14.2.3", "next": "14.2.4",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1"
}, },
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
"assemblyai": "^4.4.5", "assemblyai": "^4.4.5",
"chromadb": "1.8.1", "chromadb": "1.8.1",
"cohere-ai": "7.9.5", "cohere-ai": "7.9.5",
"groq-sdk": "^0.5.0",
"js-tiktoken": "^1.0.12", "js-tiktoken": "^1.0.12",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"magic-bytes.js": "^1.10.0", "magic-bytes.js": "^1.10.0",
......
import { getEnv } from "@llamaindex/env"; import { getEnv } from "@llamaindex/env";
import GroqSDK, { type ClientOptions } from "groq-sdk";
import { OpenAI } from "./openai.js"; import { OpenAI } from "./openai.js";
export class Groq extends OpenAI { export class Groq extends OpenAI {
constructor(init?: Partial<OpenAI>) { constructor(
init?: Partial<OpenAI> & {
additionalSessionOptions?: ClientOptions;
},
) {
const { const {
apiKey = getEnv("GROQ_API_KEY"), apiKey = getEnv("GROQ_API_KEY"),
additionalSessionOptions = {}, additionalSessionOptions = {},
...@@ -10,18 +15,16 @@ export class Groq extends OpenAI { ...@@ -10,18 +15,16 @@ export class Groq extends OpenAI {
...rest ...rest
} = init ?? {}; } = init ?? {};
if (!apiKey) {
throw new Error("Set Groq Key in GROQ_API_KEY env variable"); // Tell user to set correct env variable, and not OPENAI_API_KEY
}
additionalSessionOptions.baseURL =
additionalSessionOptions.baseURL ?? "https://api.groq.com/openai/v1";
super({ super({
apiKey, apiKey,
additionalSessionOptions, additionalSessionOptions,
model, model,
...rest, ...rest,
}); });
this.session.openai = new GroqSDK({
apiKey,
...init?.additionalSessionOptions,
}) as any;
} }
} }
...@@ -43,7 +43,7 @@ import type { ...@@ -43,7 +43,7 @@ import type {
import { extractText, wrapLLMEvent } from "./utils.js"; import { extractText, wrapLLMEvent } from "./utils.js";
export class OpenAISession { export class OpenAISession {
openai: OrigOpenAI; openai: Pick<OrigOpenAI, "chat" | "embeddings">;
constructor(options: ClientOptions & { azure?: boolean } = {}) { constructor(options: ClientOptions & { azure?: boolean } = {}) {
if (options.azure) { if (options.azure) {
......
...@@ -29,6 +29,7 @@ export default function withLlamaIndex(config: any) { ...@@ -29,6 +29,7 @@ export default function withLlamaIndex(config: any) {
sharp$: false, sharp$: false,
"onnxruntime-node$": false, "onnxruntime-node$": false,
"@google-cloud/vertexai": false, "@google-cloud/vertexai": false,
"groq-sdk": false,
}; };
return webpackConfig; return webpackConfig;
}; };
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment