mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-20 02:53:50 -04:00
refactor: move groq as llm package (#1209)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
"@llamaindex/groq": patch
|
||||
---
|
||||
|
||||
refactor: move groq as llm package
|
||||
@@ -145,6 +145,9 @@ jobs:
|
||||
- name: Pack @llamaindex/openai
|
||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
||||
working-directory: packages/llm/openai
|
||||
- name: Pack @llamaindex/groq
|
||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
||||
working-directory: packages/llm/groq
|
||||
- name: Pack @llamaindex/core
|
||||
run: pnpm pack --pack-destination ${{ runner.temp }}
|
||||
working-directory: packages/core
|
||||
|
||||
+12
-1
@@ -1,12 +1,23 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import { Document, Groq, Settings, VectorStoreIndex } from "llamaindex";
|
||||
import {
|
||||
Document,
|
||||
Groq,
|
||||
HuggingFaceEmbedding,
|
||||
Settings,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
// Update llm to use Groq
|
||||
Settings.llm = new Groq({
|
||||
apiKey: process.env.GROQ_API_KEY,
|
||||
});
|
||||
|
||||
// Use HuggingFace for embeddings
|
||||
Settings.embedModel = new HuggingFaceEmbedding({
|
||||
modelType: "Xenova/all-mpnet-base-v2",
|
||||
});
|
||||
|
||||
async function main() {
|
||||
// Load essay from abramov.txt in Node
|
||||
const path = "node_modules/llamaindex/examples/abramov.txt";
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"@llamaindex/groq": "workspace:*",
|
||||
"@mistralai/mistralai": "^1.0.4",
|
||||
"@mixedbread-ai/sdk": "^2.2.11",
|
||||
"@pinecone-database/pinecone": "^3.0.2",
|
||||
|
||||
@@ -1,30 +1 @@
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import GroqSDK, { type ClientOptions } from "groq-sdk";
|
||||
|
||||
export class Groq extends OpenAI {
|
||||
constructor(
|
||||
init?: Partial<OpenAI> & {
|
||||
additionalSessionOptions?: ClientOptions;
|
||||
},
|
||||
) {
|
||||
const {
|
||||
apiKey = getEnv("GROQ_API_KEY"),
|
||||
additionalSessionOptions = {},
|
||||
model = "mixtral-8x7b-32768",
|
||||
...rest
|
||||
} = init ?? {};
|
||||
|
||||
super({
|
||||
apiKey,
|
||||
additionalSessionOptions,
|
||||
model,
|
||||
...rest,
|
||||
});
|
||||
|
||||
this.session.openai = new GroqSDK({
|
||||
apiKey,
|
||||
...init?.additionalSessionOptions,
|
||||
}) as any;
|
||||
}
|
||||
}
|
||||
export * from "@llamaindex/groq";
|
||||
|
||||
@@ -11,7 +11,7 @@ export {
|
||||
GEMINI_MODEL,
|
||||
type GoogleGeminiSessionOptions,
|
||||
} from "./gemini/types.js";
|
||||
export { Groq } from "./groq.js";
|
||||
export * from "./groq.js";
|
||||
export { HuggingFaceInferenceAPI, HuggingFaceLLM } from "./huggingface.js";
|
||||
export {
|
||||
ALL_AVAILABLE_MISTRAL_MODELS,
|
||||
|
||||
@@ -37,7 +37,6 @@ export default function withLlamaIndex(config: any) {
|
||||
webpackConfig.resolve.alias = {
|
||||
...webpackConfig.resolve.alias,
|
||||
"@google-cloud/vertexai": false,
|
||||
"groq-sdk": false,
|
||||
};
|
||||
// Following lines will fix issues with onnxruntime-node when using pnpm
|
||||
// See: https://github.com/vercel/next.js/issues/43433
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# @llamaindex/groq
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "@llamaindex/groq",
|
||||
"description": "Groq Adapter for LlamaIndex",
|
||||
"version": "0.0.1",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./dist/index.d.cts",
|
||||
"default": "./dist/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/run-llama/LlamaIndexTS.git",
|
||||
"directory": "packages/llm/groq"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bunchee",
|
||||
"dev": "bunchee --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bunchee": "5.3.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"@llamaindex/openai": "workspace:*",
|
||||
"groq-sdk": "0.6.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { Groq } from "./llm";
|
||||
@@ -0,0 +1,30 @@
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import GroqSDK, { type ClientOptions } from "groq-sdk";
|
||||
|
||||
export class Groq extends OpenAI {
|
||||
constructor(
|
||||
init?: Partial<OpenAI> & {
|
||||
additionalSessionOptions?: ClientOptions;
|
||||
},
|
||||
) {
|
||||
const {
|
||||
apiKey = getEnv("GROQ_API_KEY"),
|
||||
additionalSessionOptions = {},
|
||||
model = "mixtral-8x7b-32768",
|
||||
...rest
|
||||
} = init ?? {};
|
||||
|
||||
super({
|
||||
apiKey,
|
||||
additionalSessionOptions,
|
||||
model,
|
||||
...rest,
|
||||
});
|
||||
|
||||
this.session.openai = new GroqSDK({
|
||||
apiKey,
|
||||
...init?.additionalSessionOptions,
|
||||
}) as any;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"outDir": "./lib"
|
||||
},
|
||||
"include": ["./src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../env/tsconfig.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
+19
@@ -522,6 +522,9 @@ importers:
|
||||
'@llamaindex/env':
|
||||
specifier: workspace:*
|
||||
version: link:../env
|
||||
'@llamaindex/groq':
|
||||
specifier: workspace:*
|
||||
version: link:../llm/groq
|
||||
'@llamaindex/openai':
|
||||
specifier: workspace:*
|
||||
version: link:../llm/openai
|
||||
@@ -859,6 +862,22 @@ importers:
|
||||
specifier: ^2.0.5
|
||||
version: 2.1.1(@edge-runtime/vm@4.0.3)(@types/node@22.5.4)(happy-dom@15.7.4)(terser@5.32.0)
|
||||
|
||||
packages/llm/groq:
|
||||
dependencies:
|
||||
'@llamaindex/env':
|
||||
specifier: workspace:*
|
||||
version: link:../../env
|
||||
'@llamaindex/openai':
|
||||
specifier: workspace:*
|
||||
version: link:../openai
|
||||
groq-sdk:
|
||||
specifier: 0.6.1
|
||||
version: 0.6.1(encoding@0.1.13)
|
||||
devDependencies:
|
||||
bunchee:
|
||||
specifier: 5.3.2
|
||||
version: 5.3.2(typescript@5.6.2)
|
||||
|
||||
packages/llm/openai:
|
||||
dependencies:
|
||||
'@llamaindex/core':
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
{
|
||||
"path": "./packages/llm/openai/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./packages/llm/groq/tsconfig.json"
|
||||
},
|
||||
{
|
||||
"path": "./packages/cloud/tsconfig.json"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user