@lobehub/chat 1.22.27 → 1.23.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/Dockerfile +17 -15
  3. package/Dockerfile.database +18 -16
  4. package/locales/ar/error.json +1 -1
  5. package/locales/ar/setting.json +7 -1
  6. package/locales/bg-BG/error.json +1 -1
  7. package/locales/bg-BG/setting.json +7 -1
  8. package/locales/de-DE/error.json +1 -1
  9. package/locales/de-DE/setting.json +7 -1
  10. package/locales/en-US/error.json +1 -1
  11. package/locales/en-US/setting.json +7 -1
  12. package/locales/es-ES/error.json +1 -1
  13. package/locales/es-ES/setting.json +7 -1
  14. package/locales/fr-FR/error.json +1 -1
  15. package/locales/fr-FR/setting.json +7 -1
  16. package/locales/it-IT/error.json +1 -1
  17. package/locales/it-IT/setting.json +7 -1
  18. package/locales/ja-JP/error.json +1 -1
  19. package/locales/ja-JP/setting.json +7 -1
  20. package/locales/ko-KR/error.json +1 -1
  21. package/locales/ko-KR/setting.json +7 -1
  22. package/locales/nl-NL/error.json +1 -1
  23. package/locales/nl-NL/setting.json +7 -1
  24. package/locales/pl-PL/error.json +1 -1
  25. package/locales/pl-PL/setting.json +7 -1
  26. package/locales/pt-BR/error.json +1 -1
  27. package/locales/pt-BR/setting.json +7 -1
  28. package/locales/ru-RU/error.json +1 -1
  29. package/locales/ru-RU/setting.json +7 -1
  30. package/locales/tr-TR/error.json +1 -1
  31. package/locales/tr-TR/setting.json +7 -1
  32. package/locales/vi-VN/error.json +1 -1
  33. package/locales/vi-VN/setting.json +7 -1
  34. package/locales/zh-CN/error.json +1 -1
  35. package/locales/zh-CN/setting.json +7 -1
  36. package/locales/zh-TW/error.json +1 -1
  37. package/locales/zh-TW/setting.json +7 -1
  38. package/package.json +2 -2
  39. package/src/app/(main)/settings/system-agent/features/createForm.tsx +90 -41
  40. package/src/app/(main)/settings/system-agent/index.tsx +15 -0
  41. package/src/chains/rewriteQuery.ts +3 -2
  42. package/src/components/TextArea/index.tsx +42 -0
  43. package/src/config/llm.ts +28 -0
  44. package/src/config/modelProviders/spark.ts +6 -6
  45. package/src/const/settings/systemAgent.ts +15 -2
  46. package/src/features/AgentSetting/AgentModal/ModelSelect.tsx +6 -2
  47. package/src/features/ModelSelect/index.tsx +5 -4
  48. package/src/features/User/UserPanel/useMenu.tsx +11 -11
  49. package/src/locales/default/setting.ts +7 -1
  50. package/src/server/globalConfig/index.ts +146 -16
  51. package/src/server/globalConfig/parseSystemAgent.ts +2 -1
  52. package/src/server/services/chunk/index.ts +2 -2
  53. package/src/store/chat/slices/aiChat/actions/rag.ts +13 -4
  54. package/src/store/user/slices/settings/action.ts +6 -3
  55. package/src/types/user/settings/systemAgent.ts +7 -1
@@ -1,15 +1,28 @@
1
- import { SystemAgentItem, UserSystemAgentConfig } from '@/types/user/settings';
1
+ import {
2
+ QueryRewriteSystemAgent,
3
+ SystemAgentItem,
4
+ UserSystemAgentConfig,
5
+ } from '@/types/user/settings';
2
6
 
3
7
  import { DEFAULT_MODEL, DEFAULT_PROVIDER } from './llm';
4
8
 
9
+ export const DEFAULT_REWRITE_QUERY =
10
+ 'Given the following conversation and a follow-up question, rephrase the follow up question to be a standalone question, in its original language. Keep as much details as possible from previous messages. Keep entity names and all.';
11
+
5
12
  export const DEFAULT_SYSTEM_AGENT_ITEM: SystemAgentItem = {
6
13
  model: DEFAULT_MODEL,
7
14
  provider: DEFAULT_PROVIDER,
8
15
  };
9
16
 
17
+ export const DEFAULT_QUERY_REWRITE_SYSTEM_AGENT_ITEM: QueryRewriteSystemAgent = {
18
+ enabled: true,
19
+ model: DEFAULT_MODEL,
20
+ provider: DEFAULT_PROVIDER,
21
+ };
22
+
10
23
  export const DEFAULT_SYSTEM_AGENT_CONFIG: UserSystemAgentConfig = {
11
24
  agentMeta: DEFAULT_SYSTEM_AGENT_ITEM,
12
- queryRewrite: DEFAULT_SYSTEM_AGENT_ITEM,
25
+ queryRewrite: DEFAULT_QUERY_REWRITE_SYSTEM_AGENT_ITEM,
13
26
  topic: DEFAULT_SYSTEM_AGENT_ITEM,
14
27
  translation: DEFAULT_SYSTEM_AGENT_ITEM,
15
28
  };
@@ -5,14 +5,18 @@ import Select from '@/features/ModelSelect';
5
5
  import { useStore } from '../store';
6
6
 
7
7
  const ModelSelect = memo(() => {
8
- const [model, updateConfig] = useStore((s) => [s.config.model, s.setAgentConfig]);
8
+ const [model, provider, updateConfig] = useStore((s) => [
9
+ s.config.model,
10
+ s.config.provider,
11
+ s.setAgentConfig,
12
+ ]);
9
13
 
10
14
  return (
11
15
  <Select
12
16
  onChange={(props) => {
13
17
  updateConfig(props);
14
18
  }}
15
- value={model}
19
+ value={{ model, provider }}
16
20
  />
17
21
  );
18
22
  });
@@ -25,7 +25,7 @@ interface ModelOption {
25
25
  interface ModelSelectProps {
26
26
  onChange?: (props: { model: string; provider: string }) => void;
27
27
  showAbility?: boolean;
28
- value?: string;
28
+ value?: { model: string; provider?: string };
29
29
  }
30
30
 
31
31
  const ModelSelect = memo<ModelSelectProps>(({ value, onChange, showAbility = true }) => {
@@ -38,7 +38,7 @@ const ModelSelect = memo<ModelSelectProps>(({ value, onChange, showAbility = tru
38
38
  provider.chatModels.map((model) => ({
39
39
  label: <ModelItemRender {...model} showInfoTag={showAbility} />,
40
40
  provider: provider.id,
41
- value: model.id,
41
+ value: `${provider.id}/${model.id}`,
42
42
  }));
43
43
 
44
44
  if (enabledList.length === 1) {
@@ -55,13 +55,14 @@ const ModelSelect = memo<ModelSelectProps>(({ value, onChange, showAbility = tru
55
55
 
56
56
  return (
57
57
  <Select
58
- onChange={(model, option) => {
58
+ onChange={(value, option) => {
59
+ const model = value.split('/').slice(1).join('/');
59
60
  onChange?.({ model, provider: (option as unknown as ModelOption).provider });
60
61
  }}
61
62
  options={options}
62
63
  popupClassName={styles.select}
63
64
  popupMatchSelectWidth={false}
64
- value={value}
65
+ value={`${value?.provider}/${value?.model}`}
65
66
  />
66
67
  );
67
68
  });
@@ -92,20 +92,20 @@ export const useMenu = () => {
92
92
 
93
93
  const settings: MenuProps['items'] = [
94
94
  {
95
+ extra: (
96
+ <ActionIcon
97
+ icon={Maximize}
98
+ onClick={() => router.push(urlJoin('/settings', SettingsTabs.Common))}
99
+ size={'small'}
100
+ title={t('fullscreen')}
101
+ />
102
+ ),
95
103
  icon: <Icon icon={Settings2} />,
96
104
  key: 'setting',
97
105
  label: (
98
- <Flexbox align={'center'} gap={8} horizontal>
99
- <NewVersionBadge onClick={openSettings} showBadge={hasNewVersion}>
100
- {t('userPanel.setting')}
101
- </NewVersionBadge>
102
- <ActionIcon
103
- icon={Maximize}
104
- onClick={() => router.push(urlJoin('/settings', SettingsTabs.Common))}
105
- size={'small'}
106
- title={t('fullscreen')}
107
- />
108
- </Flexbox>
106
+ <NewVersionBadge onClick={openSettings} showBadge={hasNewVersion}>
107
+ {t('userPanel.setting')}
108
+ </NewVersionBadge>
109
109
  ),
110
110
  },
111
111
  {
@@ -374,10 +374,16 @@ export default {
374
374
  modelDesc: '指定用于生成助理名称、描述、头像、标签的模型',
375
375
  title: '自动生成助理信息',
376
376
  },
377
+ customPrompt: {
378
+ addPrompt: '添加自定义提示',
379
+ desc: '填写后,系统助理将在生成内容时使用自定义提示',
380
+ placeholder: '请输入自定义提示词',
381
+ title: '自定义提示词',
382
+ },
377
383
  queryRewrite: {
378
384
  label: '提问重写模型',
379
385
  modelDesc: '指定用于优化用户提问的模型',
380
- title: '知识库',
386
+ title: '知识库提问重写',
381
387
  },
382
388
  title: '系统助手',
383
389
  topic: {
@@ -4,20 +4,34 @@ import { fileEnv } from '@/config/file';
4
4
  import { langfuseEnv } from '@/config/langfuse';
5
5
  import { getLLMConfig } from '@/config/llm';
6
6
  import {
7
+ Ai21ProviderCard,
8
+ Ai360ProviderCard,
9
+ AnthropicProviderCard,
10
+ BaichuanProviderCard,
7
11
  BedrockProviderCard,
12
+ DeepSeekProviderCard,
8
13
  FireworksAIProviderCard,
9
14
  GithubProviderCard,
10
15
  GoogleProviderCard,
11
16
  GroqProviderCard,
12
17
  HuggingFaceProviderCard,
13
18
  HunyuanProviderCard,
19
+ MinimaxProviderCard,
20
+ MistralProviderCard,
21
+ MoonshotProviderCard,
14
22
  NovitaProviderCard,
15
23
  OllamaProviderCard,
16
24
  OpenAIProviderCard,
17
25
  OpenRouterProviderCard,
26
+ PerplexityProviderCard,
18
27
  QwenProviderCard,
19
28
  SiliconCloudProviderCard,
29
+ SparkProviderCard,
30
+ StepfunProviderCard,
31
+ TaichuProviderCard,
20
32
  TogetherAIProviderCard,
33
+ UpstageProviderCard,
34
+ WenxinProviderCard,
21
35
  ZeroOneProviderCard,
22
36
  ZhiPuProviderCard,
23
37
  } from '@/config/modelProviders';
@@ -36,6 +50,8 @@ export const getServerGlobalConfig = () => {
36
50
  OPENAI_MODEL_LIST,
37
51
 
38
52
  ENABLED_MOONSHOT,
53
+ MOONSHOT_MODEL_LIST,
54
+
39
55
  ENABLED_ZHIPU,
40
56
  ZHIPU_MODEL_LIST,
41
57
 
@@ -55,10 +71,19 @@ export const getServerGlobalConfig = () => {
55
71
  HUNYUAN_MODEL_LIST,
56
72
 
57
73
  ENABLED_DEEPSEEK,
74
+ DEEPSEEK_MODEL_LIST,
75
+
58
76
  ENABLED_PERPLEXITY,
77
+ PERPLEXITY_MODEL_LIST,
78
+
59
79
  ENABLED_ANTHROPIC,
80
+ ANTHROPIC_MODEL_LIST,
81
+
60
82
  ENABLED_MINIMAX,
83
+ MINIMAX_MODEL_LIST,
84
+
61
85
  ENABLED_MISTRAL,
86
+ MISTRAL_MODEL_LIST,
62
87
 
63
88
  ENABLED_NOVITA,
64
89
  NOVITA_MODEL_LIST,
@@ -67,17 +92,28 @@ export const getServerGlobalConfig = () => {
67
92
  QWEN_MODEL_LIST,
68
93
 
69
94
  ENABLED_STEPFUN,
95
+ STEPFUN_MODEL_LIST,
96
+
70
97
  ENABLED_BAICHUAN,
98
+ BAICHUAN_MODEL_LIST,
99
+
71
100
  ENABLED_TAICHU,
101
+ TAICHU_MODEL_LIST,
102
+
72
103
  ENABLED_AI21,
104
+ AI21_MODEL_LIST,
105
+
73
106
  ENABLED_AI360,
107
+ AI360_MODEL_LIST,
74
108
 
75
109
  ENABLED_SILICONCLOUD,
76
110
  SILICONCLOUD_MODEL_LIST,
77
111
 
78
112
  ENABLED_UPSTAGE,
113
+ UPSTAGE_MODEL_LIST,
79
114
 
80
115
  ENABLED_SPARK,
116
+ SPARK_MODEL_LIST,
81
117
 
82
118
  ENABLED_AZURE_OPENAI,
83
119
  AZURE_MODEL_LIST,
@@ -99,6 +135,7 @@ export const getServerGlobalConfig = () => {
99
135
  FIREWORKSAI_MODEL_LIST,
100
136
 
101
137
  ENABLED_WENXIN,
138
+ WENXIN_MODEL_LIST,
102
139
 
103
140
  ENABLED_HUGGINGFACE,
104
141
  HUGGINGFACE_MODEL_LIST,
@@ -112,10 +149,29 @@ export const getServerGlobalConfig = () => {
112
149
  enabledAccessCode: ACCESS_CODES?.length > 0,
113
150
  enabledOAuthSSO: enableNextAuth,
114
151
  languageModel: {
115
- ai21: { enabled: ENABLED_AI21 },
116
- ai360: { enabled: ENABLED_AI360 },
152
+ ai21: {
153
+ enabled: ENABLED_AI21,
154
+ enabledModels: extractEnabledModels(AI21_MODEL_LIST),
155
+ serverModelCards: transformToChatModelCards({
156
+ defaultChatModels: Ai21ProviderCard.chatModels,
157
+ modelString: AI21_MODEL_LIST,
158
+ }),
159
+ },
160
+ ai360: {
161
+ enabled: ENABLED_AI360,
162
+ enabledModels: extractEnabledModels(AI360_MODEL_LIST),
163
+ serverModelCards: transformToChatModelCards({
164
+ defaultChatModels: Ai360ProviderCard.chatModels,
165
+ modelString: AI360_MODEL_LIST,
166
+ }),
167
+ },
117
168
  anthropic: {
118
169
  enabled: ENABLED_ANTHROPIC,
170
+ enabledModels: extractEnabledModels(ANTHROPIC_MODEL_LIST),
171
+ serverModelCards: transformToChatModelCards({
172
+ defaultChatModels: AnthropicProviderCard.chatModels,
173
+ modelString: ANTHROPIC_MODEL_LIST,
174
+ }),
119
175
  },
120
176
  azure: {
121
177
  enabled: ENABLED_AZURE_OPENAI,
@@ -126,7 +182,14 @@ export const getServerGlobalConfig = () => {
126
182
  withDeploymentName: true,
127
183
  }),
128
184
  },
129
- baichuan: { enabled: ENABLED_BAICHUAN },
185
+ baichuan: {
186
+ enabled: ENABLED_BAICHUAN,
187
+ enabledModels: extractEnabledModels(BAICHUAN_MODEL_LIST),
188
+ serverModelCards: transformToChatModelCards({
189
+ defaultChatModels: BaichuanProviderCard.chatModels,
190
+ modelString: BAICHUAN_MODEL_LIST,
191
+ }),
192
+ },
130
193
  bedrock: {
131
194
  enabled: ENABLED_AWS_BEDROCK,
132
195
  enabledModels: extractEnabledModels(AWS_BEDROCK_MODEL_LIST),
@@ -135,8 +198,14 @@ export const getServerGlobalConfig = () => {
135
198
  modelString: AWS_BEDROCK_MODEL_LIST,
136
199
  }),
137
200
  },
138
- deepseek: { enabled: ENABLED_DEEPSEEK },
139
-
201
+ deepseek: {
202
+ enabled: ENABLED_DEEPSEEK,
203
+ enabledModels: extractEnabledModels(DEEPSEEK_MODEL_LIST),
204
+ serverModelCards: transformToChatModelCards({
205
+ defaultChatModels: DeepSeekProviderCard.chatModels,
206
+ modelString: DEEPSEEK_MODEL_LIST,
207
+ }),
208
+ },
140
209
  fireworksai: {
141
210
  enabled: ENABLED_FIREWORKSAI,
142
211
  enabledModels: extractEnabledModels(FIREWORKSAI_MODEL_LIST),
@@ -145,7 +214,6 @@ export const getServerGlobalConfig = () => {
145
214
  modelString: FIREWORKSAI_MODEL_LIST,
146
215
  }),
147
216
  },
148
-
149
217
  github: {
150
218
  enabled: ENABLED_GITHUB,
151
219
  enabledModels: extractEnabledModels(GITHUB_MODEL_LIST),
@@ -186,9 +254,30 @@ export const getServerGlobalConfig = () => {
186
254
  modelString: HUNYUAN_MODEL_LIST,
187
255
  }),
188
256
  },
189
- minimax: { enabled: ENABLED_MINIMAX },
190
- mistral: { enabled: ENABLED_MISTRAL },
191
- moonshot: { enabled: ENABLED_MOONSHOT },
257
+ minimax: {
258
+ enabled: ENABLED_MINIMAX,
259
+ enabledModels: extractEnabledModels(MINIMAX_MODEL_LIST),
260
+ serverModelCards: transformToChatModelCards({
261
+ defaultChatModels: MinimaxProviderCard.chatModels,
262
+ modelString: MINIMAX_MODEL_LIST,
263
+ }),
264
+ },
265
+ mistral: {
266
+ enabled: ENABLED_MISTRAL,
267
+ enabledModels: extractEnabledModels(MISTRAL_MODEL_LIST),
268
+ serverModelCards: transformToChatModelCards({
269
+ defaultChatModels: MistralProviderCard.chatModels,
270
+ modelString: MISTRAL_MODEL_LIST,
271
+ }),
272
+ },
273
+ moonshot: {
274
+ enabled: ENABLED_MOONSHOT,
275
+ enabledModels: extractEnabledModels(MOONSHOT_MODEL_LIST),
276
+ serverModelCards: transformToChatModelCards({
277
+ defaultChatModels: MoonshotProviderCard.chatModels,
278
+ modelString: MOONSHOT_MODEL_LIST,
279
+ }),
280
+ },
192
281
  novita: {
193
282
  enabled: ENABLED_NOVITA,
194
283
  enabledModels: extractEnabledModels(NOVITA_MODEL_LIST),
@@ -222,7 +311,14 @@ export const getServerGlobalConfig = () => {
222
311
  modelString: OPENROUTER_MODEL_LIST,
223
312
  }),
224
313
  },
225
- perplexity: { enabled: ENABLED_PERPLEXITY },
314
+ perplexity: {
315
+ enabled: ENABLED_PERPLEXITY,
316
+ enabledModels: extractEnabledModels(PERPLEXITY_MODEL_LIST),
317
+ serverModelCards: transformToChatModelCards({
318
+ defaultChatModels: PerplexityProviderCard.chatModels,
319
+ modelString: PERPLEXITY_MODEL_LIST,
320
+ }),
321
+ },
226
322
  qwen: {
227
323
  enabled: ENABLED_QWEN,
228
324
  enabledModels: extractEnabledModels(QWEN_MODEL_LIST),
@@ -239,10 +335,30 @@ export const getServerGlobalConfig = () => {
239
335
  modelString: SILICONCLOUD_MODEL_LIST,
240
336
  }),
241
337
  },
242
- spark: { enabled: ENABLED_SPARK },
243
- stepfun: { enabled: ENABLED_STEPFUN },
244
-
245
- taichu: { enabled: ENABLED_TAICHU },
338
+ spark: {
339
+ enabled: ENABLED_SPARK,
340
+ enabledModels: extractEnabledModels(SPARK_MODEL_LIST),
341
+ serverModelCards: transformToChatModelCards({
342
+ defaultChatModels: SparkProviderCard.chatModels,
343
+ modelString: SPARK_MODEL_LIST,
344
+ }),
345
+ },
346
+ stepfun: {
347
+ enabled: ENABLED_STEPFUN,
348
+ enabledModels: extractEnabledModels(STEPFUN_MODEL_LIST),
349
+ serverModelCards: transformToChatModelCards({
350
+ defaultChatModels: StepfunProviderCard.chatModels,
351
+ modelString: STEPFUN_MODEL_LIST,
352
+ }),
353
+ },
354
+ taichu: {
355
+ enabled: ENABLED_TAICHU,
356
+ enabledModels: extractEnabledModels(TAICHU_MODEL_LIST),
357
+ serverModelCards: transformToChatModelCards({
358
+ defaultChatModels: TaichuProviderCard.chatModels,
359
+ modelString: TAICHU_MODEL_LIST,
360
+ }),
361
+ },
246
362
  togetherai: {
247
363
  enabled: ENABLED_TOGETHERAI,
248
364
  enabledModels: extractEnabledModels(TOGETHERAI_MODEL_LIST),
@@ -251,8 +367,22 @@ export const getServerGlobalConfig = () => {
251
367
  modelString: TOGETHERAI_MODEL_LIST,
252
368
  }),
253
369
  },
254
- upstage: { enabled: ENABLED_UPSTAGE },
255
- wenxin: { enabled: ENABLED_WENXIN },
370
+ upstage: {
371
+ enabled: ENABLED_UPSTAGE,
372
+ enabledModels: extractEnabledModels(UPSTAGE_MODEL_LIST),
373
+ serverModelCards: transformToChatModelCards({
374
+ defaultChatModels: UpstageProviderCard.chatModels,
375
+ modelString: UPSTAGE_MODEL_LIST,
376
+ }),
377
+ },
378
+ wenxin: {
379
+ enabled: ENABLED_WENXIN,
380
+ enabledModels: extractEnabledModels(WENXIN_MODEL_LIST),
381
+ serverModelCards: transformToChatModelCards({
382
+ defaultChatModels: WenxinProviderCard.chatModels,
383
+ modelString: WENXIN_MODEL_LIST,
384
+ }),
385
+ },
256
386
  zeroone: {
257
387
  enabled: ENABLED_ZEROONE,
258
388
  enabledModels: extractEnabledModels(ZEROONE_MODEL_LIST),
@@ -26,9 +26,10 @@ export const parseSystemAgent = (envString: string = ''): Partial<UserSystemAgen
26
26
 
27
27
  if (protectedKeys.includes(key)) {
28
28
  config[key as keyof UserSystemAgentConfig] = {
29
+ enabled: key === 'queryRewrite' ? true : undefined,
29
30
  model: model.trim(),
30
31
  provider: provider.trim(),
31
- };
32
+ } as any;
32
33
  }
33
34
  } else {
34
35
  throw new Error('Invalid environment variable format');
@@ -53,7 +53,7 @@ export class ChunkService {
53
53
  await this.asyncTaskModel.update(asyncTaskId, {
54
54
  error: new AsyncTaskError(
55
55
  AsyncTaskErrorType.TaskTriggerError,
56
- 'trigger chunk embedding async task error. Please check your app is public available or check your proxy settings is set correctly.',
56
+ 'trigger chunk embedding async task error. Please make sure the APP_URL is available from your server. You can check the proxy config or WAF blocking',
57
57
  ),
58
58
  status: AsyncTaskStatus.Error,
59
59
  });
@@ -92,7 +92,7 @@ export class ChunkService {
92
92
  await this.asyncTaskModel.update(asyncTaskId, {
93
93
  error: new AsyncTaskError(
94
94
  AsyncTaskErrorType.TaskTriggerError,
95
- 'trigger file parse async task error. Please check your app is public available or check your proxy settings is set correctly.',
95
+ 'trigger chunk embedding async task error. Please make sure the APP_URL is available from your server. You can check the proxy config or WAF blocking',
96
96
  ),
97
97
  status: AsyncTaskStatus.Error,
98
98
  });
@@ -11,7 +11,6 @@ import { toggleBooleanList } from '@/store/chat/utils';
11
11
  import { useUserStore } from '@/store/user';
12
12
  import { systemAgentSelectors } from '@/store/user/selectors';
13
13
  import { ChatSemanticSearchChunk } from '@/types/chunk';
14
- import { merge } from '@/utils/merge';
15
14
 
16
15
  export interface ChatRAGAction {
17
16
  deleteUserMessageRagQuery: (id: string) => Promise<void>;
@@ -67,10 +66,10 @@ export const chatRag: StateCreator<ChatStore, [['zustand/devtools', never]], [],
67
66
  // 1. get the rewrite query
68
67
  let rewriteQuery = message?.ragQuery || userQuery;
69
68
 
70
- // only rewrite query length is less than 10 characters, refs: https://github.com/lobehub/lobe-chat/pull/4288
69
+ // only rewrite query length is less than 15 characters, refs: https://github.com/lobehub/lobe-chat/pull/4288
71
70
  // if there is no ragQuery and there is a chat history
72
71
  // we need to rewrite the user message to get better results
73
- if (rewriteQuery.length < 10 && !message?.ragQuery && messages.length > 0) {
72
+ if (rewriteQuery.length < 15 && !message?.ragQuery && messages.length > 0) {
74
73
  rewriteQuery = await get().internal_rewriteQuery(id, userQuery, messages);
75
74
  }
76
75
 
@@ -92,7 +91,17 @@ export const chatRag: StateCreator<ChatStore, [['zustand/devtools', never]], [],
92
91
  let rewriteQuery = content;
93
92
 
94
93
  const queryRewriteConfig = systemAgentSelectors.queryRewrite(useUserStore.getState());
95
- const rewriteQueryParams = merge(queryRewriteConfig, chainRewriteQuery(content, messages));
94
+ if (!queryRewriteConfig.enabled) return content;
95
+
96
+ const rewriteQueryParams = {
97
+ model: queryRewriteConfig.model,
98
+ provider: queryRewriteConfig.provider,
99
+ ...chainRewriteQuery(
100
+ content,
101
+ messages,
102
+ !!queryRewriteConfig.customPrompt ? queryRewriteConfig.customPrompt : undefined,
103
+ ),
104
+ };
96
105
 
97
106
  let ragQuery = '';
98
107
  await chatService.fetchPresetTaskResult({
@@ -32,7 +32,10 @@ export interface UserSettingsAction {
32
32
  updateGeneralConfig: (settings: Partial<UserGeneralConfig>) => Promise<void>;
33
33
  updateKeyVaults: (settings: Partial<UserKeyVaults>) => Promise<void>;
34
34
 
35
- updateSystemAgent: (key: UserSystemAgentConfigKey, value: SystemAgentItem) => Promise<void>;
35
+ updateSystemAgent: (
36
+ key: UserSystemAgentConfigKey,
37
+ value: Partial<SystemAgentItem>,
38
+ ) => Promise<void>;
36
39
  }
37
40
 
38
41
  export const createSettingsSlice: StateCreator<
@@ -109,9 +112,9 @@ export const createSettingsSlice: StateCreator<
109
112
  updateKeyVaults: async (keyVaults) => {
110
113
  await get().setSettings({ keyVaults });
111
114
  },
112
- updateSystemAgent: async (key, { provider, model }) => {
115
+ updateSystemAgent: async (key, value) => {
113
116
  await get().setSettings({
114
- systemAgent: { [key]: { model, provider } },
117
+ systemAgent: { [key]: { ...value } },
115
118
  });
116
119
  },
117
120
  });
@@ -1,11 +1,17 @@
1
1
  export interface SystemAgentItem {
2
+ customPrompt?: string;
3
+ enabled?: boolean;
2
4
  model: string;
3
5
  provider: string;
4
6
  }
5
7
 
8
+ export interface QueryRewriteSystemAgent extends Omit<SystemAgentItem, 'enabled'> {
9
+ enabled: boolean;
10
+ }
11
+
6
12
  export interface UserSystemAgentConfig {
7
13
  agentMeta: SystemAgentItem;
8
- queryRewrite: SystemAgentItem;
14
+ queryRewrite: QueryRewriteSystemAgent;
9
15
  topic: SystemAgentItem;
10
16
  translation: SystemAgentItem;
11
17
  }