@memberjunction/ai-groq 2.42.1 → 2.44.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/package.json +3 -3
- package/readme.md +137 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-groq",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.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.44.0",
|
|
23
|
+
"@memberjunction/global": "2.44.0",
|
|
24
24
|
"groq-sdk": "0.21.0"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/readme.md
CHANGED
|
@@ -6,11 +6,13 @@ A comprehensive wrapper for Groq's LPU (Language Processing Unit) inference engi
|
|
|
6
6
|
|
|
7
7
|
- **High-Performance Integration**: Connect to Groq's ultra-fast LPU inference API
|
|
8
8
|
- **Standardized Interface**: Implements MemberJunction's BaseLLM abstract class
|
|
9
|
+
- **Streaming Support**: Full support for streaming responses for real-time interactions
|
|
9
10
|
- **Message Formatting**: Handles conversion between MemberJunction and Groq message formats
|
|
10
11
|
- **Error Handling**: Robust error handling with detailed reporting
|
|
11
12
|
- **Token Usage Tracking**: Track token consumption for monitoring
|
|
12
13
|
- **Chat Completion**: Interactive chat completions with various LLMs hosted on Groq
|
|
13
|
-
- **Model Support**: Compatible with
|
|
14
|
+
- **Model Support**: Compatible with Llama, Mixtral, Gemma, and other models hosted on Groq
|
|
15
|
+
- **Response Format Control**: Support for JSON, text, and model-specific response formats
|
|
14
16
|
|
|
15
17
|
## Installation
|
|
16
18
|
|
|
@@ -66,11 +68,55 @@ try {
|
|
|
66
68
|
}
|
|
67
69
|
```
|
|
68
70
|
|
|
71
|
+
### Streaming Responses
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { ChatParams, ChatResult } from '@memberjunction/ai';
|
|
75
|
+
|
|
76
|
+
// Enable streaming in the chat parameters
|
|
77
|
+
const streamingParams: ChatParams = {
|
|
78
|
+
model: 'llama3-70b-8192',
|
|
79
|
+
messages: [
|
|
80
|
+
{ role: 'user', content: 'Write a short story about AI.' }
|
|
81
|
+
],
|
|
82
|
+
stream: true,
|
|
83
|
+
onStream: (content: string) => {
|
|
84
|
+
// Handle each chunk of streamed content
|
|
85
|
+
process.stdout.write(content);
|
|
86
|
+
},
|
|
87
|
+
maxOutputTokens: 2000
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// The response will stream to the onStream callback
|
|
91
|
+
const response = await groqLLM.ChatCompletion(streamingParams);
|
|
92
|
+
console.log('\n\nFinal response:', response.data.choices[0].message.content);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Response Format Control
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// Request JSON formatted response
|
|
99
|
+
const jsonParams: ChatParams = {
|
|
100
|
+
model: 'mixtral-8x7b-32768',
|
|
101
|
+
messages: [
|
|
102
|
+
{ role: 'system', content: 'You are a helpful assistant that responds in JSON format.' },
|
|
103
|
+
{ role: 'user', content: 'List 3 benefits of using Groq in JSON format with keys: benefit, description' }
|
|
104
|
+
],
|
|
105
|
+
responseFormat: 'JSON',
|
|
106
|
+
maxOutputTokens: 1000
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const jsonResponse = await groqLLM.ChatCompletion(jsonParams);
|
|
110
|
+
const benefits = JSON.parse(jsonResponse.data.choices[0].message.content);
|
|
111
|
+
```
|
|
112
|
+
|
|
69
113
|
### Direct Access to Groq Client
|
|
70
114
|
|
|
71
115
|
```typescript
|
|
72
116
|
// Access the underlying Groq client for advanced usage
|
|
73
117
|
const groqClient = groqLLM.GroqClient;
|
|
118
|
+
// or use the alias
|
|
119
|
+
const client = groqLLM.client;
|
|
74
120
|
|
|
75
121
|
// Use the client directly if needed
|
|
76
122
|
const customResponse = await groqClient.chat.completions.create({
|
|
@@ -84,11 +130,19 @@ const customResponse = await groqClient.chat.completions.create({
|
|
|
84
130
|
|
|
85
131
|
Groq provides access to various open models with optimized inference:
|
|
86
132
|
|
|
87
|
-
-
|
|
88
|
-
- `
|
|
89
|
-
- `
|
|
133
|
+
- **Llama Models**:
|
|
134
|
+
- `llama3-70b-8192` - Llama 3 70B with 8K context
|
|
135
|
+
- `llama3-8b-8192` - Llama 3 8B with 8K context
|
|
136
|
+
- `llama2-70b-4096` - Llama 2 70B with 4K context
|
|
137
|
+
|
|
138
|
+
- **Mixtral Models**:
|
|
139
|
+
- `mixtral-8x7b-32768` - Mixtral 8x7B with 32K context
|
|
140
|
+
|
|
141
|
+
- **Gemma Models**:
|
|
142
|
+
- `gemma-7b-it` - Gemma 7B Instruct
|
|
143
|
+
- `gemma2-9b-it` - Gemma 2 9B Instruct
|
|
90
144
|
|
|
91
|
-
Check the [Groq documentation](https://console.groq.com/docs/models) for the latest list of supported models.
|
|
145
|
+
Check the [Groq documentation](https://console.groq.com/docs/models) for the latest list of supported models and their capabilities.
|
|
92
146
|
|
|
93
147
|
## API Reference
|
|
94
148
|
|
|
@@ -105,13 +159,28 @@ new GroqLLM(apiKey: string)
|
|
|
105
159
|
#### Properties
|
|
106
160
|
|
|
107
161
|
- `GroqClient`: (read-only) Returns the underlying Groq client instance
|
|
162
|
+
- `client`: (read-only) Alias for GroqClient
|
|
163
|
+
- `SupportsStreaming`: (read-only) Returns `true` - Groq supports streaming responses
|
|
108
164
|
|
|
109
165
|
#### Methods
|
|
110
166
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
167
|
+
##### ChatCompletion
|
|
168
|
+
```typescript
|
|
169
|
+
ChatCompletion(params: ChatParams): Promise<ChatResult>
|
|
170
|
+
```
|
|
171
|
+
Perform a chat completion with support for both streaming and non-streaming responses.
|
|
172
|
+
|
|
173
|
+
##### SummarizeText
|
|
174
|
+
```typescript
|
|
175
|
+
SummarizeText(params: SummarizeParams): Promise<SummarizeResult>
|
|
176
|
+
```
|
|
177
|
+
*Note: Not yet implemented*
|
|
178
|
+
|
|
179
|
+
##### ClassifyText
|
|
180
|
+
```typescript
|
|
181
|
+
ClassifyText(params: ClassifyParams): Promise<ClassifyResult>
|
|
182
|
+
```
|
|
183
|
+
*Note: Not yet implemented*
|
|
115
184
|
|
|
116
185
|
## Performance Considerations
|
|
117
186
|
|
|
@@ -138,11 +207,67 @@ try {
|
|
|
138
207
|
}
|
|
139
208
|
```
|
|
140
209
|
|
|
210
|
+
## Integration with MemberJunction
|
|
211
|
+
|
|
212
|
+
This package seamlessly integrates with the MemberJunction AI framework:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
216
|
+
import { BaseLLM } from '@memberjunction/ai';
|
|
217
|
+
import { GroqLLM } from '@memberjunction/ai-groq';
|
|
218
|
+
|
|
219
|
+
// The GroqLLM class is automatically registered with the MemberJunction class factory
|
|
220
|
+
// You can retrieve it using the class factory pattern
|
|
221
|
+
const llm = RegisterClass.GetRegisteredClass(BaseLLM, 'GroqLLM', 'your-api-key');
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Advanced Features
|
|
225
|
+
|
|
226
|
+
### Effort Level Support
|
|
227
|
+
|
|
228
|
+
For models that support reasoning effort levels (experimental):
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const params: ChatParams = {
|
|
232
|
+
model: 'llama3-70b-8192',
|
|
233
|
+
messages: [{ role: 'user', content: 'Solve this complex problem...' }],
|
|
234
|
+
effortLevel: 'high', // Experimental feature
|
|
235
|
+
maxOutputTokens: 2000
|
|
236
|
+
};
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Handling Groq-Specific Requirements
|
|
240
|
+
|
|
241
|
+
The wrapper automatically handles Groq's requirement that the last message must be from a user. If your message chain ends with an assistant message, the wrapper will automatically append a dummy user message to satisfy this requirement.
|
|
242
|
+
|
|
141
243
|
## Dependencies
|
|
142
244
|
|
|
143
|
-
- `groq-sdk
|
|
144
|
-
- `@memberjunction/ai
|
|
145
|
-
- `@memberjunction/global
|
|
245
|
+
- `groq-sdk` (0.21.0): Official Groq SDK
|
|
246
|
+
- `@memberjunction/ai` (2.43.0): MemberJunction AI core framework
|
|
247
|
+
- `@memberjunction/global` (2.43.0): MemberJunction global utilities
|
|
248
|
+
|
|
249
|
+
## Development
|
|
250
|
+
|
|
251
|
+
### Building
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
npm run build
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Development Mode
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
npm start
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Contributing
|
|
264
|
+
|
|
265
|
+
When contributing to this package:
|
|
266
|
+
|
|
267
|
+
1. Follow the MemberJunction coding standards
|
|
268
|
+
2. Ensure all TypeScript types are properly defined
|
|
269
|
+
3. Update tests when adding new features
|
|
270
|
+
4. Document any Groq-specific behaviors or limitations
|
|
146
271
|
|
|
147
272
|
## License
|
|
148
273
|
|