Merge pull request #23 from sijinhui/dev

修复对话中滚动异常
This commit is contained in:
sijinhui 2024-02-27 17:57:32 +08:00 committed by GitHub
commit 1633ff5963
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 8 deletions

View File

@ -112,6 +112,17 @@ export class ChatGPTApi implements LLMApi {
}; };
// console.log("[Request] openai payload: ", requestPayload); // 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 shouldStream = !!options.config.stream;
const controller = new AbortController(); const controller = new AbortController();

View File

@ -6,6 +6,7 @@ import React, {
useMemo, useMemo,
useCallback, useCallback,
Fragment, Fragment,
RefObject,
} from "react"; } from "react";
import SendWhiteIcon from "../icons/send-white.svg"; import SendWhiteIcon from "../icons/send-white.svg";
@ -396,11 +397,13 @@ function ChatAction(props: {
); );
} }
function useScrollToBottom() { function useScrollToBottom(
scrollRef: RefObject<HTMLDivElement>,
detach: boolean = false,
) {
// for auto-scroll // for auto-scroll
const scrollRef = useRef<HTMLDivElement>(null);
const [autoScroll, setAutoScroll] = useState(true);
const [autoScroll, setAutoScroll] = useState(true);
function scrollDomToBottom() { function scrollDomToBottom() {
const dom = scrollRef.current; const dom = scrollRef.current;
if (dom) { if (dom) {
@ -413,7 +416,7 @@ function useScrollToBottom() {
// auto scroll // auto scroll
useEffect(() => { useEffect(() => {
if (autoScroll) { if (autoScroll && !detach) {
scrollDomToBottom(); scrollDomToBottom();
} }
}); });
@ -688,7 +691,17 @@ function _Chat() {
const [mjImageMode, setMjImageMode] = useState<string>("IMAGINE"); const [mjImageMode, setMjImageMode] = useState<string>("IMAGINE");
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { submitKey, shouldSubmit } = useSubmitHandler(); const { submitKey, shouldSubmit } = useSubmitHandler();
const { scrollRef, setAutoScroll, scrollDomToBottom } = useScrollToBottom(); const scrollRef = useRef<HTMLDivElement>(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 [hitBottom, setHitBottom] = useState(true);
const isMobileScreen = useMobileScreen(); const isMobileScreen = useMobileScreen();
const navigate = useNavigate(); const navigate = useNavigate();
@ -1037,7 +1050,6 @@ function _Chat() {
setHitBottom(isHitBottom); setHitBottom(isHitBottom);
setAutoScroll(isHitBottom); setAutoScroll(isHitBottom);
}; };
function scrollToBottom() { function scrollToBottom() {
setMsgRenderIndex(renderMessages.length - CHAT_PAGE_SIZE); setMsgRenderIndex(renderMessages.length - CHAT_PAGE_SIZE);
scrollDomToBottom(); scrollDomToBottom();

View File

@ -112,9 +112,9 @@ export const GEMINI_SUMMARIZE_MODEL = "gemini-pro";
export const KnowledgeCutOffDate: Record<string, string> = { export const KnowledgeCutOffDate: Record<string, string> = {
default: "2021-09", default: "2021-09",
"gpt-4-turbo-preview": "2023-04", "gpt-4-turbo-preview": "2023-12",
"gpt-4-1106-preview": "2023-04", "gpt-4-1106-preview": "2023-04",
"gpt-4-0125-preview": "2023-04", "gpt-4-0125-preview": "2023-12",
"gpt-4-vision-preview": "2023-04", "gpt-4-vision-preview": "2023-04",
// After improvements, // After improvements,
// it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously. // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.