mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Edit the output data of the code operator #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { ProgrammingLanguage } from '@/constants/agent';
|
||||
import { ICodeForm } from '@/interfaces/database/agent';
|
||||
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useMemo } from 'react';
|
||||
@ -6,10 +8,26 @@ import { initialCodeValues } from '../../constant';
|
||||
function convertToArray(args: Record<string, string>) {
|
||||
return Object.entries(args).map(([key, value]) => ({
|
||||
name: key,
|
||||
component_id: value,
|
||||
type: value,
|
||||
}));
|
||||
}
|
||||
|
||||
type OutputsFormType = { name: string; type: string };
|
||||
|
||||
function convertOutputsToArray({ lang, outputs = {} }: ICodeForm) {
|
||||
if (lang === ProgrammingLanguage.Python) {
|
||||
return Object.entries(outputs).map(([key, val]) => ({
|
||||
name: key,
|
||||
type: val.type,
|
||||
}));
|
||||
}
|
||||
return Object.entries(outputs).reduce<OutputsFormType>((pre, [key, val]) => {
|
||||
pre.name = key;
|
||||
pre.type = val.type;
|
||||
return pre;
|
||||
}, {} as OutputsFormType);
|
||||
}
|
||||
|
||||
export function useValues(node?: RAGFlowNodeType) {
|
||||
const values = useMemo(() => {
|
||||
const formData = node?.data?.form;
|
||||
@ -18,7 +36,11 @@ export function useValues(node?: RAGFlowNodeType) {
|
||||
return initialCodeValues;
|
||||
}
|
||||
|
||||
return { ...formData, arguments: convertToArray(formData.arguments) };
|
||||
return {
|
||||
...formData,
|
||||
arguments: convertToArray(formData.arguments),
|
||||
outputs: convertOutputsToArray(formData),
|
||||
};
|
||||
}, [node?.data?.form]);
|
||||
|
||||
return values;
|
||||
|
||||
Reference in New Issue
Block a user