Skip to content

Commit

Permalink
fix(chat): fix system prompt updating (Issue #2920) (#2933)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaBondar authored Jan 14, 2025
1 parent 5691525 commit 550309a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const SystemPrompt: FC<Props> = ({
tokenizer,
prompt ?? DefaultsService.get('defaultSystemPrompt', ''),
onChangePrompt,
true,
);

const handleChange = useCallback(
Expand Down
11 changes: 9 additions & 2 deletions apps/chat/src/hooks/usePromptSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand All @@ -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(
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 550309a

Please sign in to comment.