mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-19 11:45:10 +08:00
### What problem does this PR solve? Feat: Exported Agent JSON Should Include Conversation Variables Configuration #11796 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -97,6 +97,7 @@ export const EmptyDsl = {
|
|||||||
retrieval: [], // reference
|
retrieval: [], // reference
|
||||||
history: [],
|
history: [],
|
||||||
path: [],
|
path: [],
|
||||||
|
variables: [],
|
||||||
globals: {
|
globals: {
|
||||||
[AgentGlobals.SysQuery]: '',
|
[AgentGlobals.SysQuery]: '',
|
||||||
[AgentGlobals.SysUserId]: '',
|
[AgentGlobals.SysUserId]: '',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { useFetchAgent } from '@/hooks/use-agent-request';
|
import { useFetchAgent } from '@/hooks/use-agent-request';
|
||||||
import { downloadJsonFile } from '@/utils/file-util';
|
import { downloadJsonFile } from '@/utils/file-util';
|
||||||
|
import { pick } from 'lodash';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useBuildDslData } from './use-build-dsl';
|
import { useBuildDslData } from './use-build-dsl';
|
||||||
|
|
||||||
@ -8,7 +9,8 @@ export const useHandleExportJsonFile = () => {
|
|||||||
const { data } = useFetchAgent();
|
const { data } = useFetchAgent();
|
||||||
|
|
||||||
const handleExportJson = useCallback(() => {
|
const handleExportJson = useCallback(() => {
|
||||||
downloadJsonFile(buildDslData().graph, `${data.title}.json`);
|
const dsl = pick(buildDslData(), ['graph', 'globals', 'variables']);
|
||||||
|
downloadJsonFile(dsl, `${data.title}.json`);
|
||||||
}, [buildDslData, data.title]);
|
}, [buildDslData, data.title]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -71,6 +71,7 @@ export const DataflowEmptyDsl = {
|
|||||||
history: [],
|
history: [],
|
||||||
path: [],
|
path: [],
|
||||||
globals: {},
|
globals: {},
|
||||||
|
variables: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useCreateAgentOrPipeline() {
|
export function useCreateAgentOrPipeline() {
|
||||||
|
|||||||
@ -34,25 +34,36 @@ export const useHandleImportJsonFile = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const graphStr = await file.text();
|
const graphOrDslStr = await file.text();
|
||||||
const errorMessage = t('flow.jsonUploadContentErrorMessage');
|
const errorMessage = t('flow.jsonUploadContentErrorMessage');
|
||||||
try {
|
try {
|
||||||
const graph = JSON.parse(graphStr);
|
const graphOrDsl = JSON.parse(graphOrDslStr);
|
||||||
if (graphStr && !isEmpty(graph) && Array.isArray(graph?.nodes)) {
|
if (graphOrDslStr && !isEmpty(graphOrDsl)) {
|
||||||
const nodes: Node[] = graph.nodes;
|
|
||||||
|
|
||||||
let isAgent = true;
|
let isAgent = true;
|
||||||
|
// Compatible with older versions
|
||||||
|
const graph = graphOrDsl?.graph ? graphOrDsl.graph : graphOrDsl;
|
||||||
|
if (Array.isArray(graph?.nodes)) {
|
||||||
|
const nodes: Node[] = graph.nodes;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
hasNode(nodes, DataflowOperator.Begin) &&
|
hasNode(nodes, DataflowOperator.Begin) &&
|
||||||
hasNode(nodes, DataflowOperator.Parser)
|
hasNode(nodes, DataflowOperator.Parser)
|
||||||
) {
|
) {
|
||||||
isAgent = false;
|
isAgent = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dsl = isAgent
|
const dsl = isAgent
|
||||||
? { ...EmptyDsl, graph }
|
? { ...EmptyDsl, graph: graph }
|
||||||
: { ...DataflowEmptyDsl, graph };
|
: { ...DataflowEmptyDsl, graph: graph };
|
||||||
|
|
||||||
|
if (graphOrDsl.globals) {
|
||||||
|
dsl.globals = graphOrDsl.globals;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graphOrDsl.variables) {
|
||||||
|
dsl.variables = graphOrDsl.variables;
|
||||||
|
}
|
||||||
|
|
||||||
setAgent({
|
setAgent({
|
||||||
title: name,
|
title: name,
|
||||||
@ -66,6 +77,7 @@ export const useHandleImportJsonFile = () => {
|
|||||||
message.error(errorMessage);
|
message.error(errorMessage);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log('🚀 ~ useHandleImportJsonFile ~ error:', error);
|
||||||
message.error(errorMessage);
|
message.error(errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user