From a84988363779c26453d40e68826764071e042ef8 Mon Sep 17 00:00:00 2001 From: Dmitri Nasonov Date: Fri, 13 Sep 2024 16:14:37 +0100 Subject: [PATCH] Added support for non-stream models (o1-) --- package.json | 2 +- public/locales/en/api.json | 13 +- public/locales/en/main.json | 1 + .../StopGeneratingButton.tsx | 21 +- src/constants/modelLoader.ts | 4 +- src/hooks/useSubmit.ts | 195 +++++++++++------- src/utils/modelReader.ts | 32 ++- 7 files changed, 187 insertions(+), 81 deletions(-) diff --git a/package.json b/package.json index 9921b4b98..014bb0c6a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "better-chatgpt", "private": true, - "version": "1.8.4", + "version": "1.9.0", "type": "module", "homepage": "./", "main": "electron/index.cjs", diff --git a/public/locales/en/api.json b/public/locales/en/api.json index 2485db13f..92a247c0a 100644 --- a/public/locales/en/api.json +++ b/public/locales/en/api.json @@ -15,5 +15,14 @@ }, "customEndpoint": "Use custom API endpoint", "advancedConfig": "View advanced API configuration <0>here", - "noApiKeyWarning": "No API key supplied! Please check your API settings." -} + "noApiKeyWarning": "No API key supplied! Please check your API settings.", + "errors": { + "errorGeneratingTitle": "Error generating title!", + "noMessagesSubmitted": "No messages submitted!", + "messageExceedMaxToken": "Message exceed max token!", + "failedToRetrieveData": "Failed to retrieve valid chat completion data.", + "streamLocked": "Oops, the stream is locked right now. Please try again", + "cancelledByUser": "Cancelled by user", + "generationCompleted": "Generation completed" + } +} \ No newline at end of file diff --git a/public/locales/en/main.json b/public/locales/en/main.json index 1c9ad0a42..97d3da69f 100644 --- a/public/locales/en/main.json +++ b/public/locales/en/main.json @@ -48,6 +48,7 @@ "cloned": "Cloned", "enterToSubmit": "Enter to submit", "submitPlaceholder": "Type a message or click [/] for prompts...", + "stopNonStreamGenerationWarning": "Stopping generation is not recommended for non-stream models. Only use it if UI is stuck. Do you want to proceed?", "reduceMessagesWarning": "Reducing messages may result in data loss. It is recommended to download the chat in JSON format if you care about the data. Do you want to proceed?", "reduceMessagesFailedImportWarning": "Full import failed as the data hit the maximum storage limit. Import as much as possible?", "partialImportWarning": "Full import failed as not all of the expected messages were imported: {{message}}. Would you like to import anyway?", diff --git a/src/components/StopGeneratingButton/StopGeneratingButton.tsx b/src/components/StopGeneratingButton/StopGeneratingButton.tsx index 295c0fd02..1ffbd9690 100644 --- a/src/components/StopGeneratingButton/StopGeneratingButton.tsx +++ b/src/components/StopGeneratingButton/StopGeneratingButton.tsx @@ -1,14 +1,31 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import useStore from '@store/store'; +import { useTranslation } from 'react-i18next'; +import { modelStreamSupport } from '@constants/modelLoader'; const StopGeneratingButton = () => { + const { t } = useTranslation(); const setGenerating = useStore((state) => state.setGenerating); const generating = useStore((state) => state.generating); + const currentModel = useStore((state) => + state.chats ? state.chats[state.currentChatIndex].config.model : '' + ); + const handleGeneratingStop = () => { + if (modelStreamSupport[currentModel]) { + setGenerating(false); + } else { + const confirmMessage = t('stopNonStreamGenerationWarning'); + if (window.confirm(confirmMessage)) { + setGenerating(false); + } + } + }; + return generating ? (
setGenerating(false)} + onClick={() => handleGeneratingStop()} >