@memberjunction/ai-groq 2.33.0 → 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/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"],"names":[],"mappings":"A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c,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,WAAW;SAClC,CAAC;Q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C;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
|
}
|