From 544bab0fe29fa9c62d6d8fd5026c97d2efda3d96 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Thu, 9 Nov 2023 20:56:45 +0700 Subject: [PATCH 1/7] Refactor Summarize Logic [+] chore(chat.ts): remove unnecessary comment and refactor variable name [+] feat(chat.ts): add stream: false to config object --- app/store/chat.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index ff7eb51b5c1..6eb4e934f18 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -494,6 +494,7 @@ export const useChatStore = createPersistStore( messages: topicMessages, config: { model: getSummarizeModel(session.mask.modelConfig.model), + stream: false, }, onFinish(message) { get().updateCurrentSession( @@ -539,6 +540,10 @@ export const useChatStore = createPersistStore( historyMsgLength > modelConfig.compressMessageLengthThreshold && modelConfig.sendMemory ) { + /** Destruct max_tokens while summarizing + * this param is just shit + **/ + const { max_tokens, ...modelcfg } = modelConfig; api.llm.chat({ messages: toBeSummarizedMsgs.concat( createMessage({ @@ -548,7 +553,7 @@ export const useChatStore = createPersistStore( }), ), config: { - ...modelConfig, + ...modelcfg, stream: true, model: getSummarizeModel(session.mask.modelConfig.model), }, From 39f3afd52c86c175f16c08b5b22cbcd9e05de9b4 Mon Sep 17 00:00:00 2001 From: SurKaa <98200894+surkaa@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:22:56 +0800 Subject: [PATCH 2/7] =?UTF-8?q?Update=20.env.template=20=E6=9B=B4=E6=AD=A3?= =?UTF-8?q?=E5=8D=95=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 3e32903695c..ba7224dea0a 100644 --- a/.env.template +++ b/.env.template @@ -2,7 +2,7 @@ # Your openai api key. (required) OPENAI_API_KEY=sk-xxxx -# Access passsword, separated by comma. (optional) +# Access password, separated by comma. (optional) CODE=your-password # You can start service behind a proxy From fe0f078353c1f6ee621ceca793747fda84cd1b81 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Sun, 19 Nov 2023 19:49:52 +0700 Subject: [PATCH 3/7] Feat ChatGPT LLM Api [Console Log] [Text Moderation] [Azure] [+] fix(openai.ts): fix parsing error in ChatGPTApi's message handler [+] feat(openai.ts): add logging for flagged categories in text moderation --- app/client/platforms/openai.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 8ea864692d5..5ca7d43b546 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -197,19 +197,21 @@ export class ChatGPTApi implements LLMApi { } const text = msg.data; try { - const json = JSON.parse(text) as { - choices: Array<{ - delta: { - content: string; - }; - }>; - }; - const delta = json.choices[0]?.delta?.content; + const json = JSON.parse(text); + const choices = json.choices as Array<{ delta: { content: string } }>; + const delta = choices[0]?.delta?.content; + const textmoderation = json?.prompt_filter_results; + if (delta) { remainText += delta; } + + if (textmoderation && textmoderation.length > 0 && ServiceProvider.Azure) { + const contentFilterResults = textmoderation[0]?.content_filter_results; + console.log(`[${ServiceProvider.Azure}] [Text Moderation] flagged categories result:`, contentFilterResults); + } } catch (e) { - console.error("[Request] parse error", text); + console.error("[Request] parse error", text, msg); } }, onclose() { From 10ea9bf1e39d982fce208da2925200ec88371409 Mon Sep 17 00:00:00 2001 From: frankylli Date: Wed, 29 Nov 2023 16:25:15 +0800 Subject: [PATCH 4/7] fix: MessageSelectorWarning --- app/components/message-selector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/message-selector.tsx b/app/components/message-selector.tsx index c2015340139..4f46ebb8112 100644 --- a/app/components/message-selector.tsx +++ b/app/components/message-selector.tsx @@ -224,7 +224,7 @@ export function MessageSelector(props: {
- +
); From 36e9c6ac4dc7d7279bfd9e4c79b10185b1ceb14d Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 1 Dec 2023 19:48:10 +0700 Subject: [PATCH 5/7] Refactor Api Common [Server Side] [Console Log] - [+] refactor(common.ts): remove unnecessary console.log for [Org ID] in requestOpenai function - [+] refactor(common.ts): conditionally delete OpenAI-Organization header from response if [Org ID] is not set up in ENV --- app/api/common.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 6b0d619df1d..da5163f4e71 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -30,10 +30,6 @@ export async function requestOpenai(req: NextRequest) { console.log("[Proxy] ", path); console.log("[Base Url]", baseUrl); - // this fix [Org ID] undefined in server side if not using custom point - if (serverConfig.openaiOrgId !== undefined) { - console.log("[Org ID]", serverConfig.openaiOrgId); - } const timeoutId = setTimeout( () => { @@ -103,12 +99,29 @@ export async function requestOpenai(req: NextRequest) { try { const res = await fetch(fetchUrl, fetchOptions); + // Extract the OpenAI-Organization header from the response + const openaiOrganizationHeader = res.headers.get("OpenAI-Organization"); + + // Check if serverConfig.openaiOrgId is defined + if (serverConfig.openaiOrgId !== undefined) { + // If openaiOrganizationHeader is present, log it; otherwise, log that the header is not present + console.log("[Org ID]", openaiOrganizationHeader); + } else { + console.log("[Org ID] is not set up."); + } + // to prevent browser prompt for credentials const newHeaders = new Headers(res.headers); newHeaders.delete("www-authenticate"); // to disable nginx buffering newHeaders.set("X-Accel-Buffering", "no"); + // Conditionally delete the OpenAI-Organization header from the response if [Org ID] is undefined (not setup in ENV) + // Also This one is to prevent the header from being sent to the client + if (!serverConfig.openaiOrgId) { + newHeaders.delete("OpenAI-Organization"); + } + return new Response(res.body, { status: res.status, statusText: res.statusText, From 8dc868207855da0de077aca739a2d5b186127326 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 4 Dec 2023 13:32:11 +0700 Subject: [PATCH 6/7] Fix Api Common [Server Side] - [+] fix(common.ts): improve handling of OpenAI-Organization header - Check if serverConfig.openaiOrgId is defined and not an empty string - Log the value of openaiOrganizationHeader if present, otherwise log that the header is not present - Conditionally delete the OpenAI-Organization header from the response if [Org ID] is undefined or empty (not setup in ENV) --- app/api/common.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index da5163f4e71..48ddfb5f038 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -102,8 +102,8 @@ export async function requestOpenai(req: NextRequest) { // Extract the OpenAI-Organization header from the response const openaiOrganizationHeader = res.headers.get("OpenAI-Organization"); - // Check if serverConfig.openaiOrgId is defined - if (serverConfig.openaiOrgId !== undefined) { + // Check if serverConfig.openaiOrgId is defined and not an empty string + if (serverConfig.openaiOrgId && serverConfig.openaiOrgId.trim() !== "") { // If openaiOrganizationHeader is present, log it; otherwise, log that the header is not present console.log("[Org ID]", openaiOrganizationHeader); } else { @@ -116,9 +116,9 @@ export async function requestOpenai(req: NextRequest) { // to disable nginx buffering newHeaders.set("X-Accel-Buffering", "no"); - // Conditionally delete the OpenAI-Organization header from the response if [Org ID] is undefined (not setup in ENV) - // Also This one is to prevent the header from being sent to the client - if (!serverConfig.openaiOrgId) { + // Conditionally delete the OpenAI-Organization header from the response if [Org ID] is undefined or empty (not setup in ENV) + // Also, this is to prevent the header from being sent to the client + if (!serverConfig.openaiOrgId || serverConfig.openaiOrgId.trim() === "") { newHeaders.delete("OpenAI-Organization"); } From 53fb52c6c029493589facd13949362da062bab3b Mon Sep 17 00:00:00 2001 From: hmhuming <461669486@qq.com> Date: Wed, 27 Mar 2024 17:58:55 +0800 Subject: [PATCH 7/7] fix docker --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index a88c7d61641..95ed9e268e4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -63,7 +63,7 @@ dist # Gatsby files .cache/ -public + # Vuepress build output .vuepress/dist