Skip to content

Commit ce01d75

Browse files
committed
feat: add prompt configuration for AI settings
1 parent fca80ab commit ce01d75

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

i18n/en_US.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,9 @@ ui:
23542354
model:
23552355
label: Model
23562356
msg: Model is required
2357+
prompt:
2358+
label: Prompt
2359+
text: Shows the prompt for the current language. Edit and save to apply.
23572360
add_success: AI settings updated successfully.
23582361
conversations:
23592362
topic: Topic
@@ -2483,4 +2486,3 @@ ui:
24832486
copied: Copied
24842487
external_content_warning: External images/media are not displayed.
24852488

2486-

i18n/zh_CN.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ ui:
17961796
security: 安全
17971797
files: 文件
17981798
apikeys: API 密钥
1799-
intelligence: 智力
1799+
intelligence: 智能
18001800
ai_assistant: AI 助手
18011801
ai_settings: AI 设置
18021802
mcp: MCP
@@ -2318,6 +2318,9 @@ ui:
23182318
model:
23192319
label: 模型
23202320
msg: 模型是必需的
2321+
prompt:
2322+
label: 提示词
2323+
text: 显示当前语言环境的提示词,可在此修改并保存。
23212324
add_success: AI 设置更新成功。
23222325
conversations:
23232326
topic: 主题

ui/src/common/interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ export interface AiConfig {
834834
api_key: string;
835835
model: string;
836836
}>;
837+
prompt_config?: {
838+
zh_cn: string;
839+
en_us: string;
840+
};
837841
}
838842

839843
export interface AiProviderItem {

ui/src/pages/Admin/AiSettings/index.tsx

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@ import { handleFormError } from '@/utils';
3232
import { useToast } from '@/hooks';
3333
import * as Type from '@/common/interface';
3434

35+
const getPromptByLang = (
36+
promptConfig: Type.AiConfig['prompt_config'] | undefined,
37+
lang: string,
38+
) => {
39+
if (!promptConfig) {
40+
return '';
41+
}
42+
const isZh = lang?.toLowerCase().startsWith('zh');
43+
return isZh ? promptConfig.zh_cn || '' : promptConfig.en_us || '';
44+
};
45+
3546
const Index = () => {
36-
const { t } = useTranslation('translation', {
47+
const { t, i18n } = useTranslation('translation', {
3748
keyPrefix: 'admin.ai_settings',
3849
});
3950
const toast = useToast();
@@ -68,11 +79,18 @@ const Index = () => {
6879
isInvalid: false,
6980
errorMsg: '',
7081
},
82+
prompt: {
83+
value: '',
84+
isInvalid: false,
85+
errorMsg: '',
86+
},
7187
});
7288
const [apiHostPlaceholder, setApiHostPlaceholder] = useState('');
7389
const [modelsData, setModels] = useState<{ id: string }[]>([]);
7490
const [isChecking, setIsChecking] = useState(false);
7591

92+
const isZhLang = i18n.language?.toLowerCase().startsWith('zh');
93+
7694
const getCurrentProviderData = (provider) => {
7795
const findHistoryProvider =
7896
historyConfigRef.current?.ai_providers.find(
@@ -227,6 +245,14 @@ const Index = () => {
227245
enabled: formData.enabled.value,
228246
chosen_provider: formData.provider.value,
229247
ai_providers: newProviders,
248+
prompt_config: {
249+
zh_cn: isZhLang
250+
? formData.prompt.value
251+
: historyConfigRef.current?.prompt_config?.zh_cn || '',
252+
en_us: isZhLang
253+
? historyConfigRef.current?.prompt_config?.en_us || ''
254+
: formData.prompt.value,
255+
},
230256
};
231257
saveAiConfig(params)
232258
.then(() => {
@@ -295,6 +321,11 @@ const Index = () => {
295321
isInvalid: false,
296322
errorMsg: '',
297323
},
324+
prompt: {
325+
value: getPromptByLang(aiConfig.prompt_config, i18n.language),
326+
isInvalid: false,
327+
errorMsg: '',
328+
},
298329
});
299330
};
300331

@@ -322,6 +353,22 @@ const Index = () => {
322353
}
323354
}, [aiProviders, formData]);
324355

356+
useEffect(() => {
357+
if (!historyConfigRef.current) {
358+
return;
359+
}
360+
setFormData((prev) => ({
361+
...prev,
362+
prompt: {
363+
value: getPromptByLang(
364+
historyConfigRef.current?.prompt_config,
365+
i18n.language,
366+
),
367+
isInvalid: false,
368+
errorMsg: '',
369+
},
370+
}));
371+
}, [i18n.language]);
325372
return (
326373
<div>
327374
<h3 className="mb-4">{t('ai_settings', { keyPrefix: 'nav_menus' })}</h3>
@@ -477,6 +524,29 @@ const Index = () => {
477524
<div className="invalid-feedback">{formData.model.errorMsg}</div>
478525
</div>
479526

527+
<Form.Group className="mb-3" controlId="prompt">
528+
<Form.Label>{t('prompt.label')}</Form.Label>
529+
<Form.Control
530+
as="textarea"
531+
rows={8}
532+
isInvalid={formData.prompt.isInvalid}
533+
value={formData.prompt.value}
534+
onChange={(e) =>
535+
handleValueChange({
536+
prompt: {
537+
value: e.target.value,
538+
errorMsg: '',
539+
isInvalid: false,
540+
},
541+
})
542+
}
543+
/>
544+
<Form.Text className="text-muted">{t('prompt.text')}</Form.Text>
545+
<Form.Control.Feedback type="invalid">
546+
{formData.prompt.errorMsg}
547+
</Form.Control.Feedback>
548+
</Form.Group>
549+
480550
<Button type="submit">{t('save', { keyPrefix: 'btns' })}</Button>
481551
</Form>
482552
</div>

0 commit comments

Comments
 (0)