@lobehub/chat 1.57.1 → 1.58.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/docker-compose/local/docker-compose.yml +1 -0
  4. package/locales/ar/modelProvider.json +24 -0
  5. package/locales/ar/models.json +60 -0
  6. package/locales/ar/providers.json +12 -0
  7. package/locales/bg-BG/modelProvider.json +24 -0
  8. package/locales/bg-BG/models.json +60 -0
  9. package/locales/bg-BG/providers.json +12 -0
  10. package/locales/de-DE/modelProvider.json +24 -0
  11. package/locales/de-DE/models.json +60 -0
  12. package/locales/de-DE/providers.json +12 -0
  13. package/locales/en-US/modelProvider.json +24 -0
  14. package/locales/en-US/models.json +60 -0
  15. package/locales/en-US/providers.json +12 -0
  16. package/locales/es-ES/modelProvider.json +24 -0
  17. package/locales/es-ES/models.json +60 -0
  18. package/locales/es-ES/providers.json +12 -0
  19. package/locales/fa-IR/modelProvider.json +30 -0
  20. package/locales/fa-IR/models.json +60 -0
  21. package/locales/fa-IR/providers.json +12 -0
  22. package/locales/fr-FR/modelProvider.json +24 -0
  23. package/locales/fr-FR/models.json +60 -0
  24. package/locales/fr-FR/providers.json +12 -0
  25. package/locales/it-IT/modelProvider.json +24 -0
  26. package/locales/it-IT/models.json +60 -0
  27. package/locales/it-IT/providers.json +12 -0
  28. package/locales/ja-JP/modelProvider.json +24 -0
  29. package/locales/ja-JP/models.json +60 -0
  30. package/locales/ja-JP/providers.json +12 -0
  31. package/locales/ko-KR/modelProvider.json +24 -0
  32. package/locales/ko-KR/models.json +60 -0
  33. package/locales/ko-KR/providers.json +12 -0
  34. package/locales/nl-NL/modelProvider.json +24 -0
  35. package/locales/nl-NL/models.json +60 -0
  36. package/locales/nl-NL/providers.json +12 -0
  37. package/locales/pl-PL/modelProvider.json +24 -0
  38. package/locales/pl-PL/models.json +60 -0
  39. package/locales/pl-PL/providers.json +12 -0
  40. package/locales/pt-BR/modelProvider.json +24 -0
  41. package/locales/pt-BR/models.json +60 -0
  42. package/locales/pt-BR/providers.json +12 -0
  43. package/locales/ru-RU/modelProvider.json +24 -0
  44. package/locales/ru-RU/models.json +60 -0
  45. package/locales/ru-RU/providers.json +12 -0
  46. package/locales/tr-TR/modelProvider.json +30 -0
  47. package/locales/tr-TR/models.json +60 -0
  48. package/locales/tr-TR/providers.json +12 -0
  49. package/locales/vi-VN/modelProvider.json +24 -0
  50. package/locales/vi-VN/models.json +60 -0
  51. package/locales/vi-VN/providers.json +12 -0
  52. package/locales/zh-CN/modelProvider.json +24 -0
  53. package/locales/zh-CN/models.json +1112 -1052
  54. package/locales/zh-CN/providers.json +80 -68
  55. package/locales/zh-TW/modelProvider.json +24 -0
  56. package/locales/zh-TW/models.json +60 -0
  57. package/locales/zh-TW/providers.json +12 -0
  58. package/package.json +4 -2
  59. package/src/app/[variants]/(main)/settings/provider/(detail)/azureai/page.tsx +58 -0
  60. package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +13 -2
  61. package/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx +6 -8
  62. package/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/index.tsx +5 -6
  63. package/src/app/[variants]/(main)/settings/provider/features/ModelList/ModelConfigModal/index.tsx +4 -3
  64. package/src/app/[variants]/(main)/settings/provider/features/ModelList/ProviderSettingsContext.ts +2 -0
  65. package/src/app/[variants]/(main)/settings/provider/features/ModelList/index.tsx +6 -7
  66. package/src/app/[variants]/(main)/settings/provider/features/ProviderConfig/index.tsx +1 -1
  67. package/src/config/aiModels/azureai.ts +18 -0
  68. package/src/config/aiModels/index.ts +3 -0
  69. package/src/config/modelProviders/azure.ts +2 -1
  70. package/src/config/modelProviders/azureai.ts +19 -0
  71. package/src/config/modelProviders/index.ts +3 -0
  72. package/src/database/server/models/aiProvider.ts +2 -0
  73. package/src/libs/agent-runtime/AgentRuntime.ts +13 -6
  74. package/src/libs/agent-runtime/azureai/index.ts +109 -0
  75. package/src/libs/agent-runtime/baichuan/index.test.ts +8 -250
  76. package/src/libs/agent-runtime/cloudflare/index.ts +22 -18
  77. package/src/libs/agent-runtime/index.ts +1 -0
  78. package/src/libs/agent-runtime/types/type.ts +1 -0
  79. package/src/libs/agent-runtime/utils/streams/__snapshots__/protocol.test.ts.snap +331 -0
  80. package/src/libs/agent-runtime/utils/streams/protocol.test.ts +137 -0
  81. package/src/libs/agent-runtime/utils/streams/protocol.ts +34 -0
  82. package/src/locales/default/modelProvider.ts +25 -0
  83. package/src/server/modules/AgentRuntime/index.ts +8 -1
  84. package/src/services/chat.ts +12 -3
  85. package/src/types/aiProvider.ts +1 -0
  86. package/src/types/user/settings/keyVaults.ts +1 -0
@@ -1,3 +1,5 @@
1
+ import { ChatModelCard } from '@/types/llm';
2
+
1
3
  import { LobeRuntimeAI } from '../BaseAI';
2
4
  import { AgentRuntimeErrorType } from '../error';
3
5
  import { ChatCompetitionOptions, ChatStreamPayload, ModelProvider } from '../types';
@@ -12,8 +14,6 @@ import { debugStream } from '../utils/debugStream';
12
14
  import { StreamingResponse } from '../utils/response';
13
15
  import { createCallbacksTransformer } from '../utils/streams';
14
16
 
15
- import { ChatModelCard } from '@/types/llm';
16
-
17
17
  export interface CloudflareModelCard {
18
18
  description: string;
19
19
  name: string;
@@ -34,7 +34,7 @@ export class LobeCloudflareAI implements LobeRuntimeAI {
34
34
  accountID: string;
35
35
  apiKey?: string;
36
36
 
37
- constructor({ apiKey, baseURLOrAccountID }: LobeCloudflareParams) {
37
+ constructor({ apiKey, baseURLOrAccountID }: LobeCloudflareParams = {}) {
38
38
  if (!baseURLOrAccountID) {
39
39
  throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidProviderAPIKey);
40
40
  }
@@ -128,30 +128,34 @@ export class LobeCloudflareAI implements LobeRuntimeAI {
128
128
 
129
129
  return modelList
130
130
  .map((model) => {
131
- const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name.toLowerCase() === m.id.toLowerCase());
131
+ const knownModel = LOBE_DEFAULT_MODEL_LIST.find(
132
+ (m) => model.name.toLowerCase() === m.id.toLowerCase(),
133
+ );
132
134
 
133
135
  return {
134
136
  contextWindowTokens: model.properties?.max_total_tokens
135
137
  ? Number(model.properties.max_total_tokens)
136
- : knownModel?.contextWindowTokens ?? undefined,
137
- displayName: knownModel?.displayName ?? (model.properties?.["beta"] === "true" ? `${model.name} (Beta)` : undefined),
138
+ : (knownModel?.contextWindowTokens ?? undefined),
139
+ displayName:
140
+ knownModel?.displayName ??
141
+ (model.properties?.['beta'] === 'true' ? `${model.name} (Beta)` : undefined),
138
142
  enabled: knownModel?.enabled || false,
139
143
  functionCall:
140
- model.description.toLowerCase().includes('function call')
141
- || model.properties?.["function_calling"] === "true"
142
- || knownModel?.abilities?.functionCall
143
- || false,
144
+ model.description.toLowerCase().includes('function call') ||
145
+ model.properties?.['function_calling'] === 'true' ||
146
+ knownModel?.abilities?.functionCall ||
147
+ false,
144
148
  id: model.name,
145
149
  reasoning:
146
- model.name.toLowerCase().includes('deepseek-r1')
147
- || knownModel?.abilities?.reasoning
148
- || false,
150
+ model.name.toLowerCase().includes('deepseek-r1') ||
151
+ knownModel?.abilities?.reasoning ||
152
+ false,
149
153
  vision:
150
- model.name.toLowerCase().includes('vision')
151
- || model.task?.name.toLowerCase().includes('image-to-text')
152
- || model.description.toLowerCase().includes('vision')
153
- || knownModel?.abilities?.vision
154
- || false,
154
+ model.name.toLowerCase().includes('vision') ||
155
+ model.task?.name.toLowerCase().includes('image-to-text') ||
156
+ model.description.toLowerCase().includes('vision') ||
157
+ knownModel?.abilities?.vision ||
158
+ false,
155
159
  };
156
160
  })
157
161
  .filter(Boolean) as ChatModelCard[];
@@ -1,5 +1,6 @@
1
1
  export { default as AgentRuntime } from './AgentRuntime';
2
2
  export { LobeAnthropicAI } from './anthropic';
3
+ export { LobeAzureAI } from './azureai';
3
4
  export { LobeAzureOpenAI } from './azureOpenai';
4
5
  export * from './BaseAI';
5
6
  export { LobeBedrockAI } from './bedrock';
@@ -26,6 +26,7 @@ export enum ModelProvider {
26
26
  Ai360 = 'ai360',
27
27
  Anthropic = 'anthropic',
28
28
  Azure = 'azure',
29
+ AzureAI = 'azureai',
29
30
  Baichuan = 'baichuan',
30
31
  Bedrock = 'bedrock',
31
32
  Cloudflare = 'cloudflare',
@@ -0,0 +1,331 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`createSSEDataExtractor > real world data > should convert azure ai data 1`] = `
4
+ [
5
+ {
6
+ "choices": [
7
+ {
8
+ "delta": {
9
+ "content": "",
10
+ "reasoning_content": null,
11
+ "role": "assistant",
12
+ "tool_calls": null,
13
+ },
14
+ "finish_reason": null,
15
+ "index": 0,
16
+ "logprobs": null,
17
+ "matched_stop": null,
18
+ },
19
+ ],
20
+ "created": 1739714651,
21
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
22
+ "model": "DeepSeek-R1",
23
+ "object": "chat.completion.chunk",
24
+ "usage": null,
25
+ },
26
+ {
27
+ "choices": [
28
+ {
29
+ "delta": {
30
+ "content": "<think>",
31
+ "reasoning_content": null,
32
+ "role": null,
33
+ "tool_calls": null,
34
+ },
35
+ "finish_reason": null,
36
+ "index": 0,
37
+ "logprobs": null,
38
+ "matched_stop": null,
39
+ },
40
+ ],
41
+ "created": 1739714651,
42
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
43
+ "model": "DeepSeek-R1",
44
+ "object": "chat.completion.chunk",
45
+ "usage": null,
46
+ },
47
+ {
48
+ "choices": [
49
+ {
50
+ "delta": {
51
+ "content": "</think>",
52
+ "reasoning_content": null,
53
+ "role": null,
54
+ "tool_calls": null,
55
+ },
56
+ "finish_reason": null,
57
+ "index": 0,
58
+ "logprobs": null,
59
+ "matched_stop": null,
60
+ },
61
+ ],
62
+ "created": 1739714651,
63
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
64
+ "model": "DeepSeek-R1",
65
+ "object": "chat.completion.chunk",
66
+ "usage": null,
67
+ },
68
+ {
69
+ "choices": [
70
+ {
71
+ "delta": {
72
+ "content": "Hello",
73
+ "reasoning_content": null,
74
+ "role": null,
75
+ "tool_calls": null,
76
+ },
77
+ "finish_reason": null,
78
+ "index": 0,
79
+ "logprobs": null,
80
+ "matched_stop": null,
81
+ },
82
+ ],
83
+ "created": 1739714651,
84
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
85
+ "model": "DeepSeek-R1",
86
+ "object": "chat.completion.chunk",
87
+ "usage": null,
88
+ },
89
+ {
90
+ "choices": [
91
+ {
92
+ "delta": {
93
+ "content": "!",
94
+ "reasoning_content": null,
95
+ "role": null,
96
+ "tool_calls": null,
97
+ },
98
+ "finish_reason": null,
99
+ "index": 0,
100
+ "logprobs": null,
101
+ "matched_stop": null,
102
+ },
103
+ ],
104
+ "created": 1739714652,
105
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
106
+ "model": "DeepSeek-R1",
107
+ "object": "chat.completion.chunk",
108
+ "usage": null,
109
+ },
110
+ {
111
+ "choices": [
112
+ {
113
+ "delta": {
114
+ "content": " How",
115
+ "reasoning_content": null,
116
+ "role": null,
117
+ "tool_calls": null,
118
+ },
119
+ "finish_reason": null,
120
+ "index": 0,
121
+ "logprobs": null,
122
+ "matched_stop": null,
123
+ },
124
+ ],
125
+ "created": 1739714652,
126
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
127
+ "model": "DeepSeek-R1",
128
+ "object": "chat.completion.chunk",
129
+ "usage": null,
130
+ },
131
+ {
132
+ "choices": [
133
+ {
134
+ "delta": {
135
+ "content": " can",
136
+ "reasoning_content": null,
137
+ "role": null,
138
+ "tool_calls": null,
139
+ },
140
+ "finish_reason": null,
141
+ "index": 0,
142
+ "logprobs": null,
143
+ "matched_stop": null,
144
+ },
145
+ ],
146
+ "created": 1739714652,
147
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
148
+ "model": "DeepSeek-R1",
149
+ "object": "chat.completion.chunk",
150
+ "usage": null,
151
+ },
152
+ {
153
+ "choices": [
154
+ {
155
+ "delta": {
156
+ "content": " I",
157
+ "reasoning_content": null,
158
+ "role": null,
159
+ "tool_calls": null,
160
+ },
161
+ "finish_reason": null,
162
+ "index": 0,
163
+ "logprobs": null,
164
+ "matched_stop": null,
165
+ },
166
+ ],
167
+ "created": 1739714652,
168
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
169
+ "model": "DeepSeek-R1",
170
+ "object": "chat.completion.chunk",
171
+ "usage": null,
172
+ },
173
+ {
174
+ "choices": [
175
+ {
176
+ "delta": {
177
+ "content": " assist",
178
+ "reasoning_content": null,
179
+ "role": null,
180
+ "tool_calls": null,
181
+ },
182
+ "finish_reason": null,
183
+ "index": 0,
184
+ "logprobs": null,
185
+ "matched_stop": null,
186
+ },
187
+ ],
188
+ "created": 1739714652,
189
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
190
+ "model": "DeepSeek-R1",
191
+ "object": "chat.completion.chunk",
192
+ "usage": null,
193
+ },
194
+ {
195
+ "choices": [
196
+ {
197
+ "delta": {
198
+ "content": " you",
199
+ "reasoning_content": null,
200
+ "role": null,
201
+ "tool_calls": null,
202
+ },
203
+ "finish_reason": null,
204
+ "index": 0,
205
+ "logprobs": null,
206
+ "matched_stop": null,
207
+ },
208
+ ],
209
+ "created": 1739714652,
210
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
211
+ "model": "DeepSeek-R1",
212
+ "object": "chat.completion.chunk",
213
+ "usage": null,
214
+ },
215
+ {
216
+ "choices": [
217
+ {
218
+ "delta": {
219
+ "content": " today",
220
+ "reasoning_content": null,
221
+ "role": null,
222
+ "tool_calls": null,
223
+ },
224
+ "finish_reason": null,
225
+ "index": 0,
226
+ "logprobs": null,
227
+ "matched_stop": null,
228
+ },
229
+ ],
230
+ "created": 1739714652,
231
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
232
+ "model": "DeepSeek-R1",
233
+ "object": "chat.completion.chunk",
234
+ "usage": null,
235
+ },
236
+ {
237
+ "choices": [
238
+ {
239
+ "delta": {
240
+ "content": "?",
241
+ "reasoning_content": null,
242
+ "role": null,
243
+ "tool_calls": null,
244
+ },
245
+ "finish_reason": null,
246
+ "index": 0,
247
+ "logprobs": null,
248
+ "matched_stop": null,
249
+ },
250
+ ],
251
+ "created": 1739714652,
252
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
253
+ "model": "DeepSeek-R1",
254
+ "object": "chat.completion.chunk",
255
+ "usage": null,
256
+ },
257
+ {
258
+ "choices": [
259
+ {
260
+ "delta": {
261
+ "content": " ",
262
+ "reasoning_content": null,
263
+ "role": null,
264
+ "tool_calls": null,
265
+ },
266
+ "finish_reason": null,
267
+ "index": 0,
268
+ "logprobs": null,
269
+ "matched_stop": null,
270
+ },
271
+ ],
272
+ "created": 1739714652,
273
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
274
+ "model": "DeepSeek-R1",
275
+ "object": "chat.completion.chunk",
276
+ "usage": null,
277
+ },
278
+ {
279
+ "choices": [
280
+ {
281
+ "delta": {
282
+ "content": "😊",
283
+ "reasoning_content": null,
284
+ "role": null,
285
+ "tool_calls": null,
286
+ },
287
+ "finish_reason": null,
288
+ "index": 0,
289
+ "logprobs": null,
290
+ "matched_stop": null,
291
+ },
292
+ ],
293
+ "created": 1739714652,
294
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
295
+ "model": "DeepSeek-R1",
296
+ "object": "chat.completion.chunk",
297
+ "usage": null,
298
+ },
299
+ {
300
+ "choices": [
301
+ {
302
+ "delta": {
303
+ "content": "",
304
+ "reasoning_content": null,
305
+ "role": null,
306
+ "tool_calls": null,
307
+ },
308
+ "finish_reason": "stop",
309
+ "index": 0,
310
+ "logprobs": null,
311
+ "matched_stop": 1,
312
+ },
313
+ ],
314
+ "created": 1739714652,
315
+ "id": "1392a93d52c3483ea872d0ab2aaff7d7",
316
+ "model": "DeepSeek-R1",
317
+ "object": "chat.completion.chunk",
318
+ "usage": null,
319
+ },
320
+ {
321
+ "choices": [],
322
+ "id": "79fca0de792a4ffb8ec836442a2a42c0",
323
+ "model": "DeepSeek-R1",
324
+ "usage": {
325
+ "completion_tokens": 16,
326
+ "prompt_tokens": 4,
327
+ "total_tokens": 20,
328
+ },
329
+ },
330
+ ]
331
+ `;
@@ -0,0 +1,137 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createSSEDataExtractor } from './protocol';
4
+
5
+ describe('createSSEDataExtractor', () => {
6
+ // Helper function to convert string to Uint8Array
7
+ const stringToUint8Array = (str: string): Uint8Array => {
8
+ return new TextEncoder().encode(str);
9
+ };
10
+
11
+ // Helper function to process chunks through transformer
12
+ const processChunk = async (transformer: TransformStream, chunk: Uint8Array) => {
13
+ const results: any[] = [];
14
+ const readable = new ReadableStream({
15
+ start(controller) {
16
+ controller.enqueue(chunk);
17
+ controller.close();
18
+ },
19
+ });
20
+
21
+ const writable = new WritableStream({
22
+ write(chunk) {
23
+ results.push(chunk);
24
+ },
25
+ });
26
+
27
+ await readable.pipeThrough(transformer).pipeTo(writable);
28
+
29
+ return results;
30
+ };
31
+
32
+ it('should correctly transform single SSE data line', async () => {
33
+ const transformer = createSSEDataExtractor();
34
+ const input = 'data: {"message": "hello"}\n';
35
+ const chunk = stringToUint8Array(input);
36
+
37
+ const results = await processChunk(transformer, chunk);
38
+
39
+ expect(results).toEqual([{ message: 'hello' }]);
40
+ });
41
+
42
+ it('should handle multiple SSE data lines', async () => {
43
+ const transformer = createSSEDataExtractor();
44
+ const input = `data: {"message": "hello"}\ndata: {"message": "world"}\n`;
45
+ const chunk = stringToUint8Array(input);
46
+
47
+ const results = await processChunk(transformer, chunk);
48
+
49
+ expect(results).toEqual([{ message: 'hello' }, { message: 'world' }]);
50
+ });
51
+
52
+ it('should ignore non-data lines', async () => {
53
+ const transformer = createSSEDataExtractor();
54
+ const input = `id: 1\ndata: {"message": "hello"}\nevent: message\n`;
55
+ const chunk = stringToUint8Array(input);
56
+
57
+ const results = await processChunk(transformer, chunk);
58
+
59
+ expect(results).toEqual([{ message: 'hello' }]);
60
+ });
61
+
62
+ it('should skip [DONE] heartbeat messages', async () => {
63
+ const transformer = createSSEDataExtractor();
64
+ const input = `data: {"message": "hello"}\ndata: [DONE]\ndata: {"message": "world"}\n`;
65
+ const chunk = stringToUint8Array(input);
66
+
67
+ const results = await processChunk(transformer, chunk);
68
+
69
+ expect(results).toEqual([{ message: 'hello' }, { message: 'world' }]);
70
+ });
71
+
72
+ it('should handle invalid JSON gracefully', async () => {
73
+ const transformer = createSSEDataExtractor();
74
+ const input = `data: {"message": "hello"}\ndata: invalid-json\ndata: {"message": "world"}\n`;
75
+ const chunk = stringToUint8Array(input);
76
+
77
+ const results = await processChunk(transformer, chunk);
78
+
79
+ expect(results).toEqual([{ message: 'hello' }, { message: 'world' }]);
80
+ });
81
+
82
+ it('should handle empty data lines', async () => {
83
+ const transformer = createSSEDataExtractor();
84
+ const input = `data: \ndata: {"message": "hello"}\ndata: \n`;
85
+ const chunk = stringToUint8Array(input);
86
+
87
+ const results = await processChunk(transformer, chunk);
88
+
89
+ expect(results).toEqual([{ message: 'hello' }]);
90
+ });
91
+
92
+ it('should process large chunks of data correctly', async () => {
93
+ const transformer = createSSEDataExtractor();
94
+ const messages = Array(100)
95
+ .fill(null)
96
+ .map((_, i) => `data: {"message": "message${i}"}\n`)
97
+ .join('');
98
+ const chunk = stringToUint8Array(messages);
99
+
100
+ const results = await processChunk(transformer, chunk);
101
+
102
+ expect(results).toHaveLength(100);
103
+ expect(results[0]).toEqual({ message: 'message0' });
104
+ expect(results[99]).toEqual({ message: 'message99' });
105
+ });
106
+
107
+ describe('real world data', () => {
108
+ it('should convert azure ai data', async () => {
109
+ const chunks = [
110
+ `data: {"choices":[{"delta":{"content":"","reasoning_content":null,"role":"assistant","tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714651,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
111
+ `data: {"choices":[{"delta":{"content":"\u003cthink\u003e","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714651,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
112
+ `data: {"choices":[{"delta":{"content":"\n\n","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714651,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
113
+ `data: {"choices":[{"delta":{"content":"\u003c/think\u003e","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714651,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
114
+ `data: {"choices":[{"delta":{"content":"\n\n","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714651,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
115
+ `data: {"choices":[{"delta":{"content":"Hello","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714651,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
116
+ `data: {"choices":[{"delta":{"content":"!","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
117
+ `data: {"choices":[{"delta":{"content":" How","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
118
+ `data: {"choices":[{"delta":{"content":" can","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
119
+ `data: {"choices":[{"delta":{"content":" I","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
120
+ `data: {"choices":[{"delta":{"content":" assist","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
121
+ `data: {"choices":[{"delta":{"content":" you","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
122
+ `data: {"choices":[{"delta":{"content":" today","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
123
+ `data: {"choices":[{"delta":{"content":"?","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
124
+ `data: {"choices":[{"delta":{"content":" ","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
125
+ `data: {"choices":[{"delta":{"content":"😊","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":null,"index":0,"logprobs":null,"matched_stop":null}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
126
+ `data: {"choices":[{"delta":{"content":"","reasoning_content":null,"role":null,"tool_calls":null},"finish_reason":"stop","index":0,"logprobs":null,"matched_stop":1}],"created":1739714652,"id":"1392a93d52c3483ea872d0ab2aaff7d7","model":"DeepSeek-R1","object":"chat.completion.chunk","usage":null}\n`,
127
+ `data: {"choices":[],"id":"79fca0de792a4ffb8ec836442a2a42c0","model":"DeepSeek-R1","usage":{"completion_tokens":16,"prompt_tokens":4,"total_tokens":20}}\n`,
128
+ `data: [DONE]`,
129
+ ];
130
+
131
+ const transformer = createSSEDataExtractor();
132
+
133
+ const results = await processChunk(transformer, stringToUint8Array(chunks.join('')));
134
+ expect(results).matchSnapshot();
135
+ });
136
+ });
137
+ });
@@ -170,3 +170,37 @@ export const createFirstErrorHandleTransformer = (
170
170
  },
171
171
  });
172
172
  };
173
+
174
+ /**
175
+ * create a transformer to remove SSE format data
176
+ */
177
+ export const createSSEDataExtractor = () =>
178
+ new TransformStream({
179
+ transform(chunk: Uint8Array, controller) {
180
+ // 将 Uint8Array 转换为字符串
181
+ const text = new TextDecoder().decode(chunk, { stream: true });
182
+
183
+ // 处理多行数据的情况
184
+ const lines = text.split('\n');
185
+
186
+ for (const line of lines) {
187
+ // 只处理以 "data: " 开头的行
188
+ if (line.startsWith('data: ')) {
189
+ // 提取 "data: " 后面的实际数据
190
+ const jsonText = line.slice(6);
191
+
192
+ // 跳过心跳消息
193
+ if (jsonText === '[DONE]') continue;
194
+
195
+ try {
196
+ // 解析 JSON 数据
197
+ const data = JSON.parse(jsonText);
198
+ // 将解析后的数据传递给下一个处理器
199
+ controller.enqueue(data);
200
+ } catch {
201
+ console.warn('Failed to parse SSE data:', jsonText);
202
+ }
203
+ }
204
+ }
205
+ },
206
+ });
@@ -19,6 +19,25 @@ export default {
19
19
  title: 'API Key',
20
20
  },
21
21
  },
22
+ azureai: {
23
+ azureApiVersion: {
24
+ desc: 'Azure 的 API 版本,遵循 YYYY-MM-DD 格式,查阅[最新版本](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions)',
25
+ fetch: '获取列表',
26
+ title: 'Azure API Version',
27
+ },
28
+ endpoint: {
29
+ desc: '从 Azure AI 项目概述找到 Azure AI 模型推理终结点',
30
+ placeholder: 'https://ai-userxxxxxxxxxx.services.ai.azure.com/models',
31
+ title: 'Azure AI 终结点',
32
+ },
33
+ title: 'Azure OpenAI',
34
+ token: {
35
+ desc: '从 Azure AI 项目概述找到 API 密钥',
36
+ placeholder: 'Azure 密钥',
37
+ title: '密钥',
38
+ },
39
+ },
40
+
22
41
  bedrock: {
23
42
  accessKeyId: {
24
43
  desc: '填入 AWS Access Key Id',
@@ -98,6 +117,7 @@ export default {
98
117
  title: '代理地址',
99
118
  },
100
119
  sdkType: {
120
+ placeholder: 'openai/anthropic/azureai/ollama/...',
101
121
  required: '请选择 SDK 类型',
102
122
  title: '请求格式',
103
123
  },
@@ -211,6 +231,11 @@ export default {
211
231
  placeholder: '请输入 Azure 中的模型部署名称',
212
232
  title: '模型部署名称',
213
233
  },
234
+ deployName: {
235
+ extra: '发送请求时会将该字段作为模型 ID',
236
+ placeholder: '请输入模型实际部署的名称或 id',
237
+ title: '模型部署名称',
238
+ },
214
239
  displayName: {
215
240
  placeholder: '请输入模型的展示名称,例如 ChatGPT、GPT-4 等',
216
241
  title: '模型展示名称',
@@ -57,6 +57,13 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {
57
57
  return { apiKey, apiVersion, baseURL };
58
58
  }
59
59
 
60
+ case ModelProvider.AzureAI: {
61
+ const { AZUREAI_ENDPOINT, AZUREAI_ENDPOINT_KEY } = llmConfig;
62
+ const apiKey = payload?.apiKey || AZUREAI_ENDPOINT_KEY;
63
+ const baseURL = payload?.baseURL || AZUREAI_ENDPOINT;
64
+ return { apiKey, baseURL };
65
+ }
66
+
60
67
  case ModelProvider.Bedrock: {
61
68
  const { AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, AWS_REGION, AWS_SESSION_TOKEN } = llmConfig;
62
69
  let accessKeyId: string | undefined = AWS_ACCESS_KEY_ID;
@@ -100,7 +107,7 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {
100
107
 
101
108
  return { apiKey };
102
109
  }
103
-
110
+
104
111
  case ModelProvider.TencentCloud: {
105
112
  const { TENCENT_CLOUD_API_KEY } = llmConfig;
106
113