@lobehub/chat 1.47.6 → 1.47.8

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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "image": "mcr.microsoft.com/devcontainers/universal:2",
3
+ "features": {
4
+ "ghcr.io/devcontainers/features/node:1": {}
5
+ }
6
+ }
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.47.8](https://github.com/lobehub/lobe-chat/compare/v1.47.7...v1.47.8)
6
+
7
+ <sup>Released on **2025-01-20**</sup>
8
+
9
+ #### 💄 Styles
10
+
11
+ - **misc**: Add deepseek r1 model.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Styles
19
+
20
+ - **misc**: Add deepseek r1 model, closes [#5520](https://github.com/lobehub/lobe-chat/issues/5520) ([414477f](https://github.com/lobehub/lobe-chat/commit/414477f))
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.47.7](https://github.com/lobehub/lobe-chat/compare/v1.47.6...v1.47.7)
31
+
32
+ <sup>Released on **2025-01-20**</sup>
33
+
34
+ #### ♻ Code Refactoring
35
+
36
+ - **misc**: Remove redundant payload remapping in client-fetch.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### Code refactoring
44
+
45
+ - **misc**: Remove redundant payload remapping in client-fetch, closes [#5267](https://github.com/lobehub/lobe-chat/issues/5267) ([0c7dd82](https://github.com/lobehub/lobe-chat/commit/0c7dd82))
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.47.6](https://github.com/lobehub/lobe-chat/compare/v1.47.5...v1.47.6)
6
56
 
7
57
  <sup>Released on **2025-01-20**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,22 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "improvements": [
5
+ "Add deepseek r1 model."
6
+ ]
7
+ },
8
+ "date": "2025-01-20",
9
+ "version": "1.47.8"
10
+ },
11
+ {
12
+ "children": {
13
+ "improvements": [
14
+ "Remove redundant payload remapping in client-fetch."
15
+ ]
16
+ },
17
+ "date": "2025-01-20",
18
+ "version": "1.47.7"
19
+ },
2
20
  {
3
21
  "children": {
4
22
  "improvements": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.47.6",
3
+ "version": "1.47.8",
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",
@@ -20,6 +20,22 @@ const deepseekChatModels: AIChatModelCard[] = [
20
20
  releasedAt: '2024-12-26',
21
21
  type: 'chat',
22
22
  },
23
+ {
24
+ contextWindowTokens: 65_536,
25
+ description:
26
+ 'DeepSeek 推出的推理模型。在输出最终回答之前,模型会先输出一段思维链内容,以提升最终答案的准确性。',
27
+ displayName: 'DeepSeek R1',
28
+ enabled: true,
29
+ id: 'deepseek-reasoner',
30
+ pricing: {
31
+ cachedInput: 1,
32
+ currency: 'CNY',
33
+ input: 4,
34
+ output: 16,
35
+ },
36
+ releasedAt: '2025-01-20',
37
+ type: 'chat',
38
+ },
23
39
  ];
24
40
 
25
41
  export const allModels = [...deepseekChatModels];
@@ -11,14 +11,29 @@ const DeepSeek: ModelProviderCard = {
11
11
  enabled: true,
12
12
  functionCall: true,
13
13
  id: 'deepseek-chat',
14
- pricing: {
15
- cachedInput: 0.5,
14
+ pricing: { // 2025.2.9 之后涨价
15
+ cachedInput: 0.1,
16
16
  currency: 'CNY',
17
- input: 2,
18
- output: 8,
17
+ input: 1,
18
+ output: 2,
19
19
  },
20
20
  releasedAt: '2024-12-26',
21
21
  },
22
+ {
23
+ contextWindowTokens: 65_536,
24
+ description:
25
+ 'DeepSeek 推出的推理模型。在输出最终回答之前,模型会先输出一段思维链内容,以提升最终答案的准确性。',
26
+ displayName: 'DeepSeek R1',
27
+ enabled: true,
28
+ id: 'deepseek-reasoner',
29
+ pricing: {
30
+ cachedInput: 1,
31
+ currency: 'CNY',
32
+ input: 4,
33
+ output: 16,
34
+ },
35
+ releasedAt: '2025-01-20',
36
+ },
22
37
  ],
23
38
  checkModel: 'deepseek-chat',
24
39
  description:
@@ -1,8 +1,30 @@
1
- import { ModelProvider } from '../types';
1
+ import OpenAI from 'openai';
2
+
3
+ import { ChatStreamPayload, ModelProvider } from '../types';
2
4
  import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
3
5
 
4
6
  export const LobeDeepSeekAI = LobeOpenAICompatibleFactory({
5
7
  baseURL: 'https://api.deepseek.com/v1',
8
+ chatCompletion: {
9
+ handlePayload: ({ frequency_penalty, model, presence_penalty, temperature, top_p, ...payload }: ChatStreamPayload) =>
10
+ ({
11
+ ...payload,
12
+ model,
13
+ ...(model === 'deepseek-reasoner'
14
+ ? {
15
+ frequency_penalty: undefined,
16
+ presence_penalty: undefined,
17
+ temperature: undefined,
18
+ top_p: undefined,
19
+ }
20
+ : {
21
+ frequency_penalty,
22
+ presence_penalty,
23
+ temperature,
24
+ top_p,
25
+ }),
26
+ }) as OpenAI.ChatCompletionCreateParamsStreaming,
27
+ },
6
28
  debug: {
7
29
  chatCompletion: () => process.env.DEBUG_DEEPSEEK_CHAT_COMPLETION === '1',
8
30
  },
@@ -92,6 +92,11 @@ describe('getProviderAuthPayload', () => {
92
92
  awsAccessKeyId: mockBedrockConfig.accessKeyId,
93
93
  awsRegion: mockBedrockConfig.region,
94
94
  awsSecretAccessKey: mockBedrockConfig.secretAccessKey,
95
+ accessKeyId: mockBedrockConfig.accessKeyId,
96
+ accessKeySecret: mockBedrockConfig.secretAccessKey,
97
+ awsSessionToken: undefined,
98
+ region: mockBedrockConfig.region,
99
+ sessionToken: undefined,
95
100
  });
96
101
  });
97
102
 
@@ -107,6 +112,7 @@ describe('getProviderAuthPayload', () => {
107
112
  expect(payload).toEqual({
108
113
  apiKey: mockAzureConfig.apiKey,
109
114
  azureApiVersion: mockAzureConfig.apiVersion,
115
+ apiVersion: mockAzureConfig.apiVersion,
110
116
  baseURL: mockAzureConfig.endpoint,
111
117
  });
112
118
  });
@@ -151,6 +157,24 @@ describe('getProviderAuthPayload', () => {
151
157
  });
152
158
  });
153
159
 
160
+ it('should return correct payload for Cloudflare provider', () => {
161
+ // 假设的 Cloudflare 配置
162
+ const mockCloudflareConfig = {
163
+ apiKey: 'cloudflare-api-key',
164
+ baseURLOrAccountID: 'cloudflare-base-url-or-account-id',
165
+ };
166
+ act(() => {
167
+ setModelProviderConfig('cloudflare', mockCloudflareConfig);
168
+ });
169
+
170
+ const payload = getProviderAuthPayload(ModelProvider.Cloudflare, mockCloudflareConfig);
171
+ expect(payload).toEqual({
172
+ apiKey: mockCloudflareConfig.apiKey,
173
+ baseURLOrAccountID: mockCloudflareConfig.baseURLOrAccountID,
174
+ cloudflareBaseURLOrAccountID: mockCloudflareConfig.baseURLOrAccountID,
175
+ });
176
+ });
177
+
154
178
  it('should return an empty object or throw an error for an unknown provider', () => {
155
179
  const payload = getProviderAuthPayload('UnknownProvider', {});
156
180
  expect(payload).toEqual({});
@@ -31,11 +31,19 @@ export const getProviderAuthPayload = (
31
31
  const apiKey = (awsSecretAccessKey || '') + (awsAccessKeyId || '');
32
32
 
33
33
  return {
34
+ accessKeyId,
35
+ accessKeySecret: awsSecretAccessKey,
34
36
  apiKey,
37
+ /** @deprecated */
35
38
  awsAccessKeyId,
39
+ /** @deprecated */
36
40
  awsRegion: region,
41
+ /** @deprecated */
37
42
  awsSecretAccessKey,
43
+ /** @deprecated */
38
44
  awsSessionToken: sessionToken,
45
+ region,
46
+ sessionToken,
39
47
  };
40
48
  }
41
49
 
@@ -54,7 +62,10 @@ export const getProviderAuthPayload = (
54
62
  case ModelProvider.Azure: {
55
63
  return {
56
64
  apiKey: keyVaults.apiKey,
57
- azureApiVersion: keyVaults.apiVersion,
65
+
66
+ apiVersion: keyVaults.apiVersion,
67
+ /** @deprecated */
68
+ azureApiVersion: keyVaults.apiVersion,
58
69
  baseURL: keyVaults.baseURL || keyVaults.endpoint,
59
70
  };
60
71
  }
@@ -66,7 +77,10 @@ export const getProviderAuthPayload = (
66
77
  case ModelProvider.Cloudflare: {
67
78
  return {
68
79
  apiKey: keyVaults?.apiKey,
69
- cloudflareBaseURLOrAccountID: keyVaults?.baseURLOrAccountID,
80
+
81
+ baseURLOrAccountID: keyVaults?.baseURLOrAccountID,
82
+ /** @deprecated */
83
+ cloudflareBaseURLOrAccountID: keyVaults?.baseURLOrAccountID,
70
84
  };
71
85
  }
72
86
 
@@ -124,90 +124,25 @@ interface CreateAssistantMessageStream extends FetchSSEOptions {
124
124
  * **Note**: if you try to fetch directly, use `fetchOnClient` instead.
125
125
  */
126
126
  export function initializeWithClientStore(provider: string, payload: any) {
127
- // add auth payload
127
+ /**
128
+ * Since #5267, we map parameters for client-fetch in function `getProviderAuthPayload`
129
+ * which called by `createPayloadWithKeyVaults` below.
130
+ * @see https://github.com/lobehub/lobe-chat/pull/5267
131
+ * @file src/services/_auth.ts
132
+ */
128
133
  const providerAuthPayload = { ...payload, ...createPayloadWithKeyVaults(provider) };
129
134
  const commonOptions = {
130
- // Some provider base openai sdk, so enable it run on browser
135
+ // Allow OpenAI SDK and Anthropic SDK run on browser
131
136
  dangerouslyAllowBrowser: true,
132
137
  };
133
- let providerOptions = {};
134
-
135
- switch (provider) {
136
- default:
137
- case ModelProvider.OpenAI: {
138
- providerOptions = {
139
- baseURL: providerAuthPayload?.baseURL,
140
- };
141
- break;
142
- }
143
- case ModelProvider.Azure: {
144
- providerOptions = {
145
- apiKey: providerAuthPayload?.apiKey,
146
- apiVersion: providerAuthPayload?.azureApiVersion,
147
- };
148
- break;
149
- }
150
- case ModelProvider.Google: {
151
- providerOptions = {
152
- baseURL: providerAuthPayload?.baseURL,
153
- };
154
- break;
155
- }
156
- case ModelProvider.Bedrock: {
157
- if (providerAuthPayload?.apiKey) {
158
- providerOptions = {
159
- accessKeyId: providerAuthPayload?.awsAccessKeyId,
160
- accessKeySecret: providerAuthPayload?.awsSecretAccessKey,
161
- region: providerAuthPayload?.awsRegion,
162
- sessionToken: providerAuthPayload?.awsSessionToken,
163
- };
164
- }
165
- break;
166
- }
167
- case ModelProvider.Ollama: {
168
- providerOptions = {
169
- baseURL: providerAuthPayload?.baseURL,
170
- };
171
- break;
172
- }
173
- case ModelProvider.Perplexity: {
174
- providerOptions = {
175
- apikey: providerAuthPayload?.apiKey,
176
- baseURL: providerAuthPayload?.baseURL,
177
- };
178
- break;
179
- }
180
- case ModelProvider.Anthropic: {
181
- providerOptions = {
182
- baseURL: providerAuthPayload?.baseURL,
183
- };
184
- break;
185
- }
186
- case ModelProvider.Groq: {
187
- providerOptions = {
188
- apikey: providerAuthPayload?.apiKey,
189
- baseURL: providerAuthPayload?.baseURL,
190
- };
191
- break;
192
- }
193
- case ModelProvider.Cloudflare: {
194
- providerOptions = {
195
- apikey: providerAuthPayload?.apiKey,
196
- baseURLOrAccountID: providerAuthPayload?.cloudflareBaseURLOrAccountID,
197
- };
198
- break;
199
- }
200
- }
201
-
202
138
  /**
203
139
  * Configuration override order:
204
- * payload -> providerOptions -> providerAuthPayload -> commonOptions
140
+ * payload -> providerAuthPayload -> commonOptions
205
141
  */
206
142
  return AgentRuntime.initializeWithProviderOptions(provider, {
207
143
  [provider]: {
208
144
  ...commonOptions,
209
145
  ...providerAuthPayload,
210
- ...providerOptions,
211
146
  ...payload,
212
147
  },
213
148
  });