From f6dcf0366fe14a02364980f8258a07ae09fa50fc Mon Sep 17 00:00:00 2001 From: an-lee Date: Fri, 2 Feb 2024 13:56:52 +0800 Subject: [PATCH] Fix: window hide & show, toast error for llm (#249) * fix window hide & show * toast error when llm failed --- enjoy/src/main/window.ts | 21 ++++++++++++------- .../components/messages/assistant-message.tsx | 4 ++++ enjoy/src/renderer/hooks/useConversation.tsx | 6 +++--- enjoy/src/renderer/pages/conversation.tsx | 3 ++- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/enjoy/src/main/window.ts b/enjoy/src/main/window.ts index 5e29d3d6..b913db4b 100644 --- a/enjoy/src/main/window.ts +++ b/enjoy/src/main/window.ts @@ -132,10 +132,10 @@ main.init = () => { mainWindow.setBrowserView(view); view.setBounds({ - x, - y, - width, - height, + x: Math.round(x), + y: Math.round(y), + width: Math.round(width), + height: Math.round(height), }); view.setAutoResize({ width: true, @@ -227,8 +227,8 @@ main.init = () => { logger.debug("current view bounds", bounds); view.setBounds({ - x: -bounds.width, - y: -bounds.height, + x: -Math.round(bounds.width), + y: -Math.round(bounds.height), width: 0, height: 0, }); @@ -247,9 +247,16 @@ main.init = () => { ) => { const view = mainWindow.getBrowserView(); if (!view) return; + if (!bounds) return; logger.debug("view-show", bounds); - view.setBounds(bounds); + const { x = 0, y = 0, width = 0, height = 0 } = bounds || {}; + view.setBounds({ + x: Math.round(x), + y: Math.round(y), + width: Math.round(width), + height: Math.round(height), + }); } ); diff --git a/enjoy/src/renderer/components/messages/assistant-message.tsx b/enjoy/src/renderer/components/messages/assistant-message.tsx index 17d6a5b4..a2889aed 100644 --- a/enjoy/src/renderer/components/messages/assistant-message.tsx +++ b/enjoy/src/renderer/components/messages/assistant-message.tsx @@ -11,6 +11,7 @@ import { SheetContent, SheetHeader, SheetClose, + toast, } from "@renderer/components/ui"; import { SpeechPlayer, @@ -70,6 +71,9 @@ export const AssistantMessageComponent = (props: { .then((speech) => { setSpeech(speech); }) + .catch((err) => { + toast.error(err.message); + }) .finally(() => { setSpeeching(false); }); diff --git a/enjoy/src/renderer/hooks/useConversation.tsx b/enjoy/src/renderer/hooks/useConversation.tsx index 19e96803..1f5f771d 100644 --- a/enjoy/src/renderer/hooks/useConversation.tsx +++ b/enjoy/src/renderer/hooks/useConversation.tsx @@ -47,7 +47,7 @@ export const useConversation = () => { return new ChatOpenAI({ openAIApiKey: openai.key, configuration: { - baseURL: baseUrl, + baseURL: baseUrl || openai.baseUrl, }, modelName: model, temperature, @@ -162,7 +162,7 @@ export const useConversation = () => { engine = currentEngine.name, model = "tts-1", voice = "alloy", - baseUrl = currentEngine.baseUrl, + baseUrl, } = configuration || {}; let client: OpenAI; @@ -176,7 +176,7 @@ export const useConversation = () => { } else { client = new OpenAI({ apiKey: openai.key, - baseURL: baseUrl, + baseURL: baseUrl || openai.baseUrl, dangerouslyAllowBrowser: true, }); } diff --git a/enjoy/src/renderer/pages/conversation.tsx b/enjoy/src/renderer/pages/conversation.tsx index 8ac1af9e..b1bdeb07 100644 --- a/enjoy/src/renderer/pages/conversation.tsx +++ b/enjoy/src/renderer/pages/conversation.tsx @@ -121,9 +121,10 @@ export default () => { }, 1000 * 60 * 5); chat(message, { conversation }) - .catch(() => { + .catch((err) => { message.status = "error"; dispatchMessages({ type: "update", record: message }); + toast.error(err.message); }) .finally(() => { setSubmitting(false);