diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index e145c0a02..f77f08dbf 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -112,6 +112,17 @@ export class ChatGPTApi implements LLMApi { }; // console.log("[Request] openai payload: ", requestPayload); + // add max_tokens to vision model + if (visionModel) { + Object.defineProperty(requestPayload, "max_tokens", { + enumerable: true, + configurable: true, + writable: true, + value: Math.max(modelConfig.max_tokens, 4096), + }); + } + + console.log("[Request] openai payload: ", requestPayload); const shouldStream = !!options.config.stream; const controller = new AbortController(); diff --git a/app/components/chat.tsx b/app/components/chat.tsx index acee90610..51a4b54af 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -6,6 +6,7 @@ import React, { useMemo, useCallback, Fragment, + RefObject, } from "react"; import SendWhiteIcon from "../icons/send-white.svg"; @@ -396,11 +397,13 @@ function ChatAction(props: { ); } -function useScrollToBottom() { +function useScrollToBottom( + scrollRef: RefObject, + detach: boolean = false, +) { // for auto-scroll - const scrollRef = useRef(null); - const [autoScroll, setAutoScroll] = useState(true); + const [autoScroll, setAutoScroll] = useState(true); function scrollDomToBottom() { const dom = scrollRef.current; if (dom) { @@ -413,7 +416,7 @@ function useScrollToBottom() { // auto scroll useEffect(() => { - if (autoScroll) { + if (autoScroll && !detach) { scrollDomToBottom(); } }); @@ -688,7 +691,17 @@ function _Chat() { const [mjImageMode, setMjImageMode] = useState("IMAGINE"); const [isLoading, setIsLoading] = useState(false); const { submitKey, shouldSubmit } = useSubmitHandler(); - const { scrollRef, setAutoScroll, scrollDomToBottom } = useScrollToBottom(); + const scrollRef = useRef(null); + const isScrolledToBottom = scrollRef?.current + ? Math.abs( + scrollRef.current.scrollHeight - + (scrollRef.current.scrollTop + scrollRef.current.clientHeight), + ) <= 1 + : false; + const { setAutoScroll, scrollDomToBottom } = useScrollToBottom( + scrollRef, + isScrolledToBottom, + ); const [hitBottom, setHitBottom] = useState(true); const isMobileScreen = useMobileScreen(); const navigate = useNavigate(); @@ -1037,7 +1050,6 @@ function _Chat() { setHitBottom(isHitBottom); setAutoScroll(isHitBottom); }; - function scrollToBottom() { setMsgRenderIndex(renderMessages.length - CHAT_PAGE_SIZE); scrollDomToBottom(); diff --git a/app/constant.ts b/app/constant.ts index 3b9d88f74..851dfdb37 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -112,9 +112,9 @@ export const GEMINI_SUMMARIZE_MODEL = "gemini-pro"; export const KnowledgeCutOffDate: Record = { default: "2021-09", - "gpt-4-turbo-preview": "2023-04", + "gpt-4-turbo-preview": "2023-12", "gpt-4-1106-preview": "2023-04", - "gpt-4-0125-preview": "2023-04", + "gpt-4-0125-preview": "2023-12", "gpt-4-vision-preview": "2023-04", // After improvements, // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.