### What problem does this PR solve? fix: fixed the issue where parameters of DuckDuckGo could not be saved to the backend after being dragged to the canvas #918 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)tags/v0.9.0
| import { variableEnabledFieldMap } from '@/constants/chat'; | import { variableEnabledFieldMap } from '@/constants/chat'; | ||||
| import i18n from '@/locales/config'; | import i18n from '@/locales/config'; | ||||
| // DuckDuckGo's channel options | |||||
| export enum Channel { | |||||
| Text = 'text', | |||||
| News = 'news', | |||||
| } | |||||
| import { | import { | ||||
| BranchesOutlined, | BranchesOutlined, | ||||
| DatabaseOutlined, | DatabaseOutlined, | ||||
| ...initialLlmBaseValues, | ...initialLlmBaseValues, | ||||
| top_n: 1, | top_n: 1, | ||||
| }; | }; | ||||
| export const initialDuckValues = { | |||||
| top_n: 10, | |||||
| channel: Channel.Text, | |||||
| }; | |||||
| export const initialFormValuesMap = { | |||||
| [Operator.Begin]: initialBeginValues, | |||||
| [Operator.Retrieval]: initialRetrievalValues, | |||||
| [Operator.Generate]: initialGenerateValues, | |||||
| [Operator.Answer]: {}, | |||||
| [Operator.Categorize]: initialCategorizeValues, | |||||
| [Operator.Relevant]: initialRelevantValues, | |||||
| [Operator.RewriteQuestion]: initialRewriteQuestionValues, | |||||
| [Operator.Message]: initialMessageValues, | |||||
| [Operator.KeywordExtract]: initialKeywordExtractValues, | |||||
| export const initialBaiduValues = { | |||||
| top_n: 10, | |||||
| }; | }; | ||||
| export const CategorizeAnchorPointPositions = [ | export const CategorizeAnchorPointPositions = [ |
| import TopNItem from '@/components/top-n-item'; | import TopNItem from '@/components/top-n-item'; | ||||
| import { useTranslate } from '@/hooks/commonHooks'; | import { useTranslate } from '@/hooks/commonHooks'; | ||||
| import { Form, Select } from 'antd'; | import { Form, Select } from 'antd'; | ||||
| import { useMemo } from 'react'; | |||||
| import { Channel } from '../constant'; | |||||
| import { IOperatorForm } from '../interface'; | import { IOperatorForm } from '../interface'; | ||||
| const DuckDuckGoForm = ({ onValuesChange, form }: IOperatorForm) => { | const DuckDuckGoForm = ({ onValuesChange, form }: IOperatorForm) => { | ||||
| const { t } = useTranslate('flow'); | const { t } = useTranslate('flow'); | ||||
| const options = useMemo(() => { | |||||
| return Object.values(Channel).map((x) => ({ value: x, label: t(x) })); | |||||
| }, [t]); | |||||
| return ( | return ( | ||||
| <Form | <Form | ||||
| name="basic" | name="basic" | ||||
| tooltip={t('channelTip')} | tooltip={t('channelTip')} | ||||
| initialValue={'text'} | initialValue={'text'} | ||||
| > | > | ||||
| <Select | |||||
| options={[ | |||||
| { value: 'text', label: t('text') }, | |||||
| { value: 'news', label: t('news') }, | |||||
| ]} | |||||
| ></Select> | |||||
| <Select options={options}></Select> | |||||
| </Form.Item> | </Form.Item> | ||||
| </Form> | </Form> | ||||
| ); | ); |
| KeyboardEventHandler, | KeyboardEventHandler, | ||||
| useCallback, | useCallback, | ||||
| useEffect, | useEffect, | ||||
| useMemo, | |||||
| useState, | useState, | ||||
| } from 'react'; | } from 'react'; | ||||
| import { Connection, Edge, Node, Position, ReactFlowInstance } from 'reactflow'; | import { Connection, Edge, Node, Position, ReactFlowInstance } from 'reactflow'; | ||||
| NodeMap, | NodeMap, | ||||
| Operator, | Operator, | ||||
| RestrictedUpstreamMap, | RestrictedUpstreamMap, | ||||
| initialBaiduValues, | |||||
| initialBeginValues, | initialBeginValues, | ||||
| initialCategorizeValues, | initialCategorizeValues, | ||||
| initialDuckValues, | |||||
| initialGenerateValues, | initialGenerateValues, | ||||
| initialKeywordExtractValues, | |||||
| initialMessageValues, | initialMessageValues, | ||||
| initialRelevantValues, | initialRelevantValues, | ||||
| initialRetrievalValues, | initialRetrievalValues, | ||||
| export const useInitializeOperatorParams = () => { | export const useInitializeOperatorParams = () => { | ||||
| const llmId = useFetchModelId(true); | const llmId = useFetchModelId(true); | ||||
| const initialFormValuesMap = useMemo(() => { | |||||
| return { | |||||
| [Operator.Begin]: initialBeginValues, | |||||
| [Operator.Retrieval]: initialRetrievalValues, | |||||
| [Operator.Generate]: { ...initialGenerateValues, llm_id: llmId }, | |||||
| [Operator.Answer]: {}, | |||||
| [Operator.Categorize]: { ...initialCategorizeValues, llm_id: llmId }, | |||||
| [Operator.Relevant]: { ...initialRelevantValues, llm_id: llmId }, | |||||
| [Operator.RewriteQuestion]: { | |||||
| ...initialRewriteQuestionValues, | |||||
| llm_id: llmId, | |||||
| }, | |||||
| [Operator.Message]: initialMessageValues, | |||||
| [Operator.KeywordExtract]: initialKeywordExtractValues, | |||||
| [Operator.DuckDuckGo]: initialDuckValues, | |||||
| [Operator.Baidu]: initialBaiduValues, | |||||
| }; | |||||
| }, [llmId]); | |||||
| const initializeOperatorParams = useCallback( | const initializeOperatorParams = useCallback( | ||||
| (operatorName: Operator) => { | (operatorName: Operator) => { | ||||
| const initialFormValuesMap = { | |||||
| [Operator.Begin]: initialBeginValues, | |||||
| [Operator.Retrieval]: initialRetrievalValues, | |||||
| [Operator.Generate]: { ...initialGenerateValues, llm_id: llmId }, | |||||
| [Operator.Answer]: {}, | |||||
| [Operator.Categorize]: { ...initialCategorizeValues, llm_id: llmId }, | |||||
| [Operator.Relevant]: { ...initialRelevantValues, llm_id: llmId }, | |||||
| [Operator.RewriteQuestion]: { | |||||
| ...initialRewriteQuestionValues, | |||||
| llm_id: llmId, | |||||
| }, | |||||
| [Operator.Message]: initialMessageValues, | |||||
| }; | |||||
| return initialFormValuesMap[operatorName]; | return initialFormValuesMap[operatorName]; | ||||
| }, | }, | ||||
| [llmId], | |||||
| [initialFormValuesMap], | |||||
| ); | ); | ||||
| return initializeOperatorParams; | return initializeOperatorParams; |