@lobehub/chat 0.156.0 → 0.156.2

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,48 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.156.2](https://github.com/lobehub/lobe-chat/compare/v0.156.1...v0.156.2)
6
+
7
+ <sup>Released on **2024-05-10**</sup>
8
+
9
+ <br/>
10
+
11
+ <details>
12
+ <summary><kbd>Improvements and Fixes</kbd></summary>
13
+
14
+ </details>
15
+
16
+ <div align="right">
17
+
18
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
19
+
20
+ </div>
21
+
22
+ ### [Version 0.156.1](https://github.com/lobehub/lobe-chat/compare/v0.156.0...v0.156.1)
23
+
24
+ <sup>Released on **2024-05-10**</sup>
25
+
26
+ #### 🐛 Bug Fixes
27
+
28
+ - **misc**: Azure OpenAI Vision models issue.
29
+
30
+ <br/>
31
+
32
+ <details>
33
+ <summary><kbd>Improvements and Fixes</kbd></summary>
34
+
35
+ #### What's fixed
36
+
37
+ - **misc**: Azure OpenAI Vision models issue, closes [#2429](https://github.com/lobehub/lobe-chat/issues/2429) ([9b8a4b1](https://github.com/lobehub/lobe-chat/commit/9b8a4b1))
38
+
39
+ </details>
40
+
41
+ <div align="right">
42
+
43
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
44
+
45
+ </div>
46
+
5
47
  ## [Version 0.156.0](https://github.com/lobehub/lobe-chat/compare/v0.155.9...v0.156.0)
6
48
 
7
49
  <sup>Released on **2024-05-09**</sup>
package/Dockerfile CHANGED
@@ -44,8 +44,11 @@ ENV NEXT_PUBLIC_ANALYTICS_UMAMI ""
44
44
  ENV NEXT_PUBLIC_UMAMI_SCRIPT_URL ""
45
45
  ENV NEXT_PUBLIC_UMAMI_WEBSITE_ID ""
46
46
 
47
+ # Node
48
+ ENV NODE_OPTIONS "--max-old-space-size=8192"
47
49
 
48
- RUN npm run build:docker # run build standalone for docker version
50
+ # run build standalone for docker version
51
+ RUN npm run build:docker
49
52
 
50
53
  ## Production image, copy all the files and run next
51
54
  FROM base AS runner
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.156.0",
3
+ "version": "0.156.2",
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",
@@ -163,4 +163,57 @@ describe('LobeAzureOpenAI', () => {
163
163
  });
164
164
  });
165
165
  });
166
+
167
+ describe('private method', () => {
168
+
169
+ describe('tocamelCase', () => {
170
+ it('should convert string to camel case', () => {
171
+ const key = 'image_url';
172
+
173
+ const camelCaseKey = instance['tocamelCase'](key);
174
+
175
+ expect(camelCaseKey).toEqual('imageUrl');
176
+ });
177
+ });
178
+
179
+ describe('camelCaseKeys', () => {
180
+ it('should convert object keys to camel case', () => {
181
+ const obj = {
182
+ "frequency_penalty": 0,
183
+ "messages": [
184
+ {
185
+ "role": "user",
186
+ "content": [
187
+ {
188
+ "type": "image_url",
189
+ "image_url": {
190
+ "url": "<image URL>"
191
+ }
192
+ }
193
+ ]
194
+ }
195
+ ]
196
+ };
197
+
198
+ const newObj = instance['camelCaseKeys'](obj);
199
+
200
+ expect(newObj).toEqual({
201
+ "frequencyPenalty": 0,
202
+ "messages": [
203
+ {
204
+ "role": "user",
205
+ "content": [
206
+ {
207
+ "type": "image_url",
208
+ "imageUrl": {
209
+ "url": "<image URL>"
210
+ }
211
+ }
212
+ ]
213
+ }
214
+ ]
215
+ });
216
+ });
217
+ });
218
+ })
166
219
  });
@@ -28,7 +28,8 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
28
28
 
29
29
  async chat(payload: ChatStreamPayload, options?: ChatCompetitionOptions) {
30
30
  // ============ 1. preprocess messages ============ //
31
- const { messages, model, ...params } = payload;
31
+ const camelCasePayload = this.camelCaseKeys(payload);
32
+ const { messages, model, maxTokens = 2048, ...params } = camelCasePayload;
32
33
 
33
34
  // ============ 2. send api ============ //
34
35
 
@@ -36,7 +37,7 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
36
37
  const response = await this.client.streamChatCompletions(
37
38
  model,
38
39
  messages as ChatRequestMessage[],
39
- { ...params, abortSignal: options?.signal } as GetChatCompletionsOptions,
40
+ { ...params, abortSignal: options?.signal, maxTokens } as GetChatCompletionsOptions,
40
41
  );
41
42
 
42
43
  const stream = OpenAIStream(response as any);
@@ -77,4 +78,28 @@ export class LobeAzureOpenAI implements LobeRuntimeAI {
77
78
  });
78
79
  }
79
80
  }
81
+
82
+ // Convert object keys to camel case, copy from `@azure/openai` in `node_modules/@azure/openai/dist/index.cjs`
83
+ private camelCaseKeys = (obj: any): any => {
84
+ if (typeof obj !== 'object' || !obj) return obj;
85
+ if (Array.isArray(obj)) {
86
+ return obj.map((v) => this.camelCaseKeys(v));
87
+ } else {
88
+ for (const key of Object.keys(obj)) {
89
+ const value = obj[key];
90
+ const newKey = this.tocamelCase(key);
91
+ if (newKey !== key) {
92
+ delete obj[key];
93
+ }
94
+ obj[newKey] = typeof obj[newKey] === 'object' ? this.camelCaseKeys(value) : value;
95
+ }
96
+ return obj;
97
+ }
98
+ };
99
+
100
+ private tocamelCase = (str: string) => {
101
+ return str
102
+ .toLowerCase()
103
+ .replaceAll(/(_[a-z])/g, (group) => group.toUpperCase().replace('_', ''));
104
+ };
80
105
  }