From 5316ab4cc7a169c3af0e39b9e81be90ad2078e33 Mon Sep 17 00:00:00 2001 From: Olivier Schiavo Date: Thu, 31 Oct 2024 14:46:33 +0100 Subject: [PATCH] feat: replace special variables in instructions presets --- client/src/hooks/Chat/useChatFunctions.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/src/hooks/Chat/useChatFunctions.ts b/client/src/hooks/Chat/useChatFunctions.ts index 43a7fcd5dae..8fb64e6d124 100644 --- a/client/src/hooks/Chat/useChatFunctions.ts +++ b/client/src/hooks/Chat/useChatFunctions.ts @@ -24,6 +24,8 @@ import { getArtifactsMode } from '~/utils/artifacts'; import { getEndpointField, logger } from '~/utils'; import useUserKey from '~/hooks/Input/useUserKey'; import store from '~/store'; +import { replaceSpecialVars } from '~/utils/prompts'; +import { useAuthContext } from '~/hooks'; const logChatRequest = (request: Record) => { logger.log('=====================================\nAsk function called with:'); @@ -62,9 +64,9 @@ export default function useChatFunctions({ const setShowStopButton = useSetRecoilState(store.showStopButtonByIndex(index)); const setFilesToDelete = useSetFilesToDelete(); const getSender = useGetSender(); - const queryClient = useQueryClient(); const { getExpiry } = useUserKey(conversation?.endpoint ?? ''); + const { user } = useAuthContext(); const ask: TAskFunction = ( { @@ -112,6 +114,14 @@ export default function useChatFunctions({ let currentMessages: TMessage[] | null = overrideMessages ?? getMessages() ?? []; + // Check and replace special variables in promptPrefix + if (conversation?.promptPrefix) { + conversation.promptPrefix = replaceSpecialVars({ + text: conversation.promptPrefix, + user + }); + } + // construct the query message // this is not a real messageId, it is used as placeholder before real messageId returned text = text.trim();