Skip to content

Commit

Permalink
Ctrl+Shift+R: regenerate assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Nov 8, 2023
1 parent c695d4b commit ce2441a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/apps/chat/AppChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useModelsStore } from '~/modules/llms/store-llms';

import { ConfirmationModal } from '~/common/components/ConfirmationModal';
import { createDMessage, DMessage, useChatStore } from '~/common/state/store-chats';
import { useGlobalShortcut } from '~/common/components/useGlobalShortcut';
import { useLayoutPluggable } from '~/common/layout/store-applayout';

import { ChatDrawerItems } from './components/applayout/ChatDrawerItems';
Expand Down Expand Up @@ -134,6 +135,19 @@ export function AppChat() {
return await handleExecuteConversation(chatModeId, conversationId, [...conversation.messages, createDMessage('user', userText)]);
};

const handleRegenerateAssistant = async () => {
const conversation = activeConversationId ? _findConversation(activeConversationId) : null;
if (conversation?.messages?.length) {
const lastMessage = conversation.messages[conversation.messages.length - 1];
if (lastMessage.role === 'assistant') {
const newMessages = [...conversation.messages];
newMessages.pop();
return await handleExecuteConversation('immediate', conversation.id, newMessages);
}
}
};
useGlobalShortcut('r', true, true, handleRegenerateAssistant);


const handleClearConversation = (conversationId: string) => setClearConfirmationId(conversationId);

Expand Down
13 changes: 11 additions & 2 deletions src/apps/chat/components/message/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import { CloseableMenu } from '~/common/components/CloseableMenu';
import { DMessage } from '~/common/state/store-chats';
import { InlineError } from '~/common/components/InlineError';
import { InlineTextarea } from '~/common/components/InlineTextarea';
import { KeyStroke } from '~/common/components/KeyStroke';
import { Link } from '~/common/components/Link';
import { SystemPurposeId, SystemPurposes } from '../../../../data';
import { copyToClipboard } from '~/common/util/copyToClipboard';
import { cssRainbowColorKeyframes } from '~/common/theme';
import { cssRainbowColorKeyframes, hideOnMobile } from '~/common/theme';
import { prettyBaseModel } from '~/common/util/modelUtils';
import { useUIPreferencesStore } from '~/common/state/store-ui';

Expand Down Expand Up @@ -446,7 +447,15 @@ export function ChatMessage(props: { message: DMessage, diffText?: string, showD
{!!props.onMessageRunFrom && (
<MenuItem onClick={handleMenuRunAgain}>
<ListItemDecorator>{fromAssistant ? <ReplayIcon /> : <FastForwardIcon />}</ListItemDecorator>
{fromAssistant ? 'Retry' : 'Run from here'}
{!fromAssistant
? 'Run from here'
: !props.isBottom
? 'Retry from here'
: <Box sx={{ flexGrow: 1, display: 'flex', justifyContent: 'space-between', gap: 1 }}>
Retry
<KeyStroke light combo='Ctrl + Shift + R' sx={hideOnMobile} />
</Box>
}
</MenuItem>
)}
{isImaginable && isImaginableEnabled && (
Expand Down
5 changes: 3 additions & 2 deletions src/common/components/KeyStroke.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from 'react';

import { Chip } from '@mui/joy';
import { SxProps } from '@mui/system';

/**
* Shows a shortcut combo in a nicely presented dark box.
*/
export function KeyStroke(props: { combo: string }) {
export function KeyStroke(props: { combo: string, light?: boolean, sx?: SxProps }) {
return (
<Chip variant='solid' color='neutral'>
<Chip variant={props.light ? 'outlined' : 'solid'} color='neutral' sx={props.sx}>
{props.combo}
</Chip>
// <Box sx={{
Expand Down

1 comment on commit ce2441a

@vercel
Copy link

@vercel vercel bot commented on ce2441a Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

big-agi – ./

big-agi-git-main-enricoros.vercel.app
big-agi-enricoros.vercel.app
get.big-agi.com

Please sign in to comment.