balibabu commited on
Commit
a9048a7
·
1 Parent(s): 78e4e26

fix: fixed the issue where parameters of DuckDuckGo could not be saved to the backend after being dragged to the canvas #918 (#1503)

Browse files

### 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)

web/src/pages/flow/constant.tsx CHANGED
@@ -4,6 +4,12 @@ import { ReactComponent as KeywordIcon } from '@/assets/svg/keyword.svg';
4
  import { variableEnabledFieldMap } from '@/constants/chat';
5
  import i18n from '@/locales/config';
6
 
 
 
 
 
 
 
7
  import {
8
  BranchesOutlined,
9
  DatabaseOutlined,
@@ -192,17 +198,13 @@ export const initialKeywordExtractValues = {
192
  ...initialLlmBaseValues,
193
  top_n: 1,
194
  };
 
 
 
 
195
 
196
- export const initialFormValuesMap = {
197
- [Operator.Begin]: initialBeginValues,
198
- [Operator.Retrieval]: initialRetrievalValues,
199
- [Operator.Generate]: initialGenerateValues,
200
- [Operator.Answer]: {},
201
- [Operator.Categorize]: initialCategorizeValues,
202
- [Operator.Relevant]: initialRelevantValues,
203
- [Operator.RewriteQuestion]: initialRewriteQuestionValues,
204
- [Operator.Message]: initialMessageValues,
205
- [Operator.KeywordExtract]: initialKeywordExtractValues,
206
  };
207
 
208
  export const CategorizeAnchorPointPositions = [
 
4
  import { variableEnabledFieldMap } from '@/constants/chat';
5
  import i18n from '@/locales/config';
6
 
7
+ // DuckDuckGo's channel options
8
+ export enum Channel {
9
+ Text = 'text',
10
+ News = 'news',
11
+ }
12
+
13
  import {
14
  BranchesOutlined,
15
  DatabaseOutlined,
 
198
  ...initialLlmBaseValues,
199
  top_n: 1,
200
  };
201
+ export const initialDuckValues = {
202
+ top_n: 10,
203
+ channel: Channel.Text,
204
+ };
205
 
206
+ export const initialBaiduValues = {
207
+ top_n: 10,
 
 
 
 
 
 
 
 
208
  };
209
 
210
  export const CategorizeAnchorPointPositions = [
web/src/pages/flow/duckduckgo-form/index.tsx CHANGED
@@ -1,11 +1,17 @@
1
  import TopNItem from '@/components/top-n-item';
2
  import { useTranslate } from '@/hooks/commonHooks';
3
  import { Form, Select } from 'antd';
 
 
4
  import { IOperatorForm } from '../interface';
5
 
6
  const DuckDuckGoForm = ({ onValuesChange, form }: IOperatorForm) => {
7
  const { t } = useTranslate('flow');
8
 
 
 
 
 
9
  return (
10
  <Form
11
  name="basic"
@@ -22,12 +28,7 @@ const DuckDuckGoForm = ({ onValuesChange, form }: IOperatorForm) => {
22
  tooltip={t('channelTip')}
23
  initialValue={'text'}
24
  >
25
- <Select
26
- options={[
27
- { value: 'text', label: t('text') },
28
- { value: 'news', label: t('news') },
29
- ]}
30
- ></Select>
31
  </Form.Item>
32
  </Form>
33
  );
 
1
  import TopNItem from '@/components/top-n-item';
2
  import { useTranslate } from '@/hooks/commonHooks';
3
  import { Form, Select } from 'antd';
4
+ import { useMemo } from 'react';
5
+ import { Channel } from '../constant';
6
  import { IOperatorForm } from '../interface';
7
 
8
  const DuckDuckGoForm = ({ onValuesChange, form }: IOperatorForm) => {
9
  const { t } = useTranslate('flow');
10
 
11
+ const options = useMemo(() => {
12
+ return Object.values(Channel).map((x) => ({ value: x, label: t(x) }));
13
+ }, [t]);
14
+
15
  return (
16
  <Form
17
  name="basic"
 
28
  tooltip={t('channelTip')}
29
  initialValue={'text'}
30
  >
31
+ <Select options={options}></Select>
 
 
 
 
 
32
  </Form.Item>
33
  </Form>
34
  );
web/src/pages/flow/hooks.ts CHANGED
@@ -8,6 +8,7 @@ import React, {
8
  KeyboardEventHandler,
9
  useCallback,
10
  useEffect,
 
11
  useState,
12
  } from 'react';
13
  import { Connection, Edge, Node, Position, ReactFlowInstance } from 'reactflow';
@@ -30,9 +31,12 @@ import {
30
  NodeMap,
31
  Operator,
32
  RestrictedUpstreamMap,
 
33
  initialBeginValues,
34
  initialCategorizeValues,
 
35
  initialGenerateValues,
 
36
  initialMessageValues,
37
  initialRelevantValues,
38
  initialRetrievalValues,
@@ -65,24 +69,30 @@ export const useSelectCanvasData = () => {
65
  export const useInitializeOperatorParams = () => {
66
  const llmId = useFetchModelId(true);
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  const initializeOperatorParams = useCallback(
69
  (operatorName: Operator) => {
70
- const initialFormValuesMap = {
71
- [Operator.Begin]: initialBeginValues,
72
- [Operator.Retrieval]: initialRetrievalValues,
73
- [Operator.Generate]: { ...initialGenerateValues, llm_id: llmId },
74
- [Operator.Answer]: {},
75
- [Operator.Categorize]: { ...initialCategorizeValues, llm_id: llmId },
76
- [Operator.Relevant]: { ...initialRelevantValues, llm_id: llmId },
77
- [Operator.RewriteQuestion]: {
78
- ...initialRewriteQuestionValues,
79
- llm_id: llmId,
80
- },
81
- [Operator.Message]: initialMessageValues,
82
- };
83
  return initialFormValuesMap[operatorName];
84
  },
85
- [llmId],
86
  );
87
 
88
  return initializeOperatorParams;
 
8
  KeyboardEventHandler,
9
  useCallback,
10
  useEffect,
11
+ useMemo,
12
  useState,
13
  } from 'react';
14
  import { Connection, Edge, Node, Position, ReactFlowInstance } from 'reactflow';
 
31
  NodeMap,
32
  Operator,
33
  RestrictedUpstreamMap,
34
+ initialBaiduValues,
35
  initialBeginValues,
36
  initialCategorizeValues,
37
+ initialDuckValues,
38
  initialGenerateValues,
39
+ initialKeywordExtractValues,
40
  initialMessageValues,
41
  initialRelevantValues,
42
  initialRetrievalValues,
 
69
  export const useInitializeOperatorParams = () => {
70
  const llmId = useFetchModelId(true);
71
 
72
+ const initialFormValuesMap = useMemo(() => {
73
+ return {
74
+ [Operator.Begin]: initialBeginValues,
75
+ [Operator.Retrieval]: initialRetrievalValues,
76
+ [Operator.Generate]: { ...initialGenerateValues, llm_id: llmId },
77
+ [Operator.Answer]: {},
78
+ [Operator.Categorize]: { ...initialCategorizeValues, llm_id: llmId },
79
+ [Operator.Relevant]: { ...initialRelevantValues, llm_id: llmId },
80
+ [Operator.RewriteQuestion]: {
81
+ ...initialRewriteQuestionValues,
82
+ llm_id: llmId,
83
+ },
84
+ [Operator.Message]: initialMessageValues,
85
+ [Operator.KeywordExtract]: initialKeywordExtractValues,
86
+ [Operator.DuckDuckGo]: initialDuckValues,
87
+ [Operator.Baidu]: initialBaiduValues,
88
+ };
89
+ }, [llmId]);
90
+
91
  const initializeOperatorParams = useCallback(
92
  (operatorName: Operator) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  return initialFormValuesMap[operatorName];
94
  },
95
+ [initialFormValuesMap],
96
  );
97
 
98
  return initializeOperatorParams;