mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
Feat: Structured data will still be stored in outputs for compatibility with older versions. #10427 (#11368)
### What problem does this PR solve? Feat: Structured data will still be stored in outputs for compatibility with older versions. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -5,7 +5,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
AgentGlobals,
|
AgentGlobals,
|
||||||
AgentGlobalsSysQueryWithBrace,
|
AgentGlobalsSysQueryWithBrace,
|
||||||
AgentStructuredOutputField,
|
|
||||||
CodeTemplateStrMap,
|
CodeTemplateStrMap,
|
||||||
ComparisonOperator,
|
ComparisonOperator,
|
||||||
JsonSchemaDataType,
|
JsonSchemaDataType,
|
||||||
@ -465,7 +464,6 @@ export const initialAgentValues = {
|
|||||||
mcp: [],
|
mcp: [],
|
||||||
cite: true,
|
cite: true,
|
||||||
showStructuredOutput: false,
|
showStructuredOutput: false,
|
||||||
[AgentStructuredOutputField]: {},
|
|
||||||
outputs: {
|
outputs: {
|
||||||
content: {
|
content: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
AgentExceptionMethod,
|
AgentExceptionMethod,
|
||||||
AgentStructuredOutputField,
|
|
||||||
NodeHandleId,
|
NodeHandleId,
|
||||||
VariableType,
|
VariableType,
|
||||||
} from '../../constant';
|
} from '../../constant';
|
||||||
@ -74,7 +73,6 @@ const FormSchema = z.object({
|
|||||||
...LargeModelFilterFormSchema,
|
...LargeModelFilterFormSchema,
|
||||||
cite: z.boolean().optional(),
|
cite: z.boolean().optional(),
|
||||||
showStructuredOutput: z.boolean().optional(),
|
showStructuredOutput: z.boolean().optional(),
|
||||||
[AgentStructuredOutputField]: z.record(z.any()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type AgentFormSchemaType = z.infer<typeof FormSchema>;
|
export type AgentFormSchemaType = z.infer<typeof FormSchema>;
|
||||||
@ -127,7 +125,7 @@ function AgentForm({ node }: INextOperatorForm) {
|
|||||||
structuredOutputDialogVisible,
|
structuredOutputDialogVisible,
|
||||||
hideStructuredOutputDialog,
|
hideStructuredOutputDialog,
|
||||||
handleStructuredOutputDialogOk,
|
handleStructuredOutputDialogOk,
|
||||||
} = useShowStructuredOutputDialog(form);
|
} = useShowStructuredOutputDialog(node?.id);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (exceptionMethod !== AgentExceptionMethod.Goto) {
|
if (exceptionMethod !== AgentExceptionMethod.Goto) {
|
||||||
@ -284,9 +282,7 @@ function AgentForm({ node }: INextOperatorForm) {
|
|||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
<RAGFlowFormItem name={AgentStructuredOutputField} className="hidden">
|
|
||||||
<Input></Input>
|
|
||||||
</RAGFlowFormItem>
|
|
||||||
<Output list={outputList}>
|
<Output list={outputList}>
|
||||||
<RAGFlowFormItem name="showStructuredOutput">
|
<RAGFlowFormItem name="showStructuredOutput">
|
||||||
{(field) => (
|
{(field) => (
|
||||||
|
|||||||
@ -1,25 +1,27 @@
|
|||||||
import { JSONSchema } from '@/components/jsonjoy-builder';
|
import { JSONSchema } from '@/components/jsonjoy-builder';
|
||||||
import { AgentStructuredOutputField } from '@/constants/agent';
|
|
||||||
import { useSetModalState } from '@/hooks/common-hooks';
|
import { useSetModalState } from '@/hooks/common-hooks';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { UseFormReturn } from 'react-hook-form';
|
import useGraphStore from '../../store';
|
||||||
|
|
||||||
export function useShowStructuredOutputDialog(form: UseFormReturn<any>) {
|
export function useShowStructuredOutputDialog(nodeId?: string) {
|
||||||
const {
|
const {
|
||||||
visible: structuredOutputDialogVisible,
|
visible: structuredOutputDialogVisible,
|
||||||
showModal: showStructuredOutputDialog,
|
showModal: showStructuredOutputDialog,
|
||||||
hideModal: hideStructuredOutputDialog,
|
hideModal: hideStructuredOutputDialog,
|
||||||
} = useSetModalState();
|
} = useSetModalState();
|
||||||
|
const { updateNodeForm, getNode } = useGraphStore((state) => state);
|
||||||
|
|
||||||
const initialStructuredOutput = form.getValues(AgentStructuredOutputField);
|
const initialStructuredOutput = getNode(nodeId)?.data.form.outputs.structured;
|
||||||
|
|
||||||
const handleStructuredOutputDialogOk = useCallback(
|
const handleStructuredOutputDialogOk = useCallback(
|
||||||
(values: JSONSchema) => {
|
(values: JSONSchema) => {
|
||||||
// Sync data to canvas
|
// Sync data to canvas
|
||||||
form.setValue(AgentStructuredOutputField, values);
|
if (nodeId) {
|
||||||
|
updateNodeForm(nodeId, values, ['outputs', 'structured']);
|
||||||
|
}
|
||||||
hideStructuredOutputDialog();
|
hideStructuredOutputDialog();
|
||||||
},
|
},
|
||||||
[form, hideStructuredOutputDialog],
|
[hideStructuredOutputDialog, nodeId, updateNodeForm],
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -22,7 +22,8 @@ export function useWatchFormChange(id?: string, form?: UseFormReturn<any>) {
|
|||||||
...nextValues,
|
...nextValues,
|
||||||
outputs: {
|
outputs: {
|
||||||
...values.outputs,
|
...values.outputs,
|
||||||
[AgentStructuredOutputField]: values[AgentStructuredOutputField],
|
[AgentStructuredOutputField]:
|
||||||
|
values[AgentStructuredOutputField] ?? {},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user