From 059006382d1506f111148d7f5d15ad27212863ef Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 1 Apr 2023 00:09:49 +0800 Subject: [PATCH 1/2] feat: add animation --- .../components/Input/OpenAIOptions/index.jsx | 52 +++++++++++++++---- client/src/style.css | 25 +++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/client/src/components/Input/OpenAIOptions/index.jsx b/client/src/components/Input/OpenAIOptions/index.jsx index b7fdfc280c..0192ac8f0a 100644 --- a/client/src/components/Input/OpenAIOptions/index.jsx +++ b/client/src/components/Input/OpenAIOptions/index.jsx @@ -1,35 +1,59 @@ import React, { useState, useEffect, forwardRef } from 'react'; import { Tabs, TabsList, TabsTrigger } from '../../ui/Tabs.tsx'; -import { useRecoilValue, useRecoilState } from 'recoil'; +import { useRecoilValue, useRecoilState, useSetRecoilState } from 'recoil'; import { Button } from '../../ui/Button.tsx'; import store from '~/store'; function OpenAIOptions({ conversation = {} }) { const { endpoint } = conversation; - const { advancedMode, setAdvancedMode } = useState(false); + const [advancedMode, setAdvancedMode] = useState(false); + const setConversation = useSetRecoilState(store.conversation); const triggerAdvancedMode = () => setAdvancedMode(prev => !prev); + const switchToSimpleMode = () => { + setAdvancedMode(false); + setConversation(prevState => ({ + ...prevState, + chatGptLabel: null, + promptPrefix: null, + temperature: 0.8, + top_p: 1, + presence_penalty: 1 + })); + }; + if (endpoint !== 'openAI') return null; const { model } = conversation; const cardStyle = - 'shadow-md px-4 h-[40px] rounded-md min-w-[75px] font-normal bg-white border-black/10 border dark:bg-gray-700 text-black dark:text-white'; + 'shadow-md rounded-md min-w-[75px] font-normal bg-white border-black/10 border dark:bg-gray-700 text-black dark:text-white'; return ( <> -
+
+
+
content
); diff --git a/client/src/style.css b/client/src/style.css index 86e343e63c..4d143cd4d2 100644 --- a/client/src/style.css +++ b/client/src/style.css @@ -28,6 +28,31 @@ transition: all 1s ease-in-out; } */ +.openAIOptions-simple-container { + pointer-events: none; + opacity: 0; + transition: all 0.5s ease-in-out; +} + +.openAIOptions-simple-container.show { + pointer-events: fill; + opacity: 1; +} + +.openAIOptions-advanced-container { + pointer-events: none; + opacity: 0; + transition: all 0.2s ease-in-out; + transform: scaleY(0); + transform-origin: bottom center; +} + +.openAIOptions-advanced-container.show { + pointer-events: fill; + opacity: 1; + transform: scaleY(1) +} + .bing-styles { position: absolute; left: 0; From bb1f8d731b6812fe0077619b52e86deacdc01691 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 1 Apr 2023 00:38:05 +0800 Subject: [PATCH 2/2] feat: select model feat: force to be advanced mode --- .../Input/OpenAIOptions/ModelSelect.jsx | 54 +++++++++++++++++++ .../components/Input/OpenAIOptions/index.jsx | 42 +++++++++++---- 2 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 client/src/components/Input/OpenAIOptions/ModelSelect.jsx diff --git a/client/src/components/Input/OpenAIOptions/ModelSelect.jsx b/client/src/components/Input/OpenAIOptions/ModelSelect.jsx new file mode 100644 index 0000000000..73e2a7303b --- /dev/null +++ b/client/src/components/Input/OpenAIOptions/ModelSelect.jsx @@ -0,0 +1,54 @@ +import React, { useState } from 'react'; +import { Button } from '../../ui/Button.tsx'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuLabel, + DropdownMenuRadioGroup, + DropdownMenuSeparator, + DropdownMenuTrigger, + DropdownMenuRadioItem +} from '../../ui/DropdownMenu.tsx'; + +const ModelSelect = ({ model, onChange, models, ...props }) => { + const [menuOpen, setMenuOpen] = useState(false); + + models = ['gpt-4', 'text-davinci-003', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301']; + + return ( + + + + + event.preventDefault()} + > + Select a model + + + {models.map(model => ( + + {model} + + ))} + + + + ); +}; + +export default ModelSelect; diff --git a/client/src/components/Input/OpenAIOptions/index.jsx b/client/src/components/Input/OpenAIOptions/index.jsx index 0192ac8f0a..cbc9b1f15d 100644 --- a/client/src/components/Input/OpenAIOptions/index.jsx +++ b/client/src/components/Input/OpenAIOptions/index.jsx @@ -1,6 +1,6 @@ -import React, { useState, useEffect, forwardRef } from 'react'; -import { Tabs, TabsList, TabsTrigger } from '../../ui/Tabs.tsx'; -import { useRecoilValue, useRecoilState, useSetRecoilState } from 'recoil'; +import React, { useEffect, useState } from 'react'; +import { useSetRecoilState } from 'recoil'; +import ModelSelect from './ModelSelect'; import { Button } from '../../ui/Button.tsx'; import store from '~/store'; @@ -13,7 +13,6 @@ function OpenAIOptions({ conversation = {} }) { const triggerAdvancedMode = () => setAdvancedMode(prev => !prev); const switchToSimpleMode = () => { - setAdvancedMode(false); setConversation(prevState => ({ ...prevState, chatGptLabel: null, @@ -22,8 +21,31 @@ function OpenAIOptions({ conversation = {} }) { top_p: 1, presence_penalty: 1 })); + setAdvancedMode(false); }; + const setModel = newModel => { + setConversation(prevState => ({ + ...prevState, + model: newModel + })); + }; + + useEffect(() => { + const { endpoint, chatGptLabel, promptPrefix, temperature, top_p, presence_penalty } = conversation; + + if (endpoint !== 'openAI') return; + + const mustInAdvancedMode = + chatGptLabel !== null || + promptPrefix !== null || + temperature !== 0.8 || + top_p !== 1 || + presence_penalty !== 1; + + if (mustInAdvancedMode && !advancedMode) setAdvancedMode(true); + }, [conversation, advancedMode]); + if (endpoint !== 'openAI') return null; const { model } = conversation; @@ -39,15 +61,15 @@ function OpenAIOptions({ conversation = {} }) { (!advancedMode ? ' show' : '') } > - + />