@lobehub/chat 0.151.8 → 0.151.9

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/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.151.9](https://github.com/lobehub/lobe-chat/compare/v0.151.8...v0.151.9)
6
+
7
+ <sup>Released on **2024-04-30**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Minimax truncationed output.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Minimax truncationed output, closes [#2308](https://github.com/lobehub/lobe-chat/issues/2308) ([488f319](https://github.com/lobehub/lobe-chat/commit/488f319))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.151.8](https://github.com/lobehub/lobe-chat/compare/v0.151.7...v0.151.8)
6
31
 
7
32
  <sup>Released on **2024-04-30**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.151.8",
3
+ "version": "0.151.9",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -223,7 +223,6 @@ describe('LobeMinimaxAI', () => {
223
223
  model: 'text-davinci-003',
224
224
  temperature: 0.5,
225
225
  top_p: 0.8,
226
- max_tokens: 100,
227
226
  };
228
227
 
229
228
  const result = instance['buildCompletionsParams'](payload);
@@ -234,7 +233,6 @@ describe('LobeMinimaxAI', () => {
234
233
  stream: true,
235
234
  temperature: 0.5,
236
235
  top_p: 0.8,
237
- max_tokens: 100,
238
236
  });
239
237
  });
240
238
 
@@ -244,7 +242,6 @@ describe('LobeMinimaxAI', () => {
244
242
  model: 'text-davinci-003',
245
243
  temperature: 0,
246
244
  top_p: 0,
247
- max_tokens: 100,
248
245
  };
249
246
 
250
247
  const result = instance['buildCompletionsParams'](payload);
@@ -253,7 +250,24 @@ describe('LobeMinimaxAI', () => {
253
250
  messages: [{ content: 'Hello', role: 'user' }],
254
251
  model: 'text-davinci-003',
255
252
  stream: true,
256
- max_tokens: 100,
253
+ });
254
+ });
255
+
256
+ it('should include max tokens when model is abab6.5-chat', () => {
257
+ const payload: ChatStreamPayload = {
258
+ messages: [{ content: 'Hello', role: 'user' }],
259
+ model: 'abab6.5-chat',
260
+ temperature: 0,
261
+ top_p: 0,
262
+ };
263
+
264
+ const result = instance['buildCompletionsParams'](payload);
265
+
266
+ expect(result).toEqual({
267
+ messages: [{ content: 'Hello', role: 'user' }],
268
+ model: 'abab6.5-chat',
269
+ stream: true,
270
+ max_tokens: 2048,
257
271
  });
258
272
  });
259
273
  });
@@ -49,7 +49,7 @@ function throwIfErrorResponse(data: MinimaxResponse) {
49
49
  });
50
50
  }
51
51
 
52
- function parseMinimaxResponse(chunk: string): string | undefined {
52
+ function parseMinimaxResponse(chunk: string): MinimaxResponse | undefined {
53
53
  let body = chunk;
54
54
  if (body.startsWith('data:')) {
55
55
  body = body.slice(5).trim();
@@ -57,10 +57,7 @@ function parseMinimaxResponse(chunk: string): string | undefined {
57
57
  if (isEmpty(body)) {
58
58
  return;
59
59
  }
60
- const data = JSON.parse(body) as MinimaxResponse;
61
- if (data.choices?.at(0)?.delta?.content) {
62
- return data.choices.at(0)?.delta.content || undefined;
63
- }
60
+ return JSON.parse(body) as MinimaxResponse;
64
61
  }
65
62
 
66
63
  export class LobeMinimaxAI implements LobeRuntimeAI {
@@ -136,11 +133,25 @@ export class LobeMinimaxAI implements LobeRuntimeAI {
136
133
  }
137
134
  }
138
135
 
136
+ // the document gives the default value of max tokens, but abab6.5 and abab6.5s
137
+ // will meet length finished error, and output is truncationed
138
+ // so here fill the max tokens number to fix it
139
+ // https://www.minimaxi.com/document/guides/chat-model/V2
140
+ private getMaxTokens(model: string): number | undefined {
141
+ switch (model) {
142
+ case 'abab6.5-chat':
143
+ case 'abab6.5s-chat': {
144
+ return 2048;
145
+ }
146
+ }
147
+ }
148
+
139
149
  private buildCompletionsParams(payload: ChatStreamPayload) {
140
150
  const { temperature, top_p, ...params } = payload;
141
151
 
142
152
  return {
143
153
  ...params,
154
+ max_tokens: this.getMaxTokens(payload.model),
144
155
  stream: true,
145
156
  temperature: temperature === 0 ? undefined : temperature,
146
157
  top_p: top_p === 0 ? undefined : top_p,
@@ -159,7 +170,8 @@ export class LobeMinimaxAI implements LobeRuntimeAI {
159
170
  const { value, done: doneReading } = await reader.read();
160
171
  done = doneReading;
161
172
  const chunkValue = decoder.decode(value, { stream: true });
162
- const text = parseMinimaxResponse(chunkValue);
173
+ const data = parseMinimaxResponse(chunkValue);
174
+ const text = data?.choices?.at(0)?.delta?.content || undefined;
163
175
  streamController?.enqueue(encoder.encode(text));
164
176
  }
165
177
 
@@ -173,12 +185,14 @@ export class LobeMinimaxAI implements LobeRuntimeAI {
173
185
  const chunkValue = decoder.decode(value, { stream: true });
174
186
  let data;
175
187
  try {
176
- data = JSON.parse(chunkValue) as MinimaxResponse;
188
+ data = parseMinimaxResponse(chunkValue);
177
189
  } catch {
178
190
  // parse error, skip it
179
191
  return;
180
192
  }
181
- throwIfErrorResponse(data);
193
+ if (data) {
194
+ throwIfErrorResponse(data);
195
+ }
182
196
  }
183
197
  }
184
198
 
@@ -25,6 +25,7 @@ export const getServerGlobalConfig = () => {
25
25
  ENABLED_GROQ,
26
26
  ENABLED_PERPLEXITY,
27
27
  ENABLED_ANTHROPIC,
28
+ ENABLED_MINIMAX,
28
29
  ENABLED_MISTRAL,
29
30
 
30
31
  ENABLED_AZURE_OPENAI,
@@ -64,6 +65,7 @@ export const getServerGlobalConfig = () => {
64
65
  bedrock: { enabled: ENABLED_AWS_BEDROCK },
65
66
  google: { enabled: ENABLED_GOOGLE },
66
67
  groq: { enabled: ENABLED_GROQ },
68
+ minimax: { enabled: ENABLED_MINIMAX },
67
69
  mistral: { enabled: ENABLED_MISTRAL },
68
70
  moonshot: { enabled: ENABLED_MOONSHOT },
69
71
  ollama: {