@memberjunction/ai-groq 2.32.2 → 2.33.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 +149 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ai-groq",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.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.33.0",
|
|
23
|
+
"@memberjunction/global": "2.33.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
|