mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Display chat content on the agent page #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -52,11 +52,13 @@ export const useSelectNextMessages = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function findMessageFromList(eventList: IEventList) {
|
function findMessageFromList(eventList: IEventList) {
|
||||||
const event = eventList.find((x) => x.event === MessageEventType.Message) as
|
const messageEventList = eventList.filter(
|
||||||
| IMessageEvent
|
(x) => x.event === MessageEventType.Message,
|
||||||
| undefined;
|
) as IMessageEvent[];
|
||||||
|
return {
|
||||||
return event?.data?.content;
|
id: messageEventList[0]?.message_id,
|
||||||
|
content: messageEventList.map((x) => x.data.content).join(''),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const useGetBeginNodePrologue = () => {
|
const useGetBeginNodePrologue = () => {
|
||||||
@ -127,10 +129,11 @@ export const useSendNextMessage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const message = findMessageFromList(answerList);
|
const { content, id } = findMessageFromList(answerList);
|
||||||
if (message) {
|
if (content) {
|
||||||
addNewestAnswer({
|
addNewestAnswer({
|
||||||
answer: message,
|
answer: content,
|
||||||
|
id: id,
|
||||||
reference: {
|
reference: {
|
||||||
chunks: [],
|
chunks: [],
|
||||||
doc_aggs: [],
|
doc_aggs: [],
|
||||||
|
|||||||
@ -27,6 +27,10 @@ import { ReactComponent as TemplateIcon } from '@/assets/svg/template.svg';
|
|||||||
import { ReactComponent as TuShareIcon } from '@/assets/svg/tushare.svg';
|
import { ReactComponent as TuShareIcon } from '@/assets/svg/tushare.svg';
|
||||||
import { ReactComponent as WenCaiIcon } from '@/assets/svg/wencai.svg';
|
import { ReactComponent as WenCaiIcon } from '@/assets/svg/wencai.svg';
|
||||||
import { ReactComponent as YahooFinanceIcon } from '@/assets/svg/yahoo-finance.svg';
|
import { ReactComponent as YahooFinanceIcon } from '@/assets/svg/yahoo-finance.svg';
|
||||||
|
import {
|
||||||
|
initialKeywordsSimilarityWeightValue,
|
||||||
|
initialSimilarityThresholdValue,
|
||||||
|
} from '@/components/similarity-slider';
|
||||||
import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent';
|
import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent';
|
||||||
|
|
||||||
export enum AgentDialogueMode {
|
export enum AgentDialogueMode {
|
||||||
@ -437,10 +441,20 @@ const initialQueryBaseValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const initialRetrievalValues = {
|
export const initialRetrievalValues = {
|
||||||
similarity_threshold: 0.2,
|
query: '',
|
||||||
keywords_similarity_weight: 0.3,
|
top_n: 0.2,
|
||||||
top_n: 8,
|
top_k: 1024,
|
||||||
...initialQueryBaseValues,
|
kb_ids: [],
|
||||||
|
rerank_id: '',
|
||||||
|
empty_response: '',
|
||||||
|
...initialSimilarityThresholdValue,
|
||||||
|
...initialKeywordsSimilarityWeightValue,
|
||||||
|
outputs: {
|
||||||
|
formalized_content: {
|
||||||
|
type: 'string',
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialBeginValues = {
|
export const initialBeginValues = {
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
import { FormContainer } from '@/components/form-container';
|
import { FormContainer } from '@/components/form-container';
|
||||||
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
||||||
import { RerankFormFields } from '@/components/rerank';
|
import { RerankFormFields } from '@/components/rerank';
|
||||||
import {
|
import { SimilaritySliderFormField } from '@/components/similarity-slider';
|
||||||
initialKeywordsSimilarityWeightValue,
|
|
||||||
initialSimilarityThresholdValue,
|
|
||||||
SimilaritySliderFormField,
|
|
||||||
} from '@/components/similarity-slider';
|
|
||||||
import { TopNFormField } from '@/components/top-n-item';
|
import { TopNFormField } from '@/components/top-n-item';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@ -17,11 +13,16 @@ import {
|
|||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { useMemo } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { initialRetrievalValues } from '../../constant';
|
||||||
|
import { useWatchFormChange } from '../../hooks/use-watch-form-change';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
|
import { Output } from '../components/output';
|
||||||
import { QueryVariable } from '../components/query-variable';
|
import { QueryVariable } from '../components/query-variable';
|
||||||
|
import { useValues } from './use-values';
|
||||||
|
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
query: z.string().optional(),
|
query: z.string().optional(),
|
||||||
@ -34,25 +35,27 @@ const FormSchema = z.object({
|
|||||||
empty_response: z.string(),
|
empty_response: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const defaultValues = {
|
|
||||||
query: '',
|
|
||||||
top_n: 0.2,
|
|
||||||
top_k: 1024,
|
|
||||||
kb_ids: [],
|
|
||||||
rerank_id: '',
|
|
||||||
empty_response: '',
|
|
||||||
...initialSimilarityThresholdValue,
|
|
||||||
...initialKeywordsSimilarityWeightValue,
|
|
||||||
};
|
|
||||||
|
|
||||||
const RetrievalForm = ({ node }: INextOperatorForm) => {
|
const RetrievalForm = ({ node }: INextOperatorForm) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const outputList = useMemo(() => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
title: 'formalized_content',
|
||||||
|
type: initialRetrievalValues.outputs.formalized_content.type,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const defaultValues = useValues(node);
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
defaultValues: defaultValues,
|
defaultValues: defaultValues,
|
||||||
resolver: zodResolver(FormSchema),
|
resolver: zodResolver(FormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useWatchFormChange(node?.id, form);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
@ -92,6 +95,7 @@ const RetrievalForm = ({ node }: INextOperatorForm) => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
|
<Output list={outputList}></Output>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
|||||||
25
web/src/pages/agent/form/retrieval-form/use-values.ts
Normal file
25
web/src/pages/agent/form/retrieval-form/use-values.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { RAGFlowNodeType } from '@/interfaces/database/flow';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { initialRetrievalValues } from '../../constant';
|
||||||
|
|
||||||
|
export function useValues(node?: RAGFlowNodeType) {
|
||||||
|
const defaultValues = useMemo(
|
||||||
|
() => ({
|
||||||
|
...initialRetrievalValues,
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const values = useMemo(() => {
|
||||||
|
const formData = node?.data?.form;
|
||||||
|
|
||||||
|
if (isEmpty(formData)) {
|
||||||
|
return defaultValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
return formData;
|
||||||
|
}, [defaultValues, node?.data?.form]);
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
@ -141,11 +141,6 @@ export const useBuildComponentIdSelectOptions = (
|
|||||||
const options = useMemo(() => {
|
const options = useMemo(() => {
|
||||||
const query: BeginQuery[] = getBeginNodeDataQuery();
|
const query: BeginQuery[] = getBeginNodeDataQuery();
|
||||||
return [
|
return [
|
||||||
{
|
|
||||||
label: <span>Component Output</span>,
|
|
||||||
title: 'Component Output',
|
|
||||||
options: componentIdOptions,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: <span>Begin Input</span>,
|
label: <span>Begin Input</span>,
|
||||||
title: 'Begin Input',
|
title: 'Begin Input',
|
||||||
@ -156,7 +151,7 @@ export const useBuildComponentIdSelectOptions = (
|
|||||||
},
|
},
|
||||||
...nodeOutputOptions,
|
...nodeOutputOptions,
|
||||||
];
|
];
|
||||||
}, [componentIdOptions, getBeginNodeDataQuery, nodeOutputOptions]);
|
}, [getBeginNodeDataQuery, nodeOutputOptions]);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user