@lobehub/chat 1.19.5 → 1.19.7

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,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.19.7](https://github.com/lobehub/lobe-chat/compare/v1.19.6...v1.19.7)
6
+
7
+ <sup>Released on **2024-09-19**</sup>
8
+
9
+ #### 💄 Styles
10
+
11
+ - **misc**: Add siliconflow qwen2.5 model.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Styles
19
+
20
+ - **misc**: Add siliconflow qwen2.5 model, closes [#4024](https://github.com/lobehub/lobe-chat/issues/4024) ([06ffd99](https://github.com/lobehub/lobe-chat/commit/06ffd99))
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
+
30
+ ### [Version 1.19.6](https://github.com/lobehub/lobe-chat/compare/v1.19.5...v1.19.6)
31
+
32
+ <sup>Released on **2024-09-19**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: Refactor the tts route url.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Code refactoring
44
+
45
+ - **misc**: Refactor the tts route url, closes [#4030](https://github.com/lobehub/lobe-chat/issues/4030) ([60dcf19](https://github.com/lobehub/lobe-chat/commit/60dcf19))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.19.5](https://github.com/lobehub/lobe-chat/compare/v1.19.4...v1.19.5)
6
56
 
7
57
  <sup>Released on **2024-09-19**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.19.5",
3
+ "version": "1.19.7",
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",
@@ -8,6 +8,7 @@ import { checkAuth } from './auth';
8
8
  import { createOpenai } from './createOpenai';
9
9
 
10
10
  /**
11
+ * @deprecated
11
12
  * createOpenAI Instance with Auth and azure openai support
12
13
  * if auth not pass ,just return error response
13
14
  */
@@ -28,6 +28,7 @@ export const preferredRegion = [
28
28
  export const POST = async (req: Request) => {
29
29
  const payload = (await req.json()) as OpenAITTSPayload;
30
30
 
31
+ // need to be refactored with jwt auth mode
31
32
  const openaiOrErrResponse = createBizOpenAI(req);
32
33
 
33
34
  // if resOrOpenAI is a Response, it means there is an error,just return it
@@ -43,9 +43,33 @@ const Qwen: ModelProviderCard = {
43
43
  },
44
44
  tokens: 32_768,
45
45
  },
46
+ {
47
+ description:
48
+ '通义千问数学模型是专门用于数学解题的语言模型。',
49
+ displayName: 'Qwen Math Turbo',
50
+ id: 'qwen-math-turbo-latest',
51
+ pricing: {
52
+ currency: 'CNY',
53
+ input: 2,
54
+ output: 6,
55
+ },
56
+ tokens: 4096,
57
+ },
58
+ {
59
+ description:
60
+ '通义千问数学模型是专门用于数学解题的语言模型。',
61
+ displayName: 'Qwen Math Plus',
62
+ id: 'qwen-math-plus-latest',
63
+ pricing: {
64
+ currency: 'CNY',
65
+ input: 4,
66
+ output: 12,
67
+ },
68
+ tokens: 4096,
69
+ },
46
70
  {
47
71
  description: '通义千问代码模型。',
48
- displayName: 'Qwen Coder',
72
+ displayName: 'Qwen Coder Turbo',
49
73
  id: 'qwen-coder-turbo-latest',
50
74
  pricing: {
51
75
  currency: 'CNY',
@@ -94,35 +118,16 @@ const Qwen: ModelProviderCard = {
94
118
  tokens: 32_000,
95
119
  vision: true,
96
120
  },
97
- {
98
- description:
99
- '通义千问数学模型是专门用于数学解题的语言模型。',
100
- displayName: 'Qwen Math Turbo',
101
- id: 'qwen-math-turbo-latest',
102
- pricing: {
103
- currency: 'CNY',
104
- input: 2,
105
- output: 6,
106
- },
107
- tokens: 4096,
108
- },
109
- {
110
- description:
111
- '通义千问数学模型是专门用于数学解题的语言模型。',
112
- displayName: 'Qwen Math Plus',
113
- id: 'qwen-math-plus-latest',
114
- pricing: {
115
- currency: 'CNY',
116
- input: 4,
117
- output: 12,
118
- },
119
- tokens: 4096,
120
- },
121
121
  {
122
122
  description: '通义千问2.5对外开源的7B规模的模型。',
123
123
  displayName: 'Qwen2.5 7B',
124
124
  functionCall: true,
125
125
  id: 'qwen2.5-7b-instruct',
126
+ pricing: {
127
+ currency: 'CNY',
128
+ input: 1,
129
+ output: 2,
130
+ },
126
131
  tokens: 131_072,
127
132
  },
128
133
  {
@@ -130,6 +135,11 @@ const Qwen: ModelProviderCard = {
130
135
  displayName: 'Qwen2.5 14B',
131
136
  functionCall: true,
132
137
  id: 'qwen2.5-14b-instruct',
138
+ pricing: {
139
+ currency: 'CNY',
140
+ input: 2,
141
+ output: 6,
142
+ },
133
143
  tokens: 131_072,
134
144
  },
135
145
  {
@@ -137,6 +147,11 @@ const Qwen: ModelProviderCard = {
137
147
  displayName: 'Qwen2.5 32B',
138
148
  functionCall: true,
139
149
  id: 'qwen2.5-32b-instruct',
150
+ pricing: {
151
+ currency: 'CNY',
152
+ input: 3.5,
153
+ output: 7,
154
+ },
140
155
  tokens: 131_072,
141
156
  },
142
157
  {
@@ -144,15 +159,13 @@ const Qwen: ModelProviderCard = {
144
159
  displayName: 'Qwen2.5 72B',
145
160
  functionCall: true,
146
161
  id: 'qwen2.5-72b-instruct',
162
+ pricing: {
163
+ currency: 'CNY',
164
+ input: 4,
165
+ output: 12,
166
+ },
147
167
  tokens: 131_072,
148
168
  },
149
- {
150
- description: '通义千问2对外开源的57B规模14B激活参数的MOE模型。',
151
- displayName: 'Qwen2 57B A14B MoE',
152
- functionCall: true,
153
- id: 'qwen2-57b-a14b-instruct',
154
- tokens: 65_536,
155
- },
156
169
  {
157
170
  description: 'Qwen-Math 模型具有强大的数学解题能力。',
158
171
  displayName: 'Qwen2.5 Math 1.5B',
@@ -168,12 +181,22 @@ const Qwen: ModelProviderCard = {
168
181
  description: 'Qwen-Math 模型具有强大的数学解题能力。',
169
182
  displayName: 'Qwen2.5 Math 7B',
170
183
  id: 'qwen2.5-math-7b-instruct',
184
+ pricing: {
185
+ currency: 'CNY',
186
+ input: 1,
187
+ output: 2,
188
+ },
171
189
  tokens: 4096,
172
190
  },
173
191
  {
174
192
  description: 'Qwen-Math 模型具有强大的数学解题能力。',
175
193
  displayName: 'Qwen2.5 Math 72B',
176
194
  id: 'qwen2.5-math-72b-instruct',
195
+ pricing: {
196
+ currency: 'CNY',
197
+ input: 4,
198
+ output: 12,
199
+ },
177
200
  tokens: 4096,
178
201
  },
179
202
  {
@@ -191,12 +214,22 @@ const Qwen: ModelProviderCard = {
191
214
  description: '通义千问代码模型开源版。',
192
215
  displayName: 'Qwen2.5 Coder 7B',
193
216
  id: 'qwen2.5-coder-7b-instruct',
217
+ pricing: {
218
+ currency: 'CNY',
219
+ input: 1,
220
+ output: 2,
221
+ },
194
222
  tokens: 131_072,
195
223
  },
196
224
  {
197
225
  description: '以 Qwen-7B 语言模型初始化,添加图像模型,图像输入分辨率为448的预训练模型。',
198
226
  displayName: 'Qwen VL',
199
227
  id: 'qwen-vl-v1',
228
+ pricing: {
229
+ currency: 'CNY',
230
+ input: 0,
231
+ output: 0,
232
+ },
200
233
  tokens: 8000,
201
234
  vision: true,
202
235
  },
@@ -204,11 +237,16 @@ const Qwen: ModelProviderCard = {
204
237
  description: '通义千问VL支持灵活的交互方式,包括多图、多轮问答、创作等能力的模型。',
205
238
  displayName: 'Qwen VL Chat',
206
239
  id: 'qwen-vl-chat-v1',
240
+ pricing: {
241
+ currency: 'CNY',
242
+ input: 0,
243
+ output: 0,
244
+ },
207
245
  tokens: 8000,
208
246
  vision: true,
209
247
  },
210
248
  ],
211
- checkModel: 'qwen-turbo',
249
+ checkModel: 'qwen-turbo-latest',
212
250
  description:
213
251
  '通义千问是阿里云自主研发的超大规模语言模型,具有强大的自然语言理解和生成能力。它可以回答各种问题、创作文字内容、表达观点看法、撰写代码等,在多个领域发挥作用。',
214
252
  disableBrowserRequest: true,
@@ -4,132 +4,160 @@ import { ModelProviderCard } from '@/types/llm';
4
4
  const SiliconCloud: ModelProviderCard = {
5
5
  chatModels: [
6
6
  {
7
- description: 'Qwen2 是全新的大型语言模型系列,旨在优化指令式任务的处理。',
8
- displayName: 'Qwen2 1.5B',
9
- id: 'Qwen/Qwen2-1.5B-Instruct',
7
+ description: 'DeepSeek V2.5 集合了先前版本的优秀特征,增强了通用和编码能力。',
8
+ displayName: 'DeepSeek V2.5',
9
+ enabled: true,
10
+ id: 'deepseek-ai/DeepSeek-V2.5',
11
+ pricing: {
12
+ currency: 'CNY',
13
+ input: 1.33,
14
+ output: 1.33,
15
+ },
10
16
  tokens: 32_768,
11
17
  },
12
18
  {
13
- description: 'Qwen2 是全新的大型语言模型系列,具有更强的理解和生成能力。',
14
- displayName: 'Qwen2 7B',
15
- enabled: true,
16
- id: 'Qwen/Qwen2-7B-Instruct',
19
+ description: 'DeepSeek V2 具备67亿参数,支持英中文本处理。',
20
+ displayName: 'DeepSeek V2 Chat',
21
+ id: 'deepseek-ai/DeepSeek-V2-Chat',
22
+ pricing: {
23
+ currency: 'CNY',
24
+ input: 1.33,
25
+ output: 1.33,
26
+ },
17
27
  tokens: 32_768,
18
28
  },
19
29
  {
20
- description: 'Qwen2 是全新的系列,57B A14B 型号在指令任务中表现卓越。',
21
- displayName: 'Qwen2 57B A14B',
22
- id: 'Qwen/Qwen2-57B-A14B-Instruct',
30
+ description: 'DeepSeek Coder V2 为代码任务设计, 专注于高效的代码生成。',
31
+ displayName: 'DeepSeek V2 Coder',
32
+ id: 'deepseek-ai/DeepSeek-Coder-V2-Instruct',
33
+ pricing: {
34
+ currency: 'CNY',
35
+ input: 1.33,
36
+ output: 1.33,
37
+ },
23
38
  tokens: 32_768,
24
39
  },
25
40
  {
26
- description: 'Qwen2 是先进的通用语言模型,支持多种指令类型。',
27
- displayName: 'Qwen2 72B',
28
- enabled: true,
29
- id: 'Qwen/Qwen2-72B-Instruct',
41
+ description: 'DeepSeek 67B 是为高复杂性对话训练的先进模型。',
42
+ displayName: 'DeepSeek LLM 67B',
43
+ id: 'deepseek-ai/deepseek-llm-67b-chat',
44
+ pricing: {
45
+ currency: 'CNY',
46
+ input: 1,
47
+ output: 1,
48
+ },
30
49
  tokens: 32_768,
31
50
  },
32
51
  {
33
- description: 'Qwen2-Math 专注于数学领域的问题求解,为高难度题提供专业解答。',
34
- displayName: 'Qwen2 Math 72B',
52
+ description: 'Qwen2.5 是全新的大型语言模型系列,旨在优化指令式任务的处理。',
53
+ displayName: 'Qwen2.5 7B',
35
54
  enabled: true,
36
- id: 'Qwen/Qwen2-Math-72B-Instruct',
55
+ id: 'Qwen/Qwen2.5-7B-Instruct',
56
+ pricing: {
57
+ currency: 'CNY',
58
+ input: 0,
59
+ output: 0,
60
+ },
37
61
  tokens: 32_768,
38
62
  },
39
63
  {
40
- description: 'Qwen1.5 通过结合高级预训练和微调提升对话表达能力。',
41
- displayName: 'Qwen1.5 7B',
42
- id: 'Qwen/Qwen1.5-7B-Chat',
64
+ description: 'Qwen2.5 是全新的大型语言模型系列,旨在优化指令式任务的处理。',
65
+ displayName: 'Qwen2.5 14B',
66
+ id: 'Qwen/Qwen2.5-14B-Instruct',
67
+ pricing: {
68
+ currency: 'CNY',
69
+ input: 0.7,
70
+ output: 0.7,
71
+ },
43
72
  tokens: 32_768,
44
73
  },
45
74
  {
46
- description: 'Qwen1.5 通过大规模数据集训练,擅长复杂的语言任务。',
47
- displayName: 'Qwen1.5 14B',
48
- id: 'Qwen/Qwen1.5-14B-Chat',
75
+ description: 'Qwen2.5 是全新的大型语言模型系列,旨在优化指令式任务的处理。',
76
+ displayName: 'Qwen2.5 32B',
77
+ id: 'Qwen/Qwen2.5-32B-Instruct',
78
+ pricing: {
79
+ currency: 'CNY',
80
+ input: 1.26,
81
+ output: 1.26,
82
+ },
49
83
  tokens: 32_768,
50
84
  },
51
85
  {
52
- description: 'Qwen1.5 具备多领域问答和文本生成的能力。',
53
- displayName: 'Qwen1.5 32B',
54
- id: 'Qwen/Qwen1.5-32B-Chat',
86
+ description: 'Qwen2.5 是全新的大型语言模型系列,具有更强的理解和生成能力。',
87
+ displayName: 'Qwen2.5 72B',
88
+ enabled: true,
89
+ id: 'Qwen/Qwen2.5-72B-Instruct',
90
+ pricing: {
91
+ currency: 'CNY',
92
+ input: 4.13,
93
+ output: 4.13,
94
+ },
55
95
  tokens: 32_768,
56
96
  },
57
97
  {
58
- description: '作为Qwen2 的测试版,Qwen1.5 使用大规模数据实现了更精确的对话功能。',
59
- displayName: 'Qwen1.5 110B',
60
- id: 'Qwen/Qwen1.5-110B-Chat',
98
+ description: 'Qwen2-Math 专注于数学领域的问题求解,为高难度题提供专业解答。',
99
+ displayName: 'Qwen2 Math 72B',
100
+ id: 'Qwen/Qwen2-Math-72B-Instruct',
101
+ pricing: {
102
+ currency: 'CNY',
103
+ input: 4.13,
104
+ output: 4.13,
105
+ },
61
106
  tokens: 32_768,
62
107
  },
63
- {
64
- description: 'Yi-1.5 是Yi系列的进化版本,拥有高质量的预训练和丰富的微调数据。',
65
- displayName: 'Yi-1.5 6B',
66
- id: '01-ai/Yi-1.5-6B-Chat',
67
- tokens: 4096,
68
- },
69
108
  {
70
109
  description: 'Yi-1.5 9B 支持16K Tokens, 提供高效、流畅的语言生成能力。',
71
110
  displayName: 'Yi-1.5 9B',
72
- enabled: true,
73
111
  id: '01-ai/Yi-1.5-9B-Chat-16K',
112
+ pricing: {
113
+ currency: 'CNY',
114
+ input: 0,
115
+ output: 0,
116
+ },
74
117
  tokens: 16_384,
75
118
  },
76
119
  {
77
120
  description: 'Yi-1.5 34B, 以丰富的训练样本在行业应用中提供优越表现。',
78
121
  displayName: 'Yi-1.5 34B',
79
- enabled: true,
80
122
  id: '01-ai/Yi-1.5-34B-Chat-16K',
123
+ pricing: {
124
+ currency: 'CNY',
125
+ input: 1.26,
126
+ output: 1.26,
127
+ },
81
128
  tokens: 16_384,
82
129
  },
83
- {
84
- description: '作为双语会话语言模型, ChatGLM3能处理中英文转换任务。',
85
- displayName: 'GLM-3 6B',
86
- id: 'THUDM/chatglm3-6b',
87
- tokens: 32_768,
88
- },
89
130
  {
90
131
  description: 'GLM-4 9B 开放源码版本,为会话应用提供优化后的对话体验。',
91
132
  displayName: 'GLM-4 9B',
92
- enabled: true,
93
133
  id: 'THUDM/glm-4-9b-chat',
134
+ pricing: {
135
+ currency: 'CNY',
136
+ input: 0,
137
+ output: 0,
138
+ },
94
139
  tokens: 32_768,
95
140
  },
96
141
  {
97
142
  description: 'InternLM2.5 提供多场景下的智能对话解决方案。',
98
143
  displayName: 'Internlm 2.5 7B',
99
- enabled: true,
100
144
  id: 'internlm/internlm2_5-7b-chat',
145
+ pricing: {
146
+ currency: 'CNY',
147
+ input: 0,
148
+ output: 0,
149
+ },
101
150
  tokens: 32_768,
102
151
  },
103
152
  {
104
153
  description: '创新的开源模型InternLM2.5,通过大规模的参数提高了对话智能。',
105
154
  displayName: 'Internlm 2.5 20B',
106
- enabled: true,
107
155
  id: 'internlm/internlm2_5-20b-chat',
108
- tokens: 32_768,
109
- },
110
- {
111
- description: 'DeepSeek V2.5 集合了先前版本的优秀特征,增强了通用和编码能力。',
112
- displayName: 'DeepSeek V2.5',
113
- enabled: true,
114
- id: 'deepseek-ai/DeepSeek-V2.5',
115
- tokens: 32_768,
116
- },
117
- {
118
- description: 'DeepSeek V2 具备67亿参数,支持英中文本处理。',
119
- displayName: 'DeepSeek V2 Chat',
120
- id: 'deepseek-ai/DeepSeek-V2-Chat',
121
- tokens: 32_768,
122
- },
123
- {
124
- description: 'DeepSeek Coder V2 为代码任务设计, 专注于高效的代码生成。',
125
- displayName: 'DeepSeek V2 Coder',
126
- id: 'deepseek-ai/DeepSeek-Coder-V2-Instruct',
127
- tokens: 32_768,
128
- },
129
- {
130
- description: 'DeepSeek 67B 是为高复杂性对话训练的先进模型。',
131
- displayName: 'DeepSeek LLM 67B',
132
- id: 'deepseek-ai/deepseek-llm-67b-chat',
156
+ pricing: {
157
+ currency: 'CNY',
158
+ input: 1,
159
+ output: 1,
160
+ },
133
161
  tokens: 32_768,
134
162
  },
135
163
  {
@@ -137,6 +165,11 @@ const SiliconCloud: ModelProviderCard = {
137
165
  displayName: 'Gemma 2 9B',
138
166
  enabled: true,
139
167
  id: 'google/gemma-2-9b-it',
168
+ pricing: {
169
+ currency: 'CNY',
170
+ input: 0,
171
+ output: 0,
172
+ },
140
173
  tokens: 8192,
141
174
  },
142
175
  {
@@ -144,6 +177,11 @@ const SiliconCloud: ModelProviderCard = {
144
177
  displayName: 'Gemma 2 27B',
145
178
  enabled: true,
146
179
  id: 'google/gemma-2-27b-it',
180
+ pricing: {
181
+ currency: 'CNY',
182
+ input: 1.26,
183
+ output: 1.26,
184
+ },
147
185
  tokens: 8192,
148
186
  },
149
187
  {
@@ -151,6 +189,11 @@ const SiliconCloud: ModelProviderCard = {
151
189
  displayName: 'Llama 3.1 8B',
152
190
  enabled: true,
153
191
  id: 'meta-llama/Meta-Llama-3.1-8B-Instruct',
192
+ pricing: {
193
+ currency: 'CNY',
194
+ input: 0,
195
+ output: 0,
196
+ },
154
197
  tokens: 32_768,
155
198
  },
156
199
  {
@@ -158,6 +201,11 @@ const SiliconCloud: ModelProviderCard = {
158
201
  displayName: 'Llama 3.1 70B',
159
202
  enabled: true,
160
203
  id: 'meta-llama/Meta-Llama-3.1-70B-Instruct',
204
+ pricing: {
205
+ currency: 'CNY',
206
+ input: 4.13,
207
+ output: 4.13,
208
+ },
161
209
  tokens: 32_768,
162
210
  },
163
211
  {
@@ -165,24 +213,11 @@ const SiliconCloud: ModelProviderCard = {
165
213
  displayName: 'Llama 3.1 405B',
166
214
  enabled: true,
167
215
  id: 'meta-llama/Meta-Llama-3.1-405B-Instruct',
168
- tokens: 32_768,
169
- },
170
- {
171
- description: 'LLaMA 3 支持大容量文本生成和指令解析。',
172
- displayName: 'Llama 3 70B',
173
- id: 'meta-llama/Meta-Llama-3-70B-Instruct',
174
- tokens: 8192,
175
- },
176
- {
177
- description: 'Mistral 7B 指令微调模型针对对话场景进行了优化,可用于文本生成和对话任务。',
178
- displayName: 'Mistral 7B',
179
- id: 'mistralai/Mistral-7B-Instruct-v0.2',
180
- tokens: 32_768,
181
- },
182
- {
183
- description: 'Mixtral 8x7B 模型支持多语言输入和输出,可用于文本生成和对话任务。',
184
- displayName: 'Mistral 8x7B',
185
- id: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
216
+ pricing: {
217
+ currency: 'CNY',
218
+ input: 21,
219
+ output: 21,
220
+ },
186
221
  tokens: 32_768,
187
222
  },
188
223
  ],
@@ -1,5 +1,6 @@
1
1
  export const OPENAI_END_POINT = 'X-openai-end-point';
2
2
  export const OPENAI_API_KEY_HEADER_KEY = 'X-openai-api-key';
3
+ export const LOBE_USER_ID = 'X-lobe-user-id';
3
4
 
4
5
  export const USE_AZURE_OPENAI = 'X-use-azure-openai';
5
6
 
@@ -19,9 +20,10 @@ export const getOpenAIAuthFromRequest = (req: Request) => {
19
20
  const useAzureStr = req.headers.get(USE_AZURE_OPENAI);
20
21
  const apiVersion = req.headers.get(AZURE_OPENAI_API_VERSION);
21
22
  const oauthAuthorizedStr = req.headers.get(OAUTH_AUTHORIZED);
23
+ const userId = req.headers.get(LOBE_USER_ID);
22
24
 
23
25
  const oauthAuthorized = !!oauthAuthorizedStr;
24
26
  const useAzure = !!useAzureStr;
25
27
 
26
- return { accessCode, apiKey, apiVersion, endpoint, oauthAuthorized, useAzure };
28
+ return { accessCode, apiKey, apiVersion, endpoint, oauthAuthorized, useAzure, userId };
27
29
  };
@@ -35,6 +35,7 @@ import {
35
35
  EmbeddingsPayload,
36
36
  ModelProvider,
37
37
  TextToImagePayload,
38
+ TextToSpeechPayload,
38
39
  } from './types';
39
40
  import { LobeUpstageAI } from './upstage';
40
41
  import { LobeZeroOneAI } from './zeroone';
@@ -97,6 +98,9 @@ class AgentRuntime {
97
98
  async embeddings(payload: EmbeddingsPayload, options?: EmbeddingsOptions) {
98
99
  return this._runtime.embeddings?.(payload, options);
99
100
  }
101
+ async textToSpeech(payload: TextToSpeechPayload, options?: EmbeddingsOptions) {
102
+ return this._runtime.textToSpeech?.(payload, options);
103
+ }
100
104
 
101
105
  /**
102
106
  * @description Initialize the runtime with the provider and the options
@@ -1,6 +1,5 @@
1
1
  import OpenAI from 'openai';
2
2
 
3
- import { TextToImagePayload } from '@/libs/agent-runtime/types/textToImage';
4
3
  import { ChatModelCard } from '@/types/llm';
5
4
 
6
5
  import {
@@ -9,6 +8,9 @@ import {
9
8
  EmbeddingItem,
10
9
  EmbeddingsOptions,
11
10
  EmbeddingsPayload,
11
+ TextToImagePayload,
12
+ TextToSpeechOptions,
13
+ TextToSpeechPayload,
12
14
  } from './types';
13
15
 
14
16
  export interface LobeRuntimeAI {
@@ -20,6 +22,11 @@ export interface LobeRuntimeAI {
20
22
  models?(): Promise<any>;
21
23
 
22
24
  textToImage?: (payload: TextToImagePayload) => Promise<string[]>;
25
+
26
+ textToSpeech?: (
27
+ payload: TextToSpeechPayload,
28
+ options?: TextToSpeechOptions,
29
+ ) => Promise<ArrayBuffer>;
23
30
  }
24
31
 
25
32
  export abstract class LobeOpenAICompatibleRuntime {
@@ -1,4 +1,5 @@
1
1
  export * from './chat';
2
2
  export * from './embeddings';
3
3
  export * from './textToImage';
4
+ export * from './tts';
4
5
  export * from './type';
@@ -0,0 +1,14 @@
1
+ export interface TextToSpeechPayload {
2
+ input: string;
3
+ model: string;
4
+ voice: string;
5
+ }
6
+
7
+ export interface TextToSpeechOptions {
8
+ headers?: Record<string, any>;
9
+ signal?: AbortSignal;
10
+ /**
11
+ * userId for the embeddings
12
+ */
13
+ user?: string;
14
+ }
@@ -1,7 +1,6 @@
1
1
  import OpenAI, { ClientOptions } from 'openai';
2
2
 
3
3
  import { LOBE_DEFAULT_MODEL_LIST } from '@/config/modelProviders';
4
- import { TextToImagePayload } from '@/libs/agent-runtime/types/textToImage';
5
4
  import { ChatModelCard } from '@/types/llm';
6
5
 
7
6
  import { LobeRuntimeAI } from '../../BaseAI';
@@ -13,6 +12,9 @@ import {
13
12
  EmbeddingItem,
14
13
  EmbeddingsOptions,
15
14
  EmbeddingsPayload,
15
+ TextToImagePayload,
16
+ TextToSpeechOptions,
17
+ TextToSpeechPayload,
16
18
  } from '../../types';
17
19
  import { AgentRuntimeError } from '../createError';
18
20
  import { debugResponse, debugStream } from '../debugStream';
@@ -253,6 +255,19 @@ export const LobeOpenAICompatibleFactory = <T extends Record<string, any> = any>
253
255
  }
254
256
  }
255
257
 
258
+ async textToSpeech(payload: TextToSpeechPayload, options?: TextToSpeechOptions) {
259
+ try {
260
+ const mp3 = await this.client.audio.speech.create(payload as any, {
261
+ headers: options?.headers,
262
+ signal: options?.signal,
263
+ });
264
+
265
+ return mp3.arrayBuffer();
266
+ } catch (error) {
267
+ throw this.handleError(error);
268
+ }
269
+ }
270
+
256
271
  private handleError(error: any): ChatCompletionErrorPayload {
257
272
  let desensitizedEndpoint = this.baseURL;
258
273
 
@@ -1,4 +1,9 @@
1
- import { LOBE_CHAT_ACCESS_CODE, OPENAI_API_KEY_HEADER_KEY, OPENAI_END_POINT } from '@/const/fetch';
1
+ import {
2
+ LOBE_CHAT_ACCESS_CODE,
3
+ LOBE_USER_ID,
4
+ OPENAI_API_KEY_HEADER_KEY,
5
+ OPENAI_END_POINT,
6
+ } from '@/const/fetch';
2
7
  import { useUserStore } from '@/store/user';
3
8
  import { keyVaultsConfigSelectors } from '@/store/user/selectors';
4
9
 
@@ -8,12 +13,14 @@ import { keyVaultsConfigSelectors } from '@/store/user/selectors';
8
13
  */
9
14
  // eslint-disable-next-line no-undef
10
15
  export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
11
- const openAIConfig = keyVaultsConfigSelectors.openAIConfig(useUserStore.getState());
16
+ const state = useUserStore.getState();
17
+ const openAIConfig = keyVaultsConfigSelectors.openAIConfig(state);
12
18
 
13
19
  // eslint-disable-next-line no-undef
14
20
  return {
15
21
  ...header,
16
- [LOBE_CHAT_ACCESS_CODE]: keyVaultsConfigSelectors.password(useUserStore.getState()),
22
+ [LOBE_CHAT_ACCESS_CODE]: keyVaultsConfigSelectors.password(state),
23
+ [LOBE_USER_ID]: state.user?.id || '',
17
24
  [OPENAI_API_KEY_HEADER_KEY]: openAIConfig.apiKey || '',
18
25
  [OPENAI_END_POINT]: openAIConfig.baseURL || '',
19
26
  };
@@ -1,4 +1,4 @@
1
- // TODO: 未来所有路由需要全部迁移到 trpc
1
+ // TODO: 未来路由需要迁移到 trpc or /webapi
2
2
 
3
3
  /* eslint-disable sort-keys-fix/sort-keys-fix */
4
4
  import { transform } from 'lodash-es';
@@ -38,9 +38,11 @@ export const API_ENDPOINTS = mapWithBasePath({
38
38
  // image
39
39
  images: '/api/text-to-image/openai',
40
40
 
41
- // TTS & STT
42
- stt: '/api/openai/stt',
43
- tts: '/api/openai/tts',
44
- edge: '/api/tts/edge-speech',
45
- microsoft: '/api/tts/microsoft-speech',
41
+ // STT
42
+ stt: '/webapi/stt/openai',
43
+
44
+ // TTS
45
+ tts: '/webapi/tts/openai',
46
+ edge: '/webapi/tts/edge',
47
+ microsoft: '/webapi/tts/microsoft',
46
48
  });
@@ -39,7 +39,7 @@ export const createTTSFileSlice: StateCreator<
39
39
  };
40
40
  const file = new File([blob], fileName, fileOptions);
41
41
 
42
- const res = await get().uploadWithProgress({ file });
42
+ const res = await get().uploadWithProgress({ file, skipCheckFileType: true });
43
43
 
44
44
  return res?.id;
45
45
  },
@@ -29,6 +29,12 @@ interface UploadWithProgressParams {
29
29
  type: 'removeFile';
30
30
  },
31
31
  ) => void;
32
+ /**
33
+ * Optional flag to indicate whether to skip the file type check.
34
+ * When set to `true`, any file type checks will be bypassed.
35
+ * Default is `false`, which means file type checks will be performed.
36
+ */
37
+ skipCheckFileType?: boolean;
32
38
  }
33
39
 
34
40
  interface UploadWithProgressResult {
@@ -52,8 +58,8 @@ export const createFileUploadSlice: StateCreator<
52
58
  [],
53
59
  FileUploadAction
54
60
  > = (set, get) => ({
55
- internal_uploadToClientDB: async ({ file, onStatusUpdate }) => {
56
- if (!file.type.startsWith('image')) {
61
+ internal_uploadToClientDB: async ({ file, onStatusUpdate, skipCheckFileType }) => {
62
+ if (!skipCheckFileType && !file.type.startsWith('image')) {
57
63
  onStatusUpdate?.({ id: file.name, type: 'removeFile' });
58
64
  message.info({
59
65
  content: t('upload.fileOnlySupportInServerMode', {
@@ -158,11 +164,11 @@ export const createFileUploadSlice: StateCreator<
158
164
  return data;
159
165
  },
160
166
 
161
- uploadWithProgress: async ({ file, onStatusUpdate, knowledgeBaseId }) => {
167
+ uploadWithProgress: async (payload) => {
162
168
  const { internal_uploadToServer, internal_uploadToClientDB } = get();
163
169
 
164
- if (isServerMode) return internal_uploadToServer({ file, knowledgeBaseId, onStatusUpdate });
170
+ if (isServerMode) return internal_uploadToServer(payload);
165
171
 
166
- return internal_uploadToClientDB({ file, onStatusUpdate });
172
+ return internal_uploadToClientDB(payload);
167
173
  },
168
174
  });