diff --git a/.dockerignore b/.dockerignore index c4477e489..a46e23147 100644 --- a/.dockerignore +++ b/.dockerignore @@ -63,7 +63,7 @@ dist # Gatsby files .cache/ -public + # Vuepress build output .vuepress/dist diff --git a/.env.template b/.env.template index 166cc4ef4..d53c1be6c 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 diff --git a/app/api/common.ts b/app/api/common.ts index 5eaa41d92..c6bf431fb 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -51,10 +51,6 @@ export async function requestOpenai( // 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( () => { @@ -110,12 +106,29 @@ export async function requestOpenai( 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 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 { + 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 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"); + } + // The latest version of the OpenAI API forced the content-encoding to be "br" in json response // So if the streaming is disabled, we need to remove the content-encoding header // Because Vercel uses gzip to compress the response, if we don't remove the content-encoding header diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 13bf46137..c02978c12 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -239,19 +239,31 @@ 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() { diff --git a/app/components/chat-list.tsx b/app/components/chat-list.tsx index 33967717d..7ef6e7b83 100644 --- a/app/components/chat-list.tsx +++ b/app/components/chat-list.tsx @@ -12,7 +12,7 @@ import { import { useChatStore } from "../store"; import Locale from "../locales"; -import { Link, useNavigate } from "react-router-dom"; +import { Link, useLocation, useNavigate } from "react-router-dom"; import { Path } from "../constant"; import { MaskAvatar } from "./mask"; import { Mask } from "../store/mask"; @@ -40,12 +40,16 @@ export function ChatItem(props: { }); } }, [props.selected]); + + const { pathname: currentPath } = useLocation(); return ( {(provided) => (
{ diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 218a4af6d..32a16c942 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -404,7 +404,16 @@ export function MaskPage() { const maskStore = useMaskStore(); const chatStore = useChatStore(); - const [filterLang, setFilterLang] = useState(); + const [filterLang, setFilterLang] = useState( + localStorage.getItem("Mask-language") as Lang | undefined, + ); + useEffect(() => { + if (filterLang) { + localStorage.setItem("Mask-language", filterLang); + } else { + localStorage.removeItem("Mask-language"); + } + }, [filterLang]); const allMasks = maskStore .getAll() diff --git a/app/components/message-selector.tsx b/app/components/message-selector.tsx index 840e480cb..8198a3cd4 100644 --- a/app/components/message-selector.tsx +++ b/app/components/message-selector.tsx @@ -227,7 +227,7 @@ export function MessageSelector(props: {
- +
); diff --git a/app/store/chat.ts b/app/store/chat.ts index 8e313463f..24e1b078d 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -865,6 +865,7 @@ export const useChatStore = createPersistStore( messages: topicMessages, config: { model: getSummarizeModel(session.mask.modelConfig.model), + stream: false, }, onFinish(message) { get().updateCurrentSession( @@ -908,6 +909,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({ @@ -917,7 +922,7 @@ export const useChatStore = createPersistStore( }), ), config: { - ...modelConfig, + ...modelcfg, stream: true, model: getSummarizeModel(session.mask.modelConfig.model), }, diff --git a/app/utils/cloud/webdav.ts b/app/utils/cloud/webdav.ts index bc569de0e..e01c193fe 100644 --- a/app/utils/cloud/webdav.ts +++ b/app/utils/cloud/webdav.ts @@ -18,8 +18,15 @@ export function createWebDavClient(store: SyncStore) { method: "MKCOL", headers: this.headers(), }); - console.log("[WebDav] check", res.status, res.statusText); - return [201, 200, 404, 301, 302, 307, 308].includes(res.status); + const success = [201, 200, 404, 405, 301, 302, 307, 308].includes( + res.status, + ); + console.log( + `[WebDav] check ${success ? "success" : "failed"}, ${res.status} ${ + res.statusText + }`, + ); + return success; } catch (e) { console.error("[WebDav] failed to check", e); }