@lobehub/chat 0.156.0 → 0.156.1

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.156.1](https://github.com/lobehub/lobe-chat/compare/v0.156.0...v0.156.1)
6
+
7
+ <sup>Released on **2024-05-10**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Azure OpenAI Vision models issue.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **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))
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.156.0](https://github.com/lobehub/lobe-chat/compare/v0.155.9...v0.156.0)
6
31
 
7
32
  <sup>Released on **2024-05-09**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.156.0",
3
+ "version": "0.156.1",
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,30 @@ 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)
85
+ return obj;
86
+ if (Array.isArray(obj)) {
87
+ return obj.map((v) => this.camelCaseKeys(v));
88
+ }
89
+ else {
90
+ for (const key of Object.keys(obj)) {
91
+ const value = obj[key];
92
+ const newKey = this.tocamelCase(key);
93
+ if (newKey !== key) {
94
+ delete obj[key];
95
+ }
96
+ obj[newKey] = typeof obj[newKey] === "object" ? this.camelCaseKeys(value) : value;
97
+ }
98
+ return obj;
99
+ }
100
+ }
101
+
102
+ private tocamelCase = (str: string) => {
103
+ return str
104
+ .toLowerCase()
105
+ .replaceAll(/(_[a-z])/g, (group) => group.toUpperCase().replace("_", ""));
106
+ }
80
107
  }