@memberjunction/ai-groq 2.32.2 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/groq.d.ts +24 -1
- package/dist/models/groq.d.ts.map +1 -1
- package/dist/models/groq.js +92 -1
- package/dist/models/groq.js.map +1 -1
- package/package.json +3 -3
- package/readme.md +149 -2
package/dist/models/groq.d.ts
CHANGED
|
@@ -14,7 +14,30 @@ export declare class GroqLLM extends BaseLLM {
|
|
|
14
14
|
* Read only getter method to get the Groq client instance
|
|
15
15
|
*/
|
|
16
16
|
get client(): Groq;
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Groq supports streaming
|
|
19
|
+
*/
|
|
20
|
+
get SupportsStreaming(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Implementation of non-streaming chat completion for Groq
|
|
23
|
+
*/
|
|
24
|
+
protected nonStreamingChatCompletion(params: ChatParams): Promise<ChatResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a streaming request for Groq
|
|
27
|
+
*/
|
|
28
|
+
protected createStreamingRequest(params: ChatParams): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Process a streaming chunk from Groq
|
|
31
|
+
*/
|
|
32
|
+
protected processStreamingChunk(chunk: any): {
|
|
33
|
+
content: string;
|
|
34
|
+
finishReason?: string;
|
|
35
|
+
usage?: any;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Create the final response from streaming results for Groq
|
|
39
|
+
*/
|
|
40
|
+
protected finalizeStreamingResponse(accumulatedContent: string | null | undefined, lastChunk: any | null | undefined, usage: any | null | undefined): ChatResult;
|
|
18
41
|
SummarizeText(params: SummarizeParams): Promise<SummarizeResult>;
|
|
19
42
|
ClassifyText(params: ClassifyParams): Promise<ClassifyResult>;
|
|
20
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groq.d.ts","sourceRoot":"","sources":["../../src/models/groq.ts"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MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;CAG7E;AAED,wBAAgB,WAAW,SAE1B"}
|
package/dist/models/groq.js
CHANGED
|
@@ -33,7 +33,16 @@ let GroqLLM = class GroqLLM extends ai_1.BaseLLM {
|
|
|
33
33
|
get client() {
|
|
34
34
|
return this.GroqClient;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Groq supports streaming
|
|
38
|
+
*/
|
|
39
|
+
get SupportsStreaming() {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Implementation of non-streaming chat completion for Groq
|
|
44
|
+
*/
|
|
45
|
+
async nonStreamingChatCompletion(params) {
|
|
37
46
|
const startTime = new Date();
|
|
38
47
|
const groqParams = {
|
|
39
48
|
model: params.model,
|
|
@@ -84,6 +93,88 @@ let GroqLLM = class GroqLLM extends ai_1.BaseLLM {
|
|
|
84
93
|
exception: null,
|
|
85
94
|
};
|
|
86
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Create a streaming request for Groq
|
|
98
|
+
*/
|
|
99
|
+
async createStreamingRequest(params) {
|
|
100
|
+
const groqParams = {
|
|
101
|
+
model: params.model,
|
|
102
|
+
messages: params.messages,
|
|
103
|
+
max_tokens: params.maxOutputTokens,
|
|
104
|
+
temperature: params.temperature,
|
|
105
|
+
stream: true
|
|
106
|
+
};
|
|
107
|
+
// Set response format if specified
|
|
108
|
+
switch (params.responseFormat) {
|
|
109
|
+
case 'JSON':
|
|
110
|
+
groqParams.response_format = { type: "json_object" };
|
|
111
|
+
break;
|
|
112
|
+
case 'ModelSpecific':
|
|
113
|
+
groqParams.response_format = params.modelSpecificResponseFormat;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
return this.client.chat.completions.create(groqParams);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Process a streaming chunk from Groq
|
|
120
|
+
*/
|
|
121
|
+
processStreamingChunk(chunk) {
|
|
122
|
+
let content = '';
|
|
123
|
+
let finishReason = undefined;
|
|
124
|
+
if (chunk?.choices && chunk.choices.length > 0) {
|
|
125
|
+
const choice = chunk.choices[0];
|
|
126
|
+
if (choice?.delta?.content) {
|
|
127
|
+
content = choice.delta.content;
|
|
128
|
+
}
|
|
129
|
+
if (choice?.finish_reason) {
|
|
130
|
+
finishReason = choice.finish_reason;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Groq doesn't provide usage in streaming chunks
|
|
134
|
+
return {
|
|
135
|
+
content,
|
|
136
|
+
finishReason,
|
|
137
|
+
usage: null
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create the final response from streaming results for Groq
|
|
142
|
+
*/
|
|
143
|
+
finalizeStreamingResponse(accumulatedContent, lastChunk, usage) {
|
|
144
|
+
// Extract finish reason from last chunk if available
|
|
145
|
+
let finishReason = 'stop';
|
|
146
|
+
if (lastChunk?.choices && lastChunk.choices.length > 0 && lastChunk.choices[0].finish_reason) {
|
|
147
|
+
finishReason = lastChunk.choices[0].finish_reason;
|
|
148
|
+
}
|
|
149
|
+
// For Groq, we don't have precise usage metrics from streaming
|
|
150
|
+
// We'll use the accumulated ones or defaults
|
|
151
|
+
const promptTokens = usage?.promptTokens || 0;
|
|
152
|
+
const completionTokens = usage?.completionTokens || 0;
|
|
153
|
+
// Create dates (will be overridden by base class)
|
|
154
|
+
const now = new Date();
|
|
155
|
+
// Create a proper ChatResult instance with constructor params
|
|
156
|
+
const result = new ai_1.ChatResult(true, now, now);
|
|
157
|
+
// Set all properties
|
|
158
|
+
result.data = {
|
|
159
|
+
choices: [{
|
|
160
|
+
message: {
|
|
161
|
+
role: 'assistant',
|
|
162
|
+
content: accumulatedContent ? accumulatedContent : ''
|
|
163
|
+
},
|
|
164
|
+
finish_reason: finishReason,
|
|
165
|
+
index: 0
|
|
166
|
+
}],
|
|
167
|
+
usage: {
|
|
168
|
+
promptTokens,
|
|
169
|
+
completionTokens,
|
|
170
|
+
totalTokens: promptTokens + completionTokens
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
result.statusText = 'success';
|
|
174
|
+
result.errorMessage = null;
|
|
175
|
+
result.exception = null;
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
87
178
|
async SummarizeText(params) {
|
|
88
179
|
throw new Error("Method not implemented.");
|
|
89
180
|
}
|
package/dist/models/groq.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groq.js","sourceRoot":"","sources":["../../src/models/groq.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"groq.js","sourceRoot":"","sources":["../../src/models/groq.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiL;AACjL,mDAAuD;AACvD,wDAA4B;AAG5B;;GAEG;AAEI,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,YAAO;IAEhC,YAAY,MAAc;QACtB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,kBAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAoB,iBAAiB;QACjC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,0BAA0B,CAAC,MAAkB;QACzD,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAE7B,MAAM,UAAU,GAA2C;YACvD,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,UAAU,EAAE,MAAM,CAAC,eAAe;YAClC,WAAW,EAAE,MAAM,CAAC,WAA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CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,MAAuB;QAC9C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,MAAsB;QAC5C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CACJ,CAAA;AAvMY,0BAAO;kBAAP,OAAO;IADnB,IAAA,sBAAa,EAAC,YAAO,EAAE,SAAS,CAAC;GACrB,OAAO,CAuMnB;AAED,SAAgB,WAAW;IACvB,iFAAiF;AACrF,CAAC;AAFD,kCAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-groq",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.34.0",
|
|
4
4
|
"description": "MemberJunction Wrapper for Groq AI LPU inference engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"typescript": "^5.4.5"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@memberjunction/ai": "2.
|
|
23
|
-
"@memberjunction/global": "2.
|
|
22
|
+
"@memberjunction/ai": "2.34.0",
|
|
23
|
+
"@memberjunction/global": "2.34.0",
|
|
24
24
|
"groq-sdk": "0.15.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/readme.md
CHANGED
|
@@ -1,2 +1,149 @@
|
|
|
1
|
-
# @memberjunction/ai-
|
|
2
|
-
|
|
1
|
+
# @memberjunction/ai-groq
|
|
2
|
+
|
|
3
|
+
A comprehensive wrapper for Groq's LPU (Language Processing Unit) inference engine, providing high-performance AI model access within the MemberJunction framework.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **High-Performance Integration**: Connect to Groq's ultra-fast LPU inference API
|
|
8
|
+
- **Standardized Interface**: Implements MemberJunction's BaseLLM abstract class
|
|
9
|
+
- **Message Formatting**: Handles conversion between MemberJunction and Groq message formats
|
|
10
|
+
- **Error Handling**: Robust error handling with detailed reporting
|
|
11
|
+
- **Token Usage Tracking**: Track token consumption for monitoring
|
|
12
|
+
- **Chat Completion**: Interactive chat completions with various LLMs hosted on Groq
|
|
13
|
+
- **Model Support**: Compatible with LLama-2, Mixtral, and other models hosted on Groq
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @memberjunction/ai-groq
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Node.js 16+
|
|
24
|
+
- A Groq API key
|
|
25
|
+
- MemberJunction Core libraries
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Setup
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { GroqLLM } from '@memberjunction/ai-groq';
|
|
33
|
+
|
|
34
|
+
// Initialize with your Groq API key
|
|
35
|
+
const groqLLM = new GroqLLM('your-groq-api-key');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Chat Completion
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { ChatParams } from '@memberjunction/ai';
|
|
42
|
+
|
|
43
|
+
// Create chat parameters
|
|
44
|
+
const chatParams: ChatParams = {
|
|
45
|
+
model: 'llama2-70b-4096', // or other models like 'mixtral-8x7b-32768'
|
|
46
|
+
messages: [
|
|
47
|
+
{ role: 'system', content: 'You are a helpful AI assistant.' },
|
|
48
|
+
{ role: 'user', content: 'Explain how LPUs differ from traditional GPUs for AI inference.' }
|
|
49
|
+
],
|
|
50
|
+
temperature: 0.7,
|
|
51
|
+
maxOutputTokens: 1000
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Get a response
|
|
55
|
+
try {
|
|
56
|
+
const response = await groqLLM.ChatCompletion(chatParams);
|
|
57
|
+
if (response.success) {
|
|
58
|
+
console.log('Response:', response.data.choices[0].message.content);
|
|
59
|
+
console.log('Token Usage:', response.data.usage);
|
|
60
|
+
console.log('Time Elapsed (ms):', response.timeElapsed);
|
|
61
|
+
} else {
|
|
62
|
+
console.error('Error:', response.errorMessage);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error('Exception:', error);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Direct Access to Groq Client
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// Access the underlying Groq client for advanced usage
|
|
73
|
+
const groqClient = groqLLM.GroqClient;
|
|
74
|
+
|
|
75
|
+
// Use the client directly if needed
|
|
76
|
+
const customResponse = await groqClient.chat.completions.create({
|
|
77
|
+
model: 'mixtral-8x7b-32768',
|
|
78
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
79
|
+
max_tokens: 500
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Supported Models
|
|
84
|
+
|
|
85
|
+
Groq provides access to various open models with optimized inference:
|
|
86
|
+
|
|
87
|
+
- `llama2-70b-4096`
|
|
88
|
+
- `mixtral-8x7b-32768`
|
|
89
|
+
- `gemma-7b-it`
|
|
90
|
+
|
|
91
|
+
Check the [Groq documentation](https://console.groq.com/docs/models) for the latest list of supported models.
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### GroqLLM Class
|
|
96
|
+
|
|
97
|
+
A class that extends BaseLLM to provide Groq-specific functionality.
|
|
98
|
+
|
|
99
|
+
#### Constructor
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
new GroqLLM(apiKey: string)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Properties
|
|
106
|
+
|
|
107
|
+
- `GroqClient`: (read-only) Returns the underlying Groq client instance
|
|
108
|
+
|
|
109
|
+
#### Methods
|
|
110
|
+
|
|
111
|
+
- `ChatCompletion(params: ChatParams): Promise<ChatResult>` - Perform a chat completion
|
|
112
|
+
- `SummarizeText(params: SummarizeParams): Promise<SummarizeResult>` - Summarize text
|
|
113
|
+
- `ClassifyText(params: ClassifyParams): Promise<ClassifyResult>` - Classify text (not implemented)
|
|
114
|
+
- `ConvertMJToGroqChatMessages(messages: ChatMessage[]): any[]` - Convert MemberJunction messages to Groq format
|
|
115
|
+
|
|
116
|
+
## Performance Considerations
|
|
117
|
+
|
|
118
|
+
Groq is known for its extremely fast inference times:
|
|
119
|
+
|
|
120
|
+
- Response generation is typically 5-10x faster than traditional GPU-based inference
|
|
121
|
+
- Lower latency means better interactive experiences
|
|
122
|
+
- Benchmark different models to find the best performance/quality balance for your use case
|
|
123
|
+
|
|
124
|
+
## Error Handling
|
|
125
|
+
|
|
126
|
+
The wrapper provides detailed error information:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
try {
|
|
130
|
+
const response = await groqLLM.ChatCompletion(params);
|
|
131
|
+
if (!response.success) {
|
|
132
|
+
console.error('Error:', response.errorMessage);
|
|
133
|
+
console.error('Status:', response.statusText);
|
|
134
|
+
console.error('Time Elapsed:', response.timeElapsed, 'ms');
|
|
135
|
+
}
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error('Exception occurred:', error);
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Dependencies
|
|
142
|
+
|
|
143
|
+
- `groq-sdk`: Official Groq SDK
|
|
144
|
+
- `@memberjunction/ai`: MemberJunction AI core framework
|
|
145
|
+
- `@memberjunction/global`: MemberJunction global utilities
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
ISC
|