mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-04 03:25:30 +08:00
### What problem does this PR solve? Feat: The bottom anchor of the agent node is only displayed when there is a downstream node #9869 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { useFetchPrompt } from '@/hooks/use-agent-request';
|
|
import { Edge } from '@xyflow/react';
|
|
import { useMemo } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { hasSubAgentOrTool } from '../../utils';
|
|
|
|
export const PromptIdentity = 'RAGFlow-Prompt';
|
|
|
|
function wrapPromptWithTag(text: string, tag: string) {
|
|
const capitalTag = tag.toUpperCase();
|
|
return `<${capitalTag}>
|
|
${text}
|
|
</${capitalTag}>`;
|
|
}
|
|
|
|
export function useBuildPromptExtraPromptOptions(
|
|
edges: Edge[],
|
|
nodeId?: string,
|
|
) {
|
|
const { data: prompts } = useFetchPrompt();
|
|
const { t } = useTranslation();
|
|
const has = hasSubAgentOrTool(edges, nodeId);
|
|
|
|
const options = useMemo(() => {
|
|
return Object.entries(prompts || {})
|
|
.map(([key, value]) => ({
|
|
label: key,
|
|
value: wrapPromptWithTag(value, key),
|
|
icon: null,
|
|
}))
|
|
.filter((x) => {
|
|
if (!has) {
|
|
return x.label === 'citation_guidelines';
|
|
}
|
|
return true;
|
|
});
|
|
}, [has, prompts]);
|
|
|
|
const extraOptions = [
|
|
{ label: PromptIdentity, title: t('flow.frameworkPrompts'), options },
|
|
];
|
|
|
|
return { extraOptions };
|
|
}
|