diff --git a/apps/chat/src/components/Chat/ChatSettings/SystemPrompt.tsx b/apps/chat/src/components/Chat/ChatSettings/SystemPrompt.tsx index ce747b404..3cee104c2 100644 --- a/apps/chat/src/components/Chat/ChatSettings/SystemPrompt.tsx +++ b/apps/chat/src/components/Chat/ChatSettings/SystemPrompt.tsx @@ -75,6 +75,7 @@ export const SystemPrompt: FC = ({ tokenizer, prompt ?? DefaultsService.get('defaultSystemPrompt', ''), onChangePrompt, + true, ); const handleChange = useCallback( diff --git a/apps/chat/src/hooks/usePromptSelection.ts b/apps/chat/src/hooks/usePromptSelection.ts index 71eb1da25..7af5cd89d 100644 --- a/apps/chat/src/hooks/usePromptSelection.ts +++ b/apps/chat/src/hooks/usePromptSelection.ts @@ -32,6 +32,7 @@ import { useTokenizer } from './useTokenizer'; * @param tokenizer: tokenizer object which used for tokens calculations. * @param prompt Default prompt value. * @param onChangePrompt A function to call if prompt selected. + * @param useLocalContentState if shouldn't dispatch state changes for content * @returns An object containing control functions and states. */ @@ -42,12 +43,16 @@ export const usePromptSelection = ( tokenizer: DialAIEntityModel['tokenizer'], prompt: string, onChangePrompt?: (prompt: string) => void, + useLocalContentState?: boolean, ) => { const { getTokensLength } = useTokenizer(tokenizer); const dispatch = useDispatch(); - const content = useAppSelector(ChatSelectors.selectInputContent); + const [_content, _setContent] = useState(prompt); + const _stateContent = useAppSelector(ChatSelectors.selectInputContent); + const content = useLocalContentState ? _content : _stateContent; + const isLoading = useAppSelector(PromptsSelectors.isPromptLoading); const promptResourcesSelector = useMemo( @@ -96,13 +101,15 @@ export const usePromptSelection = ( filteredPrompts[0] ? filteredPrompts[0] : undefined, ); - const setContent = useCallback( + const _setStateContent = useCallback( (value: string) => { dispatch(ChatActions.setInputContent(value)); }, [dispatch], ); + const setContent = useLocalContentState ? _setContent : _setStateContent; + const addPromptContent = useCallback( (newContent: string) => { setContent(content?.replace(/\/\w*$/, newContent));