diff --git a/CHANGELOG.md b/CHANGELOG.md index 4962b16..d207517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v0.0.18 - 2023-04-27 +### Fixed +- Fix using chatgpt web +- Enhance error message + ## v0.0.17 - 2023-04-25 ### Added - Support new bing as backend engine diff --git a/package.json b/package.json index 357847c..67fb1d4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "notionai-plus", "displayName": "NotionAI Plus", - "version": "0.0.17", + "version": "0.0.18", "description": "NotionAI Plus is a browser extension that brings the power of NotionAI to any website you visit.", "scripts": { "dev": "plasmo dev", diff --git a/src/background/ports/stream.ts b/src/background/ports/stream.ts index a260409..4cdef1b 100644 --- a/src/background/ports/stream.ts +++ b/src/background/ports/stream.ts @@ -2,9 +2,9 @@ import type { PlasmoMessaging } from "@plasmohq/messaging" import { BardChat } from "~lib/api/bard" import { BingChat } from "~lib/api/bing" -import { ChatStream } from "~lib/api/chatgpt-api" -import { PostChatGPTStream } from "~lib/api/chatgpt-web" -import { PostNotionStream } from "~lib/api/notion-completion" +import { ChatGPTApiChat } from "~lib/api/chatgpt-api" +import { ChatGPTWebChat } from "~lib/api/chatgpt-web" +import { NotionCompletion } from "~lib/api/notion-completion" import { EngineEnum } from "~lib/enums" import { RequestBody, @@ -22,13 +22,13 @@ const handler: PlasmoMessaging.PortHandler = async (req, res) => { switch (body.engine) { case EngineEnum.ChatGPTWeb: - await PostChatGPTStream(`${instruction}\n\n${prompt}`, res) + await ChatGPTWebChat(`${instruction}\n\n${prompt}`, res) break case EngineEnum.Bing: await BingChat(`${instruction}\n\n${prompt}`, res) break case EngineEnum.ChatGPTAPI: - await ChatStream( + await ChatGPTApiChat( OPENAI_API_URL, instruction, prompt, @@ -40,7 +40,7 @@ const handler: PlasmoMessaging.PortHandler = async (req, res) => { await BardChat(`${instruction}\n\n${prompt}`, res) break case EngineEnum.NotionBoy: - await ChatStream( + await ChatGPTApiChat( NOTIONBOY_API_URL, instruction, prompt, @@ -49,7 +49,7 @@ const handler: PlasmoMessaging.PortHandler = async (req, res) => { ) break case EngineEnum.NotionAI: - await PostNotionStream( + await NotionCompletion( res, body.builtinPrompt, body.context, diff --git a/src/lib/api/chatgpt-api.ts b/src/lib/api/chatgpt-api.ts index a9fc542..f8dfb2c 100644 --- a/src/lib/api/chatgpt-api.ts +++ b/src/lib/api/chatgpt-api.ts @@ -53,7 +53,7 @@ async function chat( }) } -async function ChatStream( +async function ChatGPTApiChat( url: string, instraction: string, prompt: string, @@ -78,4 +78,4 @@ async function ChatStream( res.send(message) } -export { ChatStream } +export { ChatGPTApiChat } diff --git a/src/lib/api/chatgpt-web.ts b/src/lib/api/chatgpt-web.ts index 2e9c158..7b697e5 100644 --- a/src/lib/api/chatgpt-web.ts +++ b/src/lib/api/chatgpt-web.ts @@ -27,7 +27,7 @@ async function getAccessToken(): Promise { return data.accessToken } -async function PostChatGPTStream( +async function ChatGPTWebChat( prompt: string, res: PlasmoMessaging.Response ) { @@ -120,4 +120,4 @@ async function removeConversation(id: string) { } } -export { PostChatGPTStream } +export { ChatGPTWebChat } diff --git a/src/lib/api/notion-completion.ts b/src/lib/api/notion-completion.ts index f639a64..865ed68 100644 --- a/src/lib/api/notion-completion.ts +++ b/src/lib/api/notion-completion.ts @@ -81,7 +81,7 @@ async function complation( await processNdjsonResp(resp, onMessage) } -async function PostNotionStream( +async function NotionCompletion( res: PlasmoMessaging.Response, promptType: string, context: string, @@ -115,4 +115,4 @@ async function PostNotionStream( res.send(message) } -export { PostNotionStream } +export { NotionCompletion } diff --git a/src/lib/utils/fetch.ts b/src/lib/utils/fetch.ts deleted file mode 100644 index 6a59b61..0000000 --- a/src/lib/utils/fetch.ts +++ /dev/null @@ -1,28 +0,0 @@ -// fetch with retry -export async function rfetch( - input: RequestInfo | URL, - init?: RequestInit -): Promise { - let message = "" - for (let i = 0; i < 3; i++) { - try { - return await ifetch(input, init) - } catch (err) { - console.error(err) - message = err.message - } - } - throw new Error(message) -} - -async function ifetch( - input: RequestInfo | URL, - init?: RequestInit -): Promise { - const resp = await fetch(input, init) - if (resp.status == 200) { - return resp - } else { - throw new Error(`Fetch error, status: ${resp.status}`) - } -}