-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07a3928
commit bb960eb
Showing
6 changed files
with
278 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...ges/lb-components/src/components/LLMToolView/sidebar/components/modelAnswerSort/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React, { useState, useEffect, useContext, useMemo } from 'react'; | ||
import { prefix } from '@/constant'; | ||
import { Button, Empty, Tag } from 'antd'; | ||
import AnswerSort from '../answerSort'; | ||
import { IWaitAnswerSort } from '@/components/LLMToolView/types'; | ||
import { getWaitSortList } from '@/components/LLMToolView/utils/data'; | ||
import { isArray } from 'lodash'; | ||
import ModelSort from '../modelSort'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
interface IAnswerSort { | ||
[key: string]: number[][]; | ||
} | ||
|
||
interface IModelList { | ||
id: number; | ||
answerList: IAnswerList[]; | ||
} | ||
|
||
interface IAnswerList { | ||
id: string; | ||
answer: string; | ||
} | ||
|
||
interface IProps { | ||
selectedSort?: IAnswerSort; | ||
maxAnswerList: IAnswerList[]; | ||
modelData: IModelList[]; | ||
} | ||
|
||
const ModelAnswerSort = (props: IProps) => { | ||
const { selectedSort, maxAnswerList, modelData } = props; | ||
const [answerSortData, setAnswerSortData] = useState({ waitSorts: [], selecteds: selectedSort }); | ||
const { t } = useTranslation(); | ||
|
||
const modelDatas = useMemo( | ||
() => | ||
modelData.map((i, itemIndex) => ({ | ||
...i, | ||
title: itemIndex + 1, | ||
})), | ||
[modelData], | ||
); | ||
|
||
const getModelList = (id: string) => { | ||
const values = modelDatas.filter((i) => i.answerList.some((item) => item.id === id)) || []; | ||
return values.map((i) => ({ id: i.id, title: i.title })); | ||
}; | ||
|
||
const exportSort = (id: string, value: number[][]) => { | ||
// TODO 当拖动一个答案的时,多次调用 | ||
// 因为answerSort组件useEffect(() => {formatSortList();}, [JSON.stringify(sortList)]) | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div | ||
style={{ | ||
fontWeight: 500, | ||
fontSize: '16px', | ||
width: '100%', | ||
lineHeight: '46px', | ||
padding: '0px 16px', | ||
}} | ||
> | ||
<span>{t('RankingQualityOfAnswers')}</span> | ||
{answerSortData?.waitSorts?.length > 0 && ( | ||
<Tag color='#FFD9D9' style={{ color: '#F26549', marginLeft: 8 }}> | ||
{t('Unfinished')} | ||
</Tag> | ||
)} | ||
</div> | ||
{maxAnswerList.map((i: IAnswerList, index: number) => { | ||
return ( | ||
<div key={index} style={{ display: 'flex' }}> | ||
<div | ||
style={{ | ||
fontSize: '16px', | ||
fontWeight: 500, | ||
width: '80px', | ||
lineHeight: '50px', | ||
textAlign: 'center', | ||
}} | ||
>{`${t('Answer')}${index + 1}`}</div> | ||
<ModelSort | ||
setSort={(value) => { | ||
exportSort(i.id, value); | ||
}} | ||
modelList={getModelList(i.id)} | ||
selectedSort={answerSortData.selecteds?.[i.id] ?? []} | ||
header={''} | ||
prefixId={`modelAnswer${index}`} | ||
/> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
export default ModelAnswerSort; |
75 changes: 75 additions & 0 deletions
75
packages/lb-components/src/components/LLMToolView/sidebar/components/modelSort/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { useState, useEffect, useContext, useMemo } from 'react'; | ||
import { prefix } from '@/constant'; | ||
import { Button, Empty } from 'antd'; | ||
import AnswerSort from '../answerSort'; | ||
import { IAnswerSort, IWaitAnswerSort } from '@/components/LLMToolView/types'; | ||
import { getWaitSortList } from '@/components/LLMToolView/utils/data'; | ||
import { isArray } from 'lodash'; | ||
|
||
interface IModelList { | ||
id: number; | ||
title: number; | ||
} | ||
|
||
interface ISortData { | ||
newSort?: IAnswerSort[][]; | ||
waitSorts?: IWaitAnswerSort[]; | ||
} | ||
|
||
interface IProps { | ||
modelList: IModelList[]; | ||
selectedSort?: number[][]; | ||
disabeledAll?: boolean; | ||
setSort: (sort: number[][]) => void; | ||
header?: HTMLElement | string; | ||
title?: string; | ||
prefixId?: string; | ||
} | ||
|
||
const ModelSort = (props: IProps) => { | ||
const { disabeledAll, modelList, selectedSort, setSort, header, title,prefixId } = props; | ||
const [sortData, setSortData] = useState<ISortData>({}); | ||
|
||
useEffect(() => { | ||
initSortData(); | ||
}, []); | ||
|
||
const initSortData = () => { | ||
let newSort: any[] = []; | ||
const waitSorts = modelList.filter((i) => { | ||
const selectedIds = selectedSort && selectedSort?.length > 0 ? selectedSort.flat() : []; | ||
if (selectedIds.includes(i.id)) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
if (selectedSort && selectedSort?.length > 0) { | ||
newSort = selectedSort.map((i: number[]) => | ||
i.map((item) => modelList.find((j) => j.id === item)), | ||
); | ||
} | ||
setSortData({ waitSorts, newSort }); | ||
}; | ||
|
||
const exportSort = (list: IAnswerSort[][]) => { | ||
const sort = list.map((i) => i.map((item) => item.id)); | ||
setSort(sort); | ||
}; | ||
|
||
return ( | ||
<AnswerSort | ||
waitSortList={sortData?.waitSorts || []} | ||
sortList={sortData?.newSort || []} | ||
setSortList={(value) => { | ||
setSortData({ ...sortData, newSort: value }); | ||
exportSort(value); | ||
}} | ||
disabeledAll={disabeledAll} | ||
header={header} | ||
title={title} | ||
prefixId={prefixId} | ||
/> | ||
); | ||
}; | ||
|
||
export default ModelSort; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.