From eabd5610bea3e964375eaee07a115db42e0cacd6 Mon Sep 17 00:00:00 2001 From: zbeyens Date: Wed, 6 Nov 2024 01:34:33 +0100 Subject: [PATCH] fix --- .../src/components/editor/plugins/copilot-plugins.tsx | 2 +- .../src/components/editor/use-chat.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/plate-playground-template/src/components/editor/plugins/copilot-plugins.tsx b/templates/plate-playground-template/src/components/editor/plugins/copilot-plugins.tsx index 13186ebc1e..21d7c600bb 100644 --- a/templates/plate-playground-template/src/components/editor/plugins/copilot-plugins.tsx +++ b/templates/plate-playground-template/src/components/editor/plugins/copilot-plugins.tsx @@ -28,6 +28,7 @@ export const copilotPlugins = [ - If no context is provided or you can't generate a continuation, return "0" without explanation.`, }, onError: () => { + // Mock the API response. Remove it when you implement the route /api/ai/copilot api.copilot.setBlockSuggestion({ text: stripMarkdown(faker.lorem.sentence()), }); @@ -36,7 +37,6 @@ export const copilotPlugins = [ if (completion === '0') return; api.copilot.setBlockSuggestion({ - //stripMarkdownBlocks in plus GhostText text: stripMarkdown(completion), }); }, diff --git a/templates/plate-playground-template/src/components/editor/use-chat.tsx b/templates/plate-playground-template/src/components/editor/use-chat.tsx index 9387373e82..93bbd9438d 100644 --- a/templates/plate-playground-template/src/components/editor/use-chat.tsx +++ b/templates/plate-playground-template/src/components/editor/use-chat.tsx @@ -50,10 +50,10 @@ export const useChat = () => { model: useOpenAI().model.value, }, fetch: async (input, init) => { - try { - return await fetch(input, init); - } catch (error) { - // Mock the API response. Remove it when you implement the route /api/ai + const res = await fetch(input, init); + + if (!res.ok) { + // Mock the API response. Remove it when you implement the route /api/ai/command await new Promise((resolve) => setTimeout(resolve, 400)); const stream = fakeStreamText(); @@ -65,6 +65,8 @@ export const useChat = () => { }, }); } + + return res; }, }); };