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

Draft: feat: LLMMultiWheel tool #552

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/lb-components/src/data/enums/ToolType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export enum EToolName {
PointCloudPolygon = 'pointCloudPolygon',
LLM = 'LLMTool',
NLP = 'NLPTool',
LLMMultiWheel = "LLMMultiWheelTool"
}

// 文本标注类型
Expand Down
6 changes: 5 additions & 1 deletion packages/lb-components/src/store/annotation/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ const updateToolInstance = (annotation: AnnotationState, imgNode: HTMLImageEleme
return;
}

if ([EToolName.LLM as string, EToolName.NLP as string].includes(stepConfig?.tool)) {
if (
[EToolName.LLM as string, EToolName.NLP as string, EToolName.LLMMultiWheel].includes(
stepConfig?.tool,
)
) {
return;
}

Expand Down
15 changes: 15 additions & 0 deletions packages/lb-components/src/store/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ interface ILLMContext {
setModelAPIResponse: React.Dispatch<React.SetStateAction<IModelAPIAnswer[]>>;
setNewAnswerList: (value: IAnswerList[]) => void;
}

interface ILLMMultiMheelContext {
hoverKey: number;
setHoverKey: (value: number) => void;
selectKey: number;
setSelectKey: (value: number) => void;
}

interface INLPContext {
highlightKey: string;
setHighlightKey: (value: string) => void;
Expand All @@ -30,3 +38,10 @@ export const NLPContext = React.createContext<INLPContext>({
highlightKey: '',
setHighlightKey: () => {},
});

export const LLMMultiMheelContext = React.createContext<ILLMMultiMheelContext>({
hoverKey: -1,
setHoverKey: () => {},
selectKey: 1,
setSelectKey: () => {},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { AppProps } from '@/App';
import { prefix } from '@/constant';
import { Layout } from 'antd/es';
import _ from 'lodash';
import React, { useState, useMemo } from 'react';
import Sidebar from '../sidebar';
import ToolFooter from '../toolFooter';
import { getClassName } from '@/utils/dom';
import { classnames } from '@/utils';
import { LLMMultiMheelContext } from '@/store/ctx';
import LLMToolView from '@/components/LLMToolView';
import { IModelAPIAnswer, IAnswerList } from '@/components/LLMToolView/types';

interface IProps {
path: string;
loading: boolean;
}

const { Sider, Content } = Layout;
const layoutCls = `${prefix}-layout`;

const LLMMultiMheelLayout: React.FC<AppProps & IProps> = (props) => {
const [hoverKey, setHoverKey] = useState(-1);
const [modelAPIResponse, setModelAPIResponse] = useState<IModelAPIAnswer[]>([]);
const [newAnswerList, setNewAnswerList] = useState<IAnswerList[]>([]);

return (
<Layout className={getClassName('layout', 'container')}>
<LLMMultiMheelContext.Provider
value={useMemo(() => {
return {
hoverKey,
setHoverKey,
selectKey,
setSelectKey,
};
}, [hoverKey, modelAPIResponse, newAnswerList])}
>
{props?.leftSider}
<Content
className={classnames({
[`${layoutCls}__content`]: true,
[`${prefix}-LLMLayout`]: true,
})}
>
{/* <LLMToolView
checkMode={props.checkMode}
showTips={props.showTips}
tips={props.tips}
drawLayerSlot={props.drawLayerSlot}
/> */}
<div>多轮的内容</div>
<ToolFooter style={props.style?.footer} mode={props.mode} footer={props?.footer} />
</Content>
<Sider className={`${layoutCls}__side`} width={600} style={{ position: 'relative' }}>
<Sidebar sider={props?.sider} checkMode={props?.checkMode} />
{props.drawLayerSlot?.({})}
</Sider>
</LLMMultiMheelContext.Provider>
</Layout>
);
};

export default LLMMultiMheelLayout;
17 changes: 15 additions & 2 deletions packages/lb-components/src/views/MainView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import AudioAnnotate from '@/components/audioAnnotate';
import { LoadingOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { EPointCloudName } from '@labelbee/lb-annotation';
import LLMMultiMheelLayout from './LLMMultiMheelLayout';

interface IProps {
path: string;
Expand Down Expand Up @@ -90,8 +91,12 @@ const ViewportProviderLayout = (props: AppProps & IProps & { children: any }) =>
const { t } = useTranslation();
const { stepList, step } = props;
const currentToolName = getStepConfig(stepList, step)?.tool;
const hasLangNode = ![EToolName.LLM, EToolName.NLP].includes(currentToolName);
const hasHeaderOption = ![EToolName.LLM, EToolName.NLP].includes(currentToolName);
const hasLangNode = ![EToolName.LLM, EToolName.NLP, EToolName.LLMMultiWheel].includes(
currentToolName,
);
const hasHeaderOption = ![EToolName.LLM, EToolName.NLP, EToolName.LLMMultiWheel].includes(
currentToolName,
);
const hasPredictTrackingIcon = [EPointCloudName.PointCloud].includes(currentToolName);
return (
<ViewportProvider>
Expand Down Expand Up @@ -127,8 +132,16 @@ const MainView: React.FC<AppProps & IProps> = (props) => {
const currentToolName = getStepConfig(stepList, step)?.tool;
const isLLMTool = EToolName.LLM === currentToolName;
const isNLPTool = EToolName.NLP === currentToolName;
const isLLMMultiWheelTool = EToolName.LLMMultiWheel === currentToolName;
const isAudioTool = ToolUtils.isAudioTool(currentToolName);

if (isLLMMultiWheelTool) {
return (
<ViewportProviderLayout {...props}>
<LLMMultiMheelLayout {...props} />
</ViewportProviderLayout>
);
}
if (isLLMTool) {
return (
<ViewportProviderLayout {...props}>
Expand Down
12 changes: 11 additions & 1 deletion packages/lb-demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import car1 from './mock/cuboidImages/1.png';
import { EToolName } from '@labelbee/lb-annotation';
import { LLMToolQa, LLMToolResult } from './mock/LLMTool';
import { textData, NLPToolResult } from './mock/NLPTool';
import { LLMMultiWheelToolQa, LLMMultiWheelToolResult } from './mock/LLMMultiWheelTool';

const App = () => {
const tool = qs.parse(window.location.search, {
Expand Down Expand Up @@ -73,9 +74,18 @@ const App = () => {
},
}));
}
if (EToolName.LLMMultiWheelTool === tool) {
return srcList.map((url, i) => ({
...extraData,
id: i + 1,
url,
result: JSON.stringify(LLMMultiWheelToolResult.step_1.result),
modelList: LLMMultiWheelToolQa,
}));
}

if (EToolName.NLP === tool) {
return srcList.map((url, i) => ({
return srcList.map((url, i) => ({
...extraData,
id: i + 1,
url,
Expand Down
93 changes: 93 additions & 0 deletions packages/lb-demo/src/mock/LLMMultiWheelTool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
export const LLMMultiWheelToolResult = {
step_1: {
dataSourceStep: 0,
result:
{
sort: [
[1], [2]
],
answerSort: {
A1: [
[2], [1]
],

A2: [
[1], [2]
]
},
textAttribute: [{
isLaText: true,
max: 22,
min: 1,
textId: "Ok",
tip: "提示语",
title: "标题",
value: " $$\\frac{a}{b}$$ "
}],
modelData: [
{
id: 1,
sort: [],
answerList: [
{
id: 'A1',
answer: '金百味1',
},
{
id: 'A2',
answer: '全刀手1',
},
],
},
{
id: 2,
sort: [],
answerList: [
{
id: 'A1',
answer: '金百味',
},
{
id: 'A2',
answer: '全刀手',
},
],
},
],
},
toolName: 'LLMMultiWheelTool',
},
};

export const LLMMultiWheelToolQa = [
{
id: 1,
question: '今天晚上吃什么?',
name: 'Orl_answer',
answerList: [
{
id: 'A1',
answer: '金百味1',
},
{
id: 'A2',
answer: '全刀手1',
},
],
},
{
id: 2,
question: '明天中午吃什么?',
name: 'GPT_answer',
answerList: [
{
id: 'A1',
answer: '金百味',
},
{
id: 'A2',
answer: '全刀手',
},
],
},
];
5 changes: 5 additions & 0 deletions packages/lb-demo/src/mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import img3 from './images/20.jpg';
import img4 from './images/66.jpg';
import { pointCloudResult1 } from './pointCloud';
import { LLMToolResult } from './LLMTool';
import { LLMMultiWheelToolResult } from './LLMMultiWheelTool';
import { NLPToolResult } from './NLPTool';

// audios
Expand Down Expand Up @@ -134,6 +135,10 @@ export const getMockResult = (tool) => {
return LLMToolResult;
}

if (tool === 'LLMMultiWheelTool') {
return LLMMultiWheelToolResult;
}

if (tool === 'NLPTool') {
return NLPToolResult;
}
Expand Down
50 changes: 50 additions & 0 deletions packages/lb-demo/src/mock/taskConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,52 @@ const LLMToolConfig = {
],
};

const LLMMultiWheelToolConfig = {
enableSort: true, // 开启答案排序
enableTextAttribute: true, // 文本标注
score: 7, // 答案评分
indicatorScore: [
{ label: '可读性', value: 'readability', text: '阅读起来是否顺畅', score: 10 },
{ label: '不可读性', value: 'unReadability', text: '偶是基督教精神', score: 10 },
], // 指标评分
indicatorDetermine: [
{ label: '包含敏感信息', value: 'sensitiveInfo' },
{ label: '包含敏感信息2', value: 'sensitiveInfo2' },
], // 指标判断
dataType: {
prompt: 'picture',
response: 'text',
},
isTextEdit: true, // 是否打开文本编辑
textEdit: [
{
title: 1,
min: 11,
max: 1000,
isFillAnswer: true, // 是否填充答案
isLaText: true, // 是否打开LaTex编辑
textControl: true, // 文本对照
},
{
title: 2,
min: 10,
isFillAnswer: false, // 是否填充答案
textControl: true, // 文本对照
},
{
title: 3,
max: 100,
isFillAnswer: true, // 是否填充答案
textControl: false, // 文本对照
},
{
title: 4,
isFillAnswer: false, // 是否填充答案
textControl: false, // 文本对照
},
],
};

const NLPToolConfig = {
indicatorDetermine: [
{
Expand Down Expand Up @@ -482,6 +528,10 @@ export const getConfig = (tool) => {
return LLMToolConfig;
}

if (tool === EToolName.LLMMultiWheel) {
return LLMMultiWheelToolConfig;
}

if (tool === EToolName.NLP) {
return NLPToolConfig;
}
Expand Down
Loading