@@ -32,8 +32,19 @@ import { handleFormError } from '@/utils';
3232import { useToast } from '@/hooks' ;
3333import * 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+
3546const 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