Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lb-components): Add LLMMultiWheel #567

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/lb-annotation/src/constant/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export enum EToolName {
LLM = 'LLMTool',
/** NLP标注工具-大模型 */
NLP = 'NLPTool',
LLMMultiWheel = 'LLMMultiWheelTool',
}

export enum ECheckModel {
Expand Down Expand Up @@ -110,6 +111,7 @@ export const TOOL_NAME: { [a: string]: string } = {
[EToolName.Cuboid]: '立体框',
[EToolName.LLM]: '大模型',
[EToolName.NLP]: 'NLP标注',
[EToolName.LLMMultiWheel]: '大模型(多轮对话)',
};

export const TOOL_NAME_EN: { [a: string]: string } = {
Expand All @@ -136,6 +138,7 @@ export const TOOL_NAME_EN: { [a: string]: string } = {
[EToolName.Cuboid]: 'Cuboid',
[EToolName.LLM]: 'LLM',
[EToolName.NLP]: 'NLP',
[EToolName.LLMMultiWheel]: 'LLMMultiWheelTool',
};

export enum EDependPattern {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { getTextControlByConfig, RenderAnswer } from '@/components/LLMToolView/questionView';
import { RenderQuestion } from '@/components/LLMToolView/questionView/components/header';
import ImgView from '@/components/LLMToolView/questionView/components/imgView';
import { ILLMMultiWheelToolConfig } from '@/components/LLMToolView/types';
import useLLMMultiWheelStore from '@/store/LLMMultiWheel';
import { classnames } from '@/utils';
import { LLMMultiWheelViewCls } from '@/views/MainView/LLMMultiWheelLayout';
import { Button } from 'antd';
import React, { useContext, useEffect, useState } from 'react';
// import { LLMMultiWheelViewCls } from '..';

interface IDialogViewProps {
id: number | string;
answerList: any;
question: any;
name?: string;
index: number;
isSelected: boolean;
answerIsImg: boolean;
questionIsImg: boolean;
LLMConfig?: ILLMMultiWheelToolConfig;
}

const DialogView = (props: IDialogViewProps) => {
const {
id,
answerList,
question,
index,
name = '',
answerIsImg,
questionIsImg,
LLMConfig,
} = props;
const { dataFormatType, selectedID, setSelectedID } = useLLMMultiWheelStore();
const order = index + 1;
const showName = name || `对话${order}`;

return (
<div
key={id}
onClick={() => setSelectedID(id)}
className={classnames({
dialog: true,
selected: id === selectedID,
})}
>
<div className={`header`}>
<span className={`order`}>{order}</span>
<div className={`name`}>
<div className={`show-name`}>{showName}</div>
<div className={`tips`}>(选中标注)</div>
</div>
</div>
<div className={`dialog-question`}>
<Button type='primary'>题目{order}</Button>
<div>
<RenderQuestion
question={question}
dataFormatType={dataFormatType}
isImg={questionIsImg}
/>
</div>
</div>
<div className={`dialog-answer`}>
{answerList.map((item: any, index: number) => {
const isTextControl = getTextControlByConfig(item, LLMConfig);
return (
<div key={index}>
<Button type='primary'>答案{index + 1}</Button>
{answerIsImg ? (
<ImgView answerList={answerList} />
) : (
<RenderAnswer
i={item}
isTextControl={isTextControl}
dataFormatType={dataFormatType}
/>
)}
</div>
);
})}
</div>
</div>
);
};

export default DialogView;
74 changes: 74 additions & 0 deletions packages/lb-components/src/components/LLMMultiWheelView/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useContext, useEffect, useState } from 'react';

import { connect } from 'react-redux';
import { AppState } from '@/store';
import { getStepConfig } from '@/store/annotation/reducer';
import { getCurrentResultFromResultList } from '../LLMToolView/utils/data';
import { jsonParser } from '@/utils';
import { ILLMMultiWheelToolConfig } from '../LLMToolView/types';
import { ELLMDataType, prefix } from '@/constant';
import { Layout } from 'antd/es';
import { LabelBeeContext } from '@/store/ctx';
import QuestionView from '../LLMToolView/questionView';
import DialogView from './dialogView';
import { LLMMultiWheelViewCls } from '@/views/MainView/LLMMultiWheelLayout';
import useLLMMultiWheelStore from '@/store/LLMMultiWheel';

interface IProps {
annotation?: any;
}

const LLMMultiWheelView: React.FC<IProps> = (props) => {
const { annotation } = props;
const { imgIndex, imgList, stepList, step, toolInstance } = annotation;
const [LLMConfig, setLLMConfig] = useState<ILLMMultiWheelToolConfig>();
const { setSelectedID } = useLLMMultiWheelStore();
const [dialogList, setDialogList] = useState([]);
const questionIsImg = LLMConfig?.dataType?.prompt === ELLMDataType.Picture;
const answerIsImg = LLMConfig?.dataType?.response === ELLMDataType.Picture;
useEffect(() => {
if (!imgList[imgIndex]) {
return;
}
const currentData = imgList[imgIndex] ?? {};
const dialogList = currentData?.questionList?.textList ?? [];

setDialogList(dialogList);
if (dialogList?.length) {
setSelectedID(dialogList[0].id);
}
}, [imgIndex]);

useEffect(() => {
if (stepList && step) {
const LLMStepConfig = getStepConfig(stepList, step)?.config;
setLLMConfig(jsonParser(LLMStepConfig));
}
}, [stepList, step]);

return (
<div className={`${LLMMultiWheelViewCls}-container`}>
{dialogList?.map((item: any, index) => (
<DialogView
{...item}
key={index}
index={index}
isSelected={true}
questionIsImg={questionIsImg}
answerIsImg={answerIsImg}
LLMConfig={LLMConfig}
/>
))}
</div>
);
};

const mapStateToProps = (state: AppState) => {
return {
annotation: state.annotation,
};
};

export default connect(mapStateToProps, null, null, { context: LabelBeeContext })(
LLMMultiWheelView,
);
Loading
Loading