Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds config option to use ENTER to send message #164

Merged
merged 6 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adds new config option to swap enter, shift+enter behavior
  • Loading branch information
JasonWeill committed May 17, 2023
commit c484d6c9bf15c7c77b3f2acf70e4579b40168fea
1 change: 1 addition & 0 deletions packages/jupyter-ai/jupyter_ai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 41 additions & 2 deletions packages/jupyter-ai/src/components/chat-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Box } from '@mui/system';
import {
Alert,
Button,
FormControl,
FormControlLabel,
FormLabel,
MenuItem,
Radio,
RadioGroup,
TextField,
CircularProgress
} from '@mui/material';
Expand Down Expand Up @@ -42,7 +47,8 @@ export function ChatSettings() {
const [inputConfig, setInputConfig] = useState<AiService.Config>({
model_provider_id: null,
embeddings_provider_id: null,
api_keys: {}
api_keys: {},
send_with_shift_enter: null
});

// whether the form is currently saving
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -256,6 +263,38 @@ export function ChatSettings() {
/>
)
)}
<FormControl>
<FormLabel id="send-radio-buttons-group-label">
When writing a message, press <kbd>Enter</kbd> to:
</FormLabel>
<RadioGroup
aria-labelledby="send-radio-buttons-group-label"
value={
(inputConfig.send_with_shift_enter ?? true) ? 'newline' : 'send'
}
name="send-radio-buttons-group"
onChange={e =>
setInputConfig(inputConfig => {
return ({
...inputConfig,
send_with_shift_enter: (e.target as HTMLInputElement).value === 'newline'
});
})}
>
<FormControlLabel
value="newline"
control={<Radio />}
label={
<>Start a new line (use <kbd>Shift</kbd>+<kbd>Enter</kbd> to send)</>
}
/>
<FormControlLabel
value="send"
control={<Radio />}
label="Send the message"
/>
</RadioGroup>
</FormControl>
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button variant="contained" onClick={handleSave} disabled={saving}>
{saving ? 'Saving...' : 'Save changes'}
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-ai/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export namespace AiService {
model_provider_id: string | null;
embeddings_provider_id: string | null;
api_keys: Record<string, string>;
send_with_shift_enter: boolean | null;
};

export type GetConfigResponse = Config;
Expand Down