fix: query modelscope files by recursive

This commit is contained in:
jialin
2024-09-27 16:50:09 +08:00
parent 7e985991cd
commit 49c0467428
26 changed files with 292 additions and 118 deletions
@@ -1,4 +1,6 @@
import useOverlayScroller from '@/hooks/use-overlay-scroller';
import _ from 'lodash';
import 'overlayscrollbars/overlayscrollbars.css';
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import CompareContext from '../../config/compare-context';
import { MessageItem, ModelSelectionItem } from '../../config/types';
@@ -14,6 +16,7 @@ interface MultiCompareProps {
}
const MultiCompare: React.FC<MultiCompareProps> = ({ modelList }) => {
const { initialize } = useOverlayScroller();
const [loadingStatus, setLoadingStatus] = useState<Record<symbol, boolean>>(
{}
);
@@ -36,6 +39,7 @@ const MultiCompare: React.FC<MultiCompareProps> = ({ modelList }) => {
});
const modelsCounterMap = useRef<Record<string, number>>({});
const modelRefs = useRef<any>({});
const chatListScrollRef = useRef<any>(null);
const boxHeight = 'calc(100vh - 72px)';
const isLoading = useMemo(() => {
@@ -249,29 +253,33 @@ const MultiCompare: React.FC<MultiCompareProps> = ({ modelList }) => {
setModelSelections(resultList);
}, [modelList]);
useEffect(() => {
if (chatListScrollRef.current) {
initialize(chatListScrollRef.current);
}
}, [chatListScrollRef.current, initialize]);
return (
<div className="multiple-chat" style={{ height: boxHeight }}>
<div className="chat-list">
<div className="chat-list-inner">
<CompareContext.Provider
value={{
spans,
globalParams,
loadingStatus,
modelFullList: modelList,
handleApplySystemChangeToAll,
setGlobalParams,
setLoadingStatus: handleSetLoadingStatus,
handleDeleteModel: handleDeleteModel
}}
>
<ActiveModels
spans={spans}
modelSelections={modelSelections}
setModelRefs={setModelRefs}
></ActiveModels>
</CompareContext.Provider>
</div>
<div className="chat-list" ref={chatListScrollRef}>
<CompareContext.Provider
value={{
spans,
globalParams,
loadingStatus,
modelFullList: modelList,
handleApplySystemChangeToAll,
setGlobalParams,
setLoadingStatus: handleSetLoadingStatus,
handleDeleteModel: handleDeleteModel
}}
>
<ActiveModels
spans={spans}
modelSelections={modelSelections}
setModelRefs={setModelRefs}
></ActiveModels>
</CompareContext.Provider>
</div>
<div>
<MessageInput
@@ -31,6 +31,7 @@ const MessageContent: React.FC<MessageContentProps> = ({
newMessageList.splice(index, 1);
setMessageList?.(newMessageList);
};
return (
<>
{!!messageList.length && (
@@ -1,4 +1,5 @@
import IconFont from '@/components/icon-font';
import useOverlayScroller from '@/hooks/use-overlay-scroller';
import { fetchChunkedData, readStreamData } from '@/utils/fetch-chunk-data';
import {
ClearOutlined,
@@ -9,6 +10,7 @@ import {
import { useIntl } from '@umijs/max';
import { Button, Checkbox, Dropdown, Popover, Select, Spin } from 'antd';
import _ from 'lodash';
import 'overlayscrollbars/overlayscrollbars.css';
import React, {
forwardRef,
useContext,
@@ -18,7 +20,6 @@ import React, {
useRef,
useState
} from 'react';
import SimpleBar from 'simplebar-react';
import 'simplebar-react/dist/simplebar.min.css';
import { CHAT_API } from '../../apis';
import { Roles } from '../../config';
@@ -62,6 +63,9 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
const contentRef = useRef<any>('');
const controllerRef = useRef<any>(null);
const currentMessageRef = useRef<MessageItem[]>([]);
const modelScrollRef = useRef<any>(null);
const { initialize } = useOverlayScroller();
const setMessageId = () => {
messageId.current = messageId.current + 1;
@@ -122,8 +126,6 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
setMessageList((preList) => {
return [...preList, ...currentMessageRef.current];
});
console.log('currentMessageRef.current 1:', currentMessageRef.current);
console.log('currentMessage==========4', messageList);
const messages = _.map(
[...messageList, ...currentMessageRef.current],
(item: MessageItem) => {
@@ -194,9 +196,6 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
});
setLoadingStatus(instanceId, false);
} catch (error) {
setMessageList((preList) => {
return [...preList, ...currentMessageRef.current];
});
setLoadingStatus(instanceId, false);
}
};
@@ -333,6 +332,12 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
};
}, []);
useEffect(() => {
if (modelScrollRef.current) {
initialize(modelScrollRef.current);
}
}, [modelScrollRef.current, initialize]);
useImperativeHandle(ref, () => {
return {
submit: handleSubmit,
@@ -410,8 +415,12 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
applyToAll={handleApplySystemChangeToAll}
setSystemMessage={setSystemMessage}
></SystemMessage>
<SimpleBar style={{ maxHeight: maxHeight }}>
<div className="content">
<div
className="content"
ref={modelScrollRef}
style={{ maxHeight: maxHeight }}
>
<div>
<MessageContent
spans={spans}
messageList={messageList}
@@ -424,7 +433,7 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
style={{ width: '100%' }}
/>
</div>
</SimpleBar>
</div>
<ViewCodeModal
open={show}
systemMessage={systemMessage}