@lobehub/chat 1.15.33 → 1.15.34

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.

Potentially problematic release.


This version of @lobehub/chat might be problematic. Click here for more details.

package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.15.34](https://github.com/lobehub/lobe-chat/compare/v1.15.33...v1.15.34)
6
+
7
+ <sup>Released on **2024-09-10**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Change empty content stream behavior.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Change empty content stream behavior, closes [#3883](https://github.com/lobehub/lobe-chat/issues/3883) ([e910f68](https://github.com/lobehub/lobe-chat/commit/e910f68))
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 1.15.33](https://github.com/lobehub/lobe-chat/compare/v1.15.32...v1.15.33)
6
31
 
7
32
  <sup>Released on **2024-09-10**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.15.33",
3
+ "version": "1.15.34",
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",
@@ -128,6 +128,40 @@ describe('OpenAIStream', () => {
128
128
  expect(chunks).toEqual(['id: 3\n', 'event: data\n', `data: {"content":null}\n\n`]);
129
129
  });
130
130
 
131
+ it('should handle content with finish_reason', async () => {
132
+ const mockOpenAIStream = new ReadableStream({
133
+ start(controller) {
134
+ controller.enqueue({
135
+ id: '123',
136
+ model: 'deepl',
137
+ choices: [
138
+ {
139
+ index: 0,
140
+ delta: { role: 'assistant', content: 'Introduce yourself.' },
141
+ finish_reason: 'stop',
142
+ },
143
+ ],
144
+ });
145
+
146
+ controller.close();
147
+ },
148
+ });
149
+
150
+ const protocolStream = OpenAIStream(mockOpenAIStream);
151
+
152
+ const decoder = new TextDecoder();
153
+ const chunks = [];
154
+
155
+ // @ts-ignore
156
+ for await (const chunk of protocolStream) {
157
+ chunks.push(decoder.decode(chunk, { stream: true }));
158
+ }
159
+
160
+ expect(chunks).toEqual(
161
+ ['id: 123', 'event: text', `data: "Introduce yourself."\n`].map((i) => `${i}\n`),
162
+ );
163
+ });
164
+
131
165
  it('should handle other delta data', async () => {
132
166
  const mockOpenAIStream = new ReadableStream({
133
167
  start(controller) {
@@ -27,10 +27,6 @@ export const transformOpenAIStream = (
27
27
  return { data: chunk, id: chunk.id, type: 'data' };
28
28
  }
29
29
 
30
- if (typeof item.delta?.content === 'string' && !item.finish_reason && !item.delta?.tool_calls) {
31
- return { data: item.delta.content, id: chunk.id, type: 'text' };
32
- }
33
-
34
30
  if (item.delta?.tool_calls) {
35
31
  return {
36
32
  data: item.delta.tool_calls.map((value, index): StreamToolCallChunkData => {
@@ -60,9 +56,20 @@ export const transformOpenAIStream = (
60
56
 
61
57
  // 给定结束原因
62
58
  if (item.finish_reason) {
59
+ // one-api 的流式接口,会出现既有 finish_reason ,也有 content 的情况
60
+ // {"id":"demo","model":"deepl-en","choices":[{"index":0,"delta":{"role":"assistant","content":"Introduce yourself."},"finish_reason":"stop"}]}
61
+
62
+ if (typeof item.delta?.content === 'string' && !!item.delta.content) {
63
+ return { data: item.delta.content, id: chunk.id, type: 'text' };
64
+ }
65
+
63
66
  return { data: item.finish_reason, id: chunk.id, type: 'stop' };
64
67
  }
65
68
 
69
+ if (typeof item.delta?.content === 'string') {
70
+ return { data: item.delta.content, id: chunk.id, type: 'text' };
71
+ }
72
+
66
73
  if (item.delta?.content === null) {
67
74
  return { data: item.delta, id: chunk.id, type: 'data' };
68
75
  }