Skip to content

Commit

Permalink
[shortcuts] Ctrl+Shift+O: current Chat Model options (temperature, et…
Browse files Browse the repository at this point in the history
…c..)
  • Loading branch information
enricoros committed Dec 5, 2023
1 parent fedd4b1 commit 31684c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
13 changes: 10 additions & 3 deletions src/apps/chat/AppChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { useBrowseStore } from '~/modules/browse/store-module-browsing';
import { useModelsStore } from '~/modules/llms/store-llms';

import { ConfirmationModal } from '~/common/components/ConfirmationModal';
import { GlobalShortcutItem, ShortcutKeyName, useGlobalShortcuts } from '~/common/components/useGlobalShortcut';
import { addSnackbar, removeSnackbar } from '~/common/components/useSnackbarsStore';
import { createDMessage, DConversationId, DMessage, getConversation, useConversation } from '~/common/state/store-chats';
import { GlobalShortcutItem, ShortcutKeyName, useGlobalShortcuts } from '~/common/components/useGlobalShortcut';
import { useLayoutPluggable } from '~/common/layout/store-applayout';
import { openLayoutLLMOptions, useLayoutPluggable } from '~/common/layout/store-applayout';
import { useUXLabsStore } from '~/common/state/store-ux-labs';

import { ChatDrawerItemsMemo } from './components/applayout/ChatDrawerItems';
Expand Down Expand Up @@ -291,15 +291,22 @@ export function AppChat() {

// Shortcuts

const handleOpenChatLlmOptions = React.useCallback(() => {
const { chatLLMId } = useModelsStore.getState();
if (!chatLLMId) return;
openLayoutLLMOptions(chatLLMId);
}, []);

const shortcuts = React.useMemo((): GlobalShortcutItem[] => [
['o', true, true, false, handleOpenChatLlmOptions],
['r', true, true, false, handleMessageRegenerateLast],
['n', true, false, true, handleConversationNew],
['b', true, false, true, () => isFocusedChatEmpty || focusedConversationId && handleConversationBranch(focusedConversationId, null)],
['x', true, false, true, () => isFocusedChatEmpty || focusedConversationId && handleConversationClear(focusedConversationId)],
['d', true, false, true, () => focusedConversationId && handleConversationDelete(focusedConversationId, false)],
[ShortcutKeyName.Left, true, false, true, () => handleNavigateHistory('back')],
[ShortcutKeyName.Right, true, false, true, () => handleNavigateHistory('forward')],
], [focusedConversationId, handleConversationBranch, handleConversationDelete, handleConversationNew, handleMessageRegenerateLast, handleNavigateHistory, isFocusedChatEmpty]);
], [focusedConversationId, handleConversationBranch, handleConversationDelete, handleConversationNew, handleMessageRegenerateLast, handleNavigateHistory, handleOpenChatLlmOptions, isFocusedChatEmpty]);
useGlobalShortcuts(shortcuts);


Expand Down
21 changes: 12 additions & 9 deletions src/apps/chat/components/applayout/useLLMDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import { openLayoutLLMOptions, openLayoutModelsSetup } from '~/common/layout/sto

function AppBarLLMDropdown(props: {
llms: DLLM[],
llmId: DLLMId | null,
setLlmId: (llmId: DLLMId | null) => void,
chatLlmId: DLLMId | null,
setChatLlmId: (llmId: DLLMId | null) => void,
placeholder?: string,
}) {

// build model menu items, filtering-out hidden models, and add Source separators
const llmItems: DropdownItems = {};
let prevSourceId: DModelSourceId | null = null;
for (const llm of props.llms) {
if (!llm.hidden || llm.id === props.llmId) {
if (!llm.hidden || llm.id === props.chatLlmId) {
if (!prevSourceId || llm.sId !== prevSourceId) {
if (prevSourceId)
llmItems[`sep-${llm.id}`] = { type: 'separator', title: llm.sId };
Expand All @@ -33,22 +33,25 @@ function AppBarLLMDropdown(props: {
}
}

const handleChatLLMChange = (_event: any, value: DLLMId | null) => value && props.setLlmId(value);
const handleChatLLMChange = (_event: any, value: DLLMId | null) => value && props.setChatLlmId(value);

const handleOpenLLMOptions = () => props.llmId && openLayoutLLMOptions(props.llmId);
const handleOpenLLMOptions = () => props.chatLlmId && openLayoutLLMOptions(props.chatLlmId);


return (
<AppBarDropdown
items={llmItems}
value={props.llmId} onChange={handleChatLLMChange}
value={props.chatLlmId} onChange={handleChatLLMChange}
placeholder={props.placeholder || 'Models …'}
appendOption={<>

{props.llmId && (
{props.chatLlmId && (
<ListItemButton key='menu-opt' onClick={handleOpenLLMOptions}>
<ListItemDecorator><SettingsIcon color='success' /></ListItemDecorator>
Options
<Box sx={{ flexGrow: 1, display: 'flex', justifyContent: 'space-between', gap: 1 }}>
Options
<KeyStroke combo='Ctrl + Shift + O' />
</Box>
</ListItemButton>
)}

Expand All @@ -74,7 +77,7 @@ export function useChatLLMDropdown() {
}), shallow);

const chatLLMDropdown = React.useMemo(
() => <AppBarLLMDropdown llms={llms} llmId={chatLLMId} setLlmId={setChatLLMId} />,
() => <AppBarLLMDropdown llms={llms} chatLlmId={chatLLMId} setChatLlmId={setChatLLMId} />,
[llms, chatLLMId, setChatLLMId],
);

Expand Down
3 changes: 2 additions & 1 deletion src/apps/settings-modal/ShortcutsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const shortcutsMd = `
| Ctrl + Alt + D | **Delete** chat |
| Ctrl + Alt + B | **Branch** chat |
| **Settings** | |
| Ctrl + Shift + M | 🧠 Models |
| Ctrl + Shift + P | ⚙️ Preferences |
| Ctrl + Shift + M | 🧠 Models |
| Ctrl + Shift + O | Options (current Chat Model) |
| Ctrl + Shift + ? | Shortcuts |
`.trim();
Expand Down

0 comments on commit 31684c2

Please sign in to comment.