From e3bdd6944be8e4b4a6bb6c81f569fb3d5f444942 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Fri, 13 Dec 2024 00:58:02 +0530 Subject: [PATCH] added prompt url params --- app/components/chat/Chat.client.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index cd651cb1..5d523c9c 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -20,6 +20,7 @@ import Cookies from 'js-cookie'; import { debounce } from '~/utils/debounce'; import { useSettings } from '~/lib/hooks/useSettings'; import type { ProviderInfo } from '~/types/model'; +import { useSearchParams } from '@remix-run/react'; const toastAnimation = cssTransition({ enter: 'animated fadeInRight', @@ -93,6 +94,7 @@ export const ChatImpl = memo( const [uploadedFiles, setUploadedFiles] = useState([]); // Move here const [imageDataList, setImageDataList] = useState([]); // Move here const { activeProviders } = useSettings(); + const [searchParams, setSearchParams] = useSearchParams(); const [model, setModel] = useState(() => { const savedModel = Cookies.get('selectedModel'); @@ -126,6 +128,24 @@ export const ChatImpl = memo( initialMessages, initialInput: Cookies.get(PROMPT_COOKIE_KEY) || '', }); + useEffect(() => { + const prompt = searchParams.get('prompt'); + console.log(prompt, searchParams, model, provider); + + if (prompt) { + setSearchParams({}); + runAnimation(); + append({ + role: 'user', + content: [ + { + type: 'text', + text: `[Model: ${model}]\n\n[Provider: ${provider.name}]\n\n${prompt}`, + }, + ] as any, // Type assertion to bypass compiler check + }); + } + }, [model, provider, searchParams]); const { enhancingPrompt, promptEnhanced, enhancePrompt, resetEnhancer } = usePromptEnhancer(); const { parsedMessages, parseMessages } = useMessageParser();