balibabu commited on
Commit
53bc504
·
1 Parent(s): c832019

feat: add llm Select to KeywordExtractForm #918 (#1492)

Browse files

### What problem does this PR solve?

feat: add llm Select to KeywordExtractForm #918

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/components/top-n-item.tsx CHANGED
@@ -5,14 +5,18 @@ type FieldType = {
5
  top_n?: number;
6
  };
7
 
8
- const TopNItem = () => {
 
 
 
 
9
  const { t } = useTranslate('chat');
10
 
11
  return (
12
  <Form.Item<FieldType>
13
  label={t('topN')}
14
  name={'top_n'}
15
- initialValue={8}
16
  tooltip={t('topNTip')}
17
  >
18
  <Slider max={30} />
 
5
  top_n?: number;
6
  };
7
 
8
+ interface IProps {
9
+ initialValue?: number;
10
+ }
11
+
12
+ const TopNItem = ({ initialValue = 8 }: IProps) => {
13
  const { t } = useTranslate('chat');
14
 
15
  return (
16
  <Form.Item<FieldType>
17
  label={t('topN')}
18
  name={'top_n'}
19
+ initialValue={initialValue}
20
  tooltip={t('topNTip')}
21
  >
22
  <Slider max={30} />
web/src/pages/flow/baidu-form/index.tsx CHANGED
@@ -12,7 +12,7 @@ const BaiduForm = ({ onValuesChange, form }: IOperatorForm) => {
12
  form={form}
13
  onValuesChange={onValuesChange}
14
  >
15
- <TopNItem></TopNItem>
16
  </Form>
17
  );
18
  };
 
12
  form={form}
13
  onValuesChange={onValuesChange}
14
  >
15
+ <TopNItem initialValue={10}></TopNItem>
16
  </Form>
17
  );
18
  };
web/src/pages/flow/canvas/node/index.less CHANGED
@@ -57,3 +57,10 @@
57
  text-align: center;
58
  // align-items: center;
59
  }
 
 
 
 
 
 
 
 
57
  text-align: center;
58
  // align-items: center;
59
  }
60
+
61
+ .jsonView {
62
+ word-wrap: break-word;
63
+ overflow: auto;
64
+ max-width: 300px;
65
+ max-height: 500px;
66
+ }
web/src/pages/flow/canvas/node/popover.tsx CHANGED
@@ -7,6 +7,8 @@ import 'react18-json-view/src/style.css';
7
  import { Operator } from '../../constant';
8
  import { useReplaceIdWithText } from '../../hooks';
9
 
 
 
10
  interface IProps extends React.PropsWithChildren {
11
  nodeId: string;
12
  }
@@ -32,7 +34,7 @@ const NodePopover = ({ children, nodeId }: IProps) => {
32
  <JsonView
33
  src={replacedOutput}
34
  displaySize={30}
35
- style={{ maxWidth: 300, maxHeight: 500 }}
36
  />
37
  </div>
38
  ) : undefined;
 
7
  import { Operator } from '../../constant';
8
  import { useReplaceIdWithText } from '../../hooks';
9
 
10
+ import styles from './index.less';
11
+
12
  interface IProps extends React.PropsWithChildren {
13
  nodeId: string;
14
  }
 
34
  <JsonView
35
  src={replacedOutput}
36
  displaySize={30}
37
+ className={styles.jsonView}
38
  />
39
  </div>
40
  ) : undefined;
web/src/pages/flow/constant.tsx CHANGED
@@ -188,6 +188,11 @@ export const initialMessageValues = {
188
  messages: [],
189
  };
190
 
 
 
 
 
 
191
  export const initialFormValuesMap = {
192
  [Operator.Begin]: initialBeginValues,
193
  [Operator.Retrieval]: initialRetrievalValues,
@@ -197,6 +202,7 @@ export const initialFormValuesMap = {
197
  [Operator.Relevant]: initialRelevantValues,
198
  [Operator.RewriteQuestion]: initialRewriteQuestionValues,
199
  [Operator.Message]: initialMessageValues,
 
200
  };
201
 
202
  export const CategorizeAnchorPointPositions = [
 
188
  messages: [],
189
  };
190
 
191
+ export const initialKeywordExtractValues = {
192
+ ...initialLlmBaseValues,
193
+ top_n: 1,
194
+ };
195
+
196
  export const initialFormValuesMap = {
197
  [Operator.Begin]: initialBeginValues,
198
  [Operator.Retrieval]: initialRetrievalValues,
 
202
  [Operator.Relevant]: initialRelevantValues,
203
  [Operator.RewriteQuestion]: initialRewriteQuestionValues,
204
  [Operator.Message]: initialMessageValues,
205
+ [Operator.KeywordExtract]: initialKeywordExtractValues,
206
  };
207
 
208
  export const CategorizeAnchorPointPositions = [
web/src/pages/flow/duckduckgo-form/index.tsx CHANGED
@@ -15,7 +15,7 @@ const DuckDuckGoForm = ({ onValuesChange, form }: IOperatorForm) => {
15
  form={form}
16
  onValuesChange={onValuesChange}
17
  >
18
- <TopNItem></TopNItem>
19
  <Form.Item
20
  label={t('channel')}
21
  name={'channel'}
 
15
  form={form}
16
  onValuesChange={onValuesChange}
17
  >
18
+ <TopNItem initialValue={10}></TopNItem>
19
  <Form.Item
20
  label={t('channel')}
21
  name={'channel'}
web/src/pages/flow/hooks.ts CHANGED
@@ -365,6 +365,7 @@ export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {
365
  const { id } = useParams();
366
  const { saveGraph } = useSaveGraph();
367
  const { resetFlow } = useResetFlow();
 
368
  const { send } = useSendMessageWithSse(api.runCanvas);
369
  const handleRun = useCallback(async () => {
370
  const saveRet = await saveGraph();
@@ -373,6 +374,7 @@ export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {
373
  const resetRet = await resetFlow();
374
  // After resetting, all previous messages will be cleared.
375
  if (resetRet?.retcode === 0) {
 
376
  // fetch prologue
377
  const sendRet = await send({ id });
378
  if (receiveMessageError(sendRet)) {
@@ -382,7 +384,7 @@ export const useSaveGraphBeforeOpeningDebugDrawer = (show: () => void) => {
382
  }
383
  }
384
  }
385
- }, [saveGraph, resetFlow, id, send, show]);
386
 
387
  return handleRun;
388
  };
 
365
  const { id } = useParams();
366
  const { saveGraph } = useSaveGraph();
367
  const { resetFlow } = useResetFlow();
368
+ const { refetch } = useFetchFlow();
369
  const { send } = useSendMessageWithSse(api.runCanvas);
370
  const handleRun = useCallback(async () => {
371
  const saveRet = await saveGraph();
 
374
  const resetRet = await resetFlow();
375
  // After resetting, all previous messages will be cleared.
376
  if (resetRet?.retcode === 0) {
377
+ refetch();
378
  // fetch prologue
379
  const sendRet = await send({ id });
380
  if (receiveMessageError(sendRet)) {
 
384
  }
385
  }
386
  }
387
+ }, [saveGraph, resetFlow, id, send, show, refetch]);
388
 
389
  return handleRun;
390
  };
web/src/pages/flow/keyword-extract-form/index.tsx CHANGED
@@ -1,8 +1,15 @@
 
1
  import TopNItem from '@/components/top-n-item';
 
2
  import { Form } from 'antd';
 
3
  import { IOperatorForm } from '../interface';
4
 
5
  const KeywordExtractForm = ({ onValuesChange, form }: IOperatorForm) => {
 
 
 
 
6
  return (
7
  <Form
8
  name="basic"
@@ -12,7 +19,14 @@ const KeywordExtractForm = ({ onValuesChange, form }: IOperatorForm) => {
12
  form={form}
13
  onValuesChange={onValuesChange}
14
  >
15
- <TopNItem></TopNItem>
 
 
 
 
 
 
 
16
  </Form>
17
  );
18
  };
 
1
+ import LLMSelect from '@/components/llm-select';
2
  import TopNItem from '@/components/top-n-item';
3
+ import { useTranslate } from '@/hooks/commonHooks';
4
  import { Form } from 'antd';
5
+ import { useSetLlmSetting } from '../hooks';
6
  import { IOperatorForm } from '../interface';
7
 
8
  const KeywordExtractForm = ({ onValuesChange, form }: IOperatorForm) => {
9
+ const { t } = useTranslate('flow');
10
+
11
+ useSetLlmSetting(form);
12
+
13
  return (
14
  <Form
15
  name="basic"
 
19
  form={form}
20
  onValuesChange={onValuesChange}
21
  >
22
+ <Form.Item
23
+ name={'llm_id'}
24
+ label={t('model', { keyPrefix: 'chat' })}
25
+ tooltip={t('modelTip', { keyPrefix: 'chat' })}
26
+ >
27
+ <LLMSelect></LLMSelect>
28
+ </Form.Item>
29
+ <TopNItem initialValue={1}></TopNItem>
30
  </Form>
31
  );
32
  };