@lobehub/chat 1.22.26 → 1.23.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.
- package/CHANGELOG.md +50 -0
- package/docs/self-hosting/server-database.mdx +6 -2
- package/locales/ar/error.json +1 -1
- package/locales/ar/setting.json +7 -1
- package/locales/bg-BG/error.json +1 -1
- package/locales/bg-BG/setting.json +7 -1
- package/locales/de-DE/error.json +1 -1
- package/locales/de-DE/setting.json +7 -1
- package/locales/en-US/error.json +1 -1
- package/locales/en-US/setting.json +7 -1
- package/locales/es-ES/error.json +1 -1
- package/locales/es-ES/setting.json +7 -1
- package/locales/fr-FR/error.json +1 -1
- package/locales/fr-FR/setting.json +7 -1
- package/locales/it-IT/error.json +1 -1
- package/locales/it-IT/setting.json +7 -1
- package/locales/ja-JP/error.json +1 -1
- package/locales/ja-JP/setting.json +7 -1
- package/locales/ko-KR/error.json +1 -1
- package/locales/ko-KR/setting.json +7 -1
- package/locales/nl-NL/error.json +1 -1
- package/locales/nl-NL/setting.json +7 -1
- package/locales/pl-PL/error.json +1 -1
- package/locales/pl-PL/setting.json +7 -1
- package/locales/pt-BR/error.json +1 -1
- package/locales/pt-BR/setting.json +7 -1
- package/locales/ru-RU/error.json +1 -1
- package/locales/ru-RU/setting.json +7 -1
- package/locales/tr-TR/error.json +1 -1
- package/locales/tr-TR/setting.json +7 -1
- package/locales/vi-VN/error.json +1 -1
- package/locales/vi-VN/setting.json +7 -1
- package/locales/zh-CN/error.json +1 -1
- package/locales/zh-CN/setting.json +7 -1
- package/locales/zh-TW/error.json +1 -1
- package/locales/zh-TW/setting.json +7 -1
- package/package.json +2 -2
- package/src/app/(main)/settings/system-agent/features/createForm.tsx +90 -41
- package/src/app/(main)/settings/system-agent/index.tsx +15 -0
- package/src/chains/rewriteQuery.ts +3 -2
- package/src/components/TextArea/index.tsx +42 -0
- package/src/config/modelProviders/bedrock.ts +14 -0
- package/src/const/settings/systemAgent.ts +15 -2
- package/src/features/AgentSetting/AgentModal/ModelSelect.tsx +6 -2
- package/src/features/ModelSelect/index.tsx +5 -4
- package/src/features/User/UserPanel/useMenu.tsx +11 -11
- package/src/locales/default/setting.ts +7 -1
- package/src/server/globalConfig/parseSystemAgent.ts +2 -1
- package/src/server/services/chunk/index.ts +2 -2
- package/src/store/chat/slices/aiChat/actions/rag.ts +13 -4
- package/src/store/user/slices/settings/action.ts +6 -3
- package/src/types/user/settings/systemAgent.ts +7 -1
@@ -372,10 +372,16 @@
|
|
372
372
|
"modelDesc": "指定用于生成助理名称、描述、头像、标签的模型",
|
373
373
|
"title": "自动生成助理信息"
|
374
374
|
},
|
375
|
+
"customPrompt": {
|
376
|
+
"addPrompt": "添加自定义提示",
|
377
|
+
"desc": "填写后,系统助理将在生成内容时使用自定义提示",
|
378
|
+
"placeholder": "请输入自定义提示词",
|
379
|
+
"title": "自定义提示词"
|
380
|
+
},
|
375
381
|
"queryRewrite": {
|
376
382
|
"label": "提问重写模型",
|
377
383
|
"modelDesc": "指定用于优化用户提问的模型",
|
378
|
-
"title": "
|
384
|
+
"title": "知识库提问重写"
|
379
385
|
},
|
380
386
|
"title": "系统助手",
|
381
387
|
"topic": {
|
package/locales/zh-TW/error.json
CHANGED
@@ -51,10 +51,10 @@
|
|
51
51
|
"431": "很抱歉,您的請求頭字段太大,伺服器無法處理",
|
52
52
|
"451": "很抱歉,由於法律原因,伺服器拒絕提供此資源",
|
53
53
|
"500": "抱歉,伺服器似乎遇到一些困難,暫時無法完成您的請求。請稍後再試。",
|
54
|
+
"501": "很抱歉,伺服器尚未知道如何處理此請求,請確認您的操作是否正確",
|
54
55
|
"502": "抱歉,伺服器似乎迷失了方向,暫時無法提供服務。請稍後再試。",
|
55
56
|
"503": "抱歉,伺服器目前無法處理您的請求,可能是因為過載或正在進行維護。請稍後再試。",
|
56
57
|
"504": "抱歉,伺服器沒有收到上游伺服器的回應。請稍後再試。",
|
57
|
-
"501": "很抱歉,伺服器尚未知道如何處理此請求,請確認您的操作是否正確",
|
58
58
|
"505": "很抱歉,伺服器不支援您使用的HTTP版本,請更新後再試",
|
59
59
|
"506": "很抱歉,伺服器配置出現問題,請聯繫管理員解決",
|
60
60
|
"507": "很抱歉,伺服器儲存空間不足,無法處理您的請求,請稍後再試",
|
@@ -372,10 +372,16 @@
|
|
372
372
|
"modelDesc": "指定用於生成助理名稱、描述、頭像、標籤的模型",
|
373
373
|
"title": "自動生成助理資訊"
|
374
374
|
},
|
375
|
+
"customPrompt": {
|
376
|
+
"addPrompt": "新增自訂提示",
|
377
|
+
"desc": "填寫後,系統助理將在生成內容時使用自訂提示",
|
378
|
+
"placeholder": "請輸入自訂提示詞",
|
379
|
+
"title": "自訂提示詞"
|
380
|
+
},
|
375
381
|
"queryRewrite": {
|
376
382
|
"label": "提問重寫模型",
|
377
383
|
"modelDesc": "指定用於優化用戶提問的模型",
|
378
|
-
"title": "
|
384
|
+
"title": "知識庫提問重寫"
|
379
385
|
},
|
380
386
|
"title": "系統助手",
|
381
387
|
"topic": {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.23.0",
|
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",
|
@@ -143,7 +143,7 @@
|
|
143
143
|
"ahooks": "^3.8.1",
|
144
144
|
"ai": "^3.4.16",
|
145
145
|
"antd": "^5.21.4",
|
146
|
-
"antd-style": "^3.7.
|
146
|
+
"antd-style": "^3.7.1",
|
147
147
|
"brotli-wasm": "^3.0.1",
|
148
148
|
"chroma-js": "^2.6.0",
|
149
149
|
"dayjs": "^1.11.13",
|
@@ -1,11 +1,14 @@
|
|
1
1
|
'use client';
|
2
2
|
|
3
|
-
import { Form, type ItemGroup } from '@lobehub/ui';
|
4
|
-
import {
|
3
|
+
import { Form, Icon, type ItemGroup } from '@lobehub/ui';
|
4
|
+
import type { FormItemProps } from '@lobehub/ui/es/Form/components/FormItem';
|
5
|
+
import { Form as AntForm, Button, Switch } from 'antd';
|
5
6
|
import isEqual from 'fast-deep-equal';
|
7
|
+
import { PencilIcon } from 'lucide-react';
|
6
8
|
import { memo } from 'react';
|
7
9
|
import { useTranslation } from 'react-i18next';
|
8
10
|
|
11
|
+
import TextArea from '@/components/TextArea';
|
9
12
|
import { FORM_STYLE } from '@/const/layoutTokens';
|
10
13
|
import ModelSelect from '@/features/ModelSelect';
|
11
14
|
import { useUserStore } from '@/store/user';
|
@@ -16,44 +19,90 @@ import { useSyncSystemAgent } from './useSync';
|
|
16
19
|
|
17
20
|
type SettingItemGroup = ItemGroup;
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
22
|
+
interface SystemAgentFormProps {
|
23
|
+
allowCustomPrompt?: boolean;
|
24
|
+
allowDisable?: boolean;
|
25
|
+
defaultPrompt?: string;
|
26
|
+
systemAgentKey: UserSystemAgentConfigKey;
|
27
|
+
}
|
28
|
+
|
29
|
+
const SystemAgentForm = memo(
|
30
|
+
({ systemAgentKey, allowDisable, allowCustomPrompt, defaultPrompt }: SystemAgentFormProps) => {
|
31
|
+
const { t } = useTranslation('setting');
|
32
|
+
|
33
|
+
const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual);
|
34
|
+
const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]);
|
35
|
+
|
36
|
+
const [form] = AntForm.useForm();
|
37
|
+
const value = settings[systemAgentKey];
|
38
|
+
|
39
|
+
const systemAgentSettings: SettingItemGroup = {
|
40
|
+
children: [
|
41
|
+
{
|
42
|
+
children: (
|
43
|
+
<ModelSelect
|
44
|
+
onChange={(props) => {
|
45
|
+
updateSystemAgent(systemAgentKey, props);
|
46
|
+
}}
|
47
|
+
showAbility={false}
|
48
|
+
// value={value}
|
49
|
+
/>
|
50
|
+
),
|
51
|
+
desc: t(`systemAgent.${systemAgentKey}.modelDesc`),
|
52
|
+
label: t(`systemAgent.${systemAgentKey}.label`),
|
53
|
+
name: systemAgentKey,
|
54
|
+
},
|
55
|
+
(!!allowCustomPrompt && {
|
56
|
+
children: !!value.customPrompt ? (
|
57
|
+
<TextArea
|
58
|
+
onChange={(e) => {
|
59
|
+
updateSystemAgent(systemAgentKey, { customPrompt: e });
|
60
|
+
}}
|
61
|
+
placeholder={t('systemAgent.customPrompt.placeholder')}
|
62
|
+
style={{ minHeight: 160 }}
|
63
|
+
value={value.customPrompt}
|
64
|
+
/>
|
65
|
+
) : (
|
66
|
+
<Button
|
67
|
+
block
|
68
|
+
icon={<Icon icon={PencilIcon} />}
|
69
|
+
onClick={async () => {
|
70
|
+
await updateSystemAgent(systemAgentKey, { customPrompt: defaultPrompt });
|
71
|
+
}}
|
72
|
+
>
|
73
|
+
{t('systemAgent.customPrompt.addPrompt')}
|
74
|
+
</Button>
|
75
|
+
),
|
76
|
+
desc: t('systemAgent.customPrompt.desc'),
|
77
|
+
label: t('systemAgent.customPrompt.title'),
|
78
|
+
name: [systemAgentKey, 'customPrompt'],
|
79
|
+
}) as FormItemProps,
|
80
|
+
].filter(Boolean),
|
81
|
+
extra: allowDisable && (
|
82
|
+
<Switch
|
83
|
+
onChange={(enabled) => {
|
84
|
+
updateSystemAgent(systemAgentKey, { enabled });
|
85
|
+
}}
|
86
|
+
value={value.enabled}
|
87
|
+
/>
|
88
|
+
),
|
89
|
+
title: (
|
90
|
+
<span
|
91
|
+
style={{
|
92
|
+
opacity: typeof value.enabled === 'boolean' && !value.enabled ? 0.45 : 1,
|
93
|
+
}}
|
94
|
+
>
|
95
|
+
{t(`systemAgent.${systemAgentKey}.title`)}
|
96
|
+
</span>
|
97
|
+
),
|
98
|
+
};
|
99
|
+
|
100
|
+
useSyncSystemAgent(form, settings);
|
101
|
+
|
102
|
+
return (
|
103
|
+
<Form form={form} initialValues={settings} items={[systemAgentSettings]} {...FORM_STYLE} />
|
104
|
+
);
|
105
|
+
},
|
106
|
+
);
|
58
107
|
|
59
108
|
export default SystemAgentForm;
|
@@ -1,11 +1,26 @@
|
|
1
|
+
'use client';
|
2
|
+
|
3
|
+
import { DEFAULT_REWRITE_QUERY } from '@/const/settings';
|
4
|
+
import { isServerMode } from '@/const/version';
|
5
|
+
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
|
6
|
+
|
1
7
|
import SystemAgentForm from './features/createForm';
|
2
8
|
|
3
9
|
const Page = () => {
|
10
|
+
const { enableKnowledgeBase } = useServerConfigStore(featureFlagsSelectors);
|
4
11
|
return (
|
5
12
|
<>
|
6
13
|
<SystemAgentForm systemAgentKey="topic" />
|
7
14
|
<SystemAgentForm systemAgentKey="translation" />
|
8
15
|
<SystemAgentForm systemAgentKey="agentMeta" />
|
16
|
+
{isServerMode && enableKnowledgeBase && (
|
17
|
+
<SystemAgentForm
|
18
|
+
allowCustomPrompt
|
19
|
+
allowDisable
|
20
|
+
defaultPrompt={DEFAULT_REWRITE_QUERY}
|
21
|
+
systemAgentKey="queryRewrite"
|
22
|
+
/>
|
23
|
+
)}
|
9
24
|
</>
|
10
25
|
);
|
11
26
|
};
|
@@ -1,13 +1,14 @@
|
|
1
|
+
import { DEFAULT_REWRITE_QUERY } from '@/const/settings';
|
1
2
|
import { ChatStreamPayload } from '@/types/openai/chat';
|
2
3
|
|
3
4
|
export const chainRewriteQuery = (
|
4
5
|
query: string,
|
5
6
|
context: string[],
|
7
|
+
instruction: string = DEFAULT_REWRITE_QUERY,
|
6
8
|
): Partial<ChatStreamPayload> => ({
|
7
9
|
messages: [
|
8
10
|
{
|
9
|
-
content:
|
10
|
-
|
11
|
+
content: `${instruction}
|
11
12
|
<chatHistory>
|
12
13
|
${context.join('\n')}
|
13
14
|
</chatHistory>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { Input } from 'antd';
|
2
|
+
import { TextAreaProps as Props, TextAreaRef } from 'antd/es/input/TextArea';
|
3
|
+
import { memo, useRef, useState } from 'react';
|
4
|
+
|
5
|
+
interface TextAreaProps extends Omit<Props, 'onChange'> {
|
6
|
+
onChange?: (value: string) => void;
|
7
|
+
}
|
8
|
+
|
9
|
+
const TextArea = memo<TextAreaProps>(({ onChange, value: defaultValue, ...props }) => {
|
10
|
+
const ref = useRef<TextAreaRef>(null);
|
11
|
+
const isChineseInput = useRef(false);
|
12
|
+
|
13
|
+
const [value, setValue] = useState(defaultValue as string);
|
14
|
+
|
15
|
+
return (
|
16
|
+
<Input.TextArea
|
17
|
+
onBlur={() => {
|
18
|
+
onChange?.(value);
|
19
|
+
}}
|
20
|
+
onChange={(e) => {
|
21
|
+
setValue(e.target.value);
|
22
|
+
}}
|
23
|
+
onCompositionEnd={() => {
|
24
|
+
isChineseInput.current = false;
|
25
|
+
}}
|
26
|
+
onCompositionStart={() => {
|
27
|
+
isChineseInput.current = true;
|
28
|
+
}}
|
29
|
+
onPressEnter={() => {
|
30
|
+
if (isChineseInput.current) return;
|
31
|
+
onChange?.(value);
|
32
|
+
}}
|
33
|
+
ref={ref}
|
34
|
+
{...props}
|
35
|
+
value={value}
|
36
|
+
/>
|
37
|
+
);
|
38
|
+
});
|
39
|
+
|
40
|
+
TextArea.displayName = 'TextArea';
|
41
|
+
|
42
|
+
export default TextArea;
|
@@ -32,6 +32,20 @@ const Bedrock: ModelProviderCard = {
|
|
32
32
|
displayName: 'Claude 3.5 Sonnet',
|
33
33
|
enabled: true,
|
34
34
|
functionCall: true,
|
35
|
+
id: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
36
|
+
pricing: {
|
37
|
+
input: 3,
|
38
|
+
output: 15,
|
39
|
+
},
|
40
|
+
tokens: 200_000,
|
41
|
+
vision: true,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
description:
|
45
|
+
'Claude 3.5 Sonnet 提升了行业标准,性能超过竞争对手模型和 Claude 3 Opus,在广泛的评估中表现出色,同时具有我们中等层级模型的速度和成本。',
|
46
|
+
displayName: 'Claude 3.5 Sonnet 0620',
|
47
|
+
enabled: true,
|
48
|
+
functionCall: true,
|
35
49
|
id: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
|
36
50
|
pricing: {
|
37
51
|
input: 3,
|
@@ -1,15 +1,28 @@
|
|
1
|
-
import {
|
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:
|
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) => [
|
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={(
|
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
|
-
<
|
99
|
-
|
100
|
-
|
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: {
|
@@ -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
|
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
|
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
|
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 <
|
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
|
-
|
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: (
|
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,
|
115
|
+
updateSystemAgent: async (key, value) => {
|
113
116
|
await get().setSettings({
|
114
|
-
systemAgent: { [key]: {
|
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:
|
14
|
+
queryRewrite: QueryRewriteSystemAgent;
|
9
15
|
topic: SystemAgentItem;
|
10
16
|
translation: SystemAgentItem;
|
11
17
|
}
|