From c484d6c9bf15c7c77b3f2acf70e4579b40168fea Mon Sep 17 00:00:00 2001 From: Jason Weill Date: Thu, 11 May 2023 15:08:45 -0700 Subject: [PATCH 1/6] Adds new config option to swap enter, shift+enter behavior --- packages/jupyter-ai/jupyter_ai/models.py | 1 + .../src/components/chat-settings.tsx | 43 ++++++++++++++++++- packages/jupyter-ai/src/handler.ts | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/models.py b/packages/jupyter-ai/jupyter_ai/models.py index a9f28768a..7cef9e5d0 100644 --- a/packages/jupyter-ai/jupyter_ai/models.py +++ b/packages/jupyter-ai/jupyter_ai/models.py @@ -107,3 +107,4 @@ class GlobalConfig(BaseModel): model_provider_id: Optional[str] = None embeddings_provider_id: Optional[str] = None api_keys: Dict[str, str] = {} + send_with_shift_enter: Optional[bool] = None diff --git a/packages/jupyter-ai/src/components/chat-settings.tsx b/packages/jupyter-ai/src/components/chat-settings.tsx index d36a3bf63..a069ff78d 100644 --- a/packages/jupyter-ai/src/components/chat-settings.tsx +++ b/packages/jupyter-ai/src/components/chat-settings.tsx @@ -3,7 +3,12 @@ import { Box } from '@mui/system'; import { Alert, Button, + FormControl, + FormControlLabel, + FormLabel, MenuItem, + Radio, + RadioGroup, TextField, CircularProgress } from '@mui/material'; @@ -42,7 +47,8 @@ export function ChatSettings() { const [inputConfig, setInputConfig] = useState({ model_provider_id: null, embeddings_provider_id: null, - api_keys: {} + api_keys: {}, + send_with_shift_enter: null }); // whether the form is currently saving @@ -109,7 +115,8 @@ export function ChatSettings() { const handleSave = async () => { const inputConfigCopy: AiService.Config = { ...inputConfig, - api_keys: { ...inputConfig.api_keys } + api_keys: { ...inputConfig.api_keys }, + send_with_shift_enter: inputConfig.send_with_shift_enter ?? true }; // delete any empty api keys @@ -256,6 +263,38 @@ export function ChatSettings() { /> ) )} + + + When writing a message, press Enter to: + + + setInputConfig(inputConfig => { + return ({ + ...inputConfig, + send_with_shift_enter: (e.target as HTMLInputElement).value === 'newline' + }); + })} + > + } + label={ + <>Start a new line (use Shift+Enter to send) + } + /> + } + label="Send the message" + /> + +