From 8a46375261971e71adcec35bca876a9f216c0330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Hincapi=C3=A9=20M?= <43832784+shincap8@users.noreply.github.com> Date: Tue, 25 Feb 2025 15:55:03 -0500 Subject: [PATCH] add provider and model name to model inputs (#347) --- .../Contexts/ChatRandomWithInstructions.tsx | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/ChatRandomWithInstructions.tsx b/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/ChatRandomWithInstructions.tsx index b8bbdf3a..dac66bdc 100644 --- a/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/ChatRandomWithInstructions.tsx +++ b/frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts/ChatRandomWithInstructions.tsx @@ -17,7 +17,13 @@ import { CreateInterfaceContext } from "new_front/context/CreateInterface/Contex import BasicInstructions from "new_front/components/Inputs/BasicInstructions"; import GeneralButton from "new_front/components/Buttons/GeneralButton"; -const ChatWithInstructions: FC< +interface ModelNameMap { + [key: string]: { + model_name: string; + }; +} + +const ChatRandomWithInstructions: FC< ContextAnnotationFactoryType & ContextConfigType > = ({ taskId, @@ -34,7 +40,7 @@ const ChatWithInstructions: FC< user: [], bot: [], }); - const [modelName, setModelName] = useState({}); + const [modelName, setModelName] = useState({}); const [provider, setProvider] = useState(""); const [localContext, setLocalContext] = useState(null); const [agreeText, setAgreeText] = useState(null); @@ -43,7 +49,7 @@ const ChatWithInstructions: FC< const [readInstructions, setReadInstructions] = useState( artifactsInput?.jump_instructions ? true : false ); - const { updateModelInputs } = useContext(CreateInterfaceContext); + const { updateModelInputs, modelInputs } = useContext(CreateInterfaceContext); const { get, post, response, loading } = useFetch(); const { user } = useContext(UserContext); const location = useLocation(); @@ -140,6 +146,24 @@ const ChatWithInstructions: FC< bringDistinctContextAndModelInfo(); }, []); + useEffect(() => { + finishConversation && + !("model_info" in modelInputs) && + updateModelInputs({ + ...modelInputs, + model_info: { + provider: provider, + model_name: modelName[provider]["model_name"], + }, + }); + }, [finishConversation]); + + useEffect(() => { + if ("chat_history" in modelInputs) { + setFinishConversation(true); + } + }, [modelInputs]); + return ( <> {callLoading || loading ? ( @@ -241,4 +265,4 @@ const ChatWithInstructions: FC< ); }; -export default ChatWithInstructions; +export default ChatRandomWithInstructions;