diff --git a/src/components/ChatInput.vue b/src/components/ChatInput.vue index 46774a6..10c917b 100644 --- a/src/components/ChatInput.vue +++ b/src/components/ChatInput.vue @@ -19,7 +19,7 @@ const props = defineProps({ }); // emits -const emits = defineEmits(['addMessage', 'setChatLoading', 'saveMessage', 'clearMessages', 'toggleUserBehavior']); +const emits = defineEmits(['addMessage', 'setChatLoading', 'saveMessage', 'clearMessages', 'toggleUserBehavior', 'replaceMessages', 'setPromptForm']); // i18n const i18n = useI18n(); @@ -129,6 +129,16 @@ const doChat = async () => { .finally(() => emits('setChatLoading', false)); }; +const reGenerate = () => { + if (!props.localMessages.length) { + return; + } + emits('setChatLoading', true); + emits('replaceMessages', props.localMessages.slice(0, props.localMessages.length - 2)); + promptForm.value.content = props.localMessages[props.localMessages.length -2].content; + doChat(); +}; + // auto submit const lastMeta = ref(false); const allowSubmitKeys = ref(['Shift', 'Alt', 'Control', 'Meta']); @@ -144,6 +154,8 @@ const onKeydown = (event) => { }; const showEditBox = ref(true); + +defineExpose({reGenerate, promptForm});