### 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)tags/v0.9.0
| top_n?: number; | top_n?: number; | ||||
| }; | }; | ||||
| const TopNItem = () => { | |||||
| interface IProps { | |||||
| initialValue?: number; | |||||
| } | |||||
| const TopNItem = ({ initialValue = 8 }: IProps) => { | |||||
| const { t } = useTranslate('chat'); | const { t } = useTranslate('chat'); | ||||
| return ( | return ( | ||||
| <Form.Item<FieldType> | <Form.Item<FieldType> | ||||
| label={t('topN')} | label={t('topN')} | ||||
| name={'top_n'} | name={'top_n'} | ||||
| initialValue={8} | |||||
| initialValue={initialValue} | |||||
| tooltip={t('topNTip')} | tooltip={t('topNTip')} | ||||
| > | > | ||||
| <Slider max={30} /> | <Slider max={30} /> |
| form={form} | form={form} | ||||
| onValuesChange={onValuesChange} | onValuesChange={onValuesChange} | ||||
| > | > | ||||
| <TopNItem></TopNItem> | |||||
| <TopNItem initialValue={10}></TopNItem> | |||||
| </Form> | </Form> | ||||
| ); | ); | ||||
| }; | }; |
| text-align: center; | text-align: center; | ||||
| // align-items: center; | // align-items: center; | ||||
| } | } | ||||
| .jsonView { | |||||
| word-wrap: break-word; | |||||
| overflow: auto; | |||||
| max-width: 300px; | |||||
| max-height: 500px; | |||||
| } |
| import { Operator } from '../../constant'; | import { Operator } from '../../constant'; | ||||
| import { useReplaceIdWithText } from '../../hooks'; | import { useReplaceIdWithText } from '../../hooks'; | ||||
| import styles from './index.less'; | |||||
| interface IProps extends React.PropsWithChildren { | interface IProps extends React.PropsWithChildren { | ||||
| nodeId: string; | nodeId: string; | ||||
| } | } | ||||
| <JsonView | <JsonView | ||||
| src={replacedOutput} | src={replacedOutput} | ||||
| displaySize={30} | displaySize={30} | ||||
| style={{ maxWidth: 300, maxHeight: 500 }} | |||||
| className={styles.jsonView} | |||||
| /> | /> | ||||
| </div> | </div> | ||||
| ) : undefined; | ) : undefined; |
| messages: [], | messages: [], | ||||
| }; | }; | ||||
| export const initialKeywordExtractValues = { | |||||
| ...initialLlmBaseValues, | |||||
| top_n: 1, | |||||
| }; | |||||
| export const initialFormValuesMap = { | export const initialFormValuesMap = { | ||||
| [Operator.Begin]: initialBeginValues, | [Operator.Begin]: initialBeginValues, | ||||
| [Operator.Retrieval]: initialRetrievalValues, | [Operator.Retrieval]: initialRetrievalValues, | ||||
| [Operator.Relevant]: initialRelevantValues, | [Operator.Relevant]: initialRelevantValues, | ||||
| [Operator.RewriteQuestion]: initialRewriteQuestionValues, | [Operator.RewriteQuestion]: initialRewriteQuestionValues, | ||||
| [Operator.Message]: initialMessageValues, | [Operator.Message]: initialMessageValues, | ||||
| [Operator.KeywordExtract]: initialKeywordExtractValues, | |||||
| }; | }; | ||||
| export const CategorizeAnchorPointPositions = [ | export const CategorizeAnchorPointPositions = [ |
| form={form} | form={form} | ||||
| onValuesChange={onValuesChange} | onValuesChange={onValuesChange} | ||||
| > | > | ||||
| <TopNItem></TopNItem> | |||||
| <TopNItem initialValue={10}></TopNItem> | |||||
| <Form.Item | <Form.Item | ||||
| label={t('channel')} | label={t('channel')} | ||||
| name={'channel'} | name={'channel'} |
| const { id } = useParams(); | const { id } = useParams(); | ||||
| const { saveGraph } = useSaveGraph(); | const { saveGraph } = useSaveGraph(); | ||||
| const { resetFlow } = useResetFlow(); | const { resetFlow } = useResetFlow(); | ||||
| const { refetch } = useFetchFlow(); | |||||
| const { send } = useSendMessageWithSse(api.runCanvas); | const { send } = useSendMessageWithSse(api.runCanvas); | ||||
| const handleRun = useCallback(async () => { | const handleRun = useCallback(async () => { | ||||
| const saveRet = await saveGraph(); | const saveRet = await saveGraph(); | ||||
| const resetRet = await resetFlow(); | const resetRet = await resetFlow(); | ||||
| // After resetting, all previous messages will be cleared. | // After resetting, all previous messages will be cleared. | ||||
| if (resetRet?.retcode === 0) { | if (resetRet?.retcode === 0) { | ||||
| refetch(); | |||||
| // fetch prologue | // fetch prologue | ||||
| const sendRet = await send({ id }); | const sendRet = await send({ id }); | ||||
| if (receiveMessageError(sendRet)) { | if (receiveMessageError(sendRet)) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| }, [saveGraph, resetFlow, id, send, show]); | |||||
| }, [saveGraph, resetFlow, id, send, show, refetch]); | |||||
| return handleRun; | return handleRun; | ||||
| }; | }; |
| import LLMSelect from '@/components/llm-select'; | |||||
| import TopNItem from '@/components/top-n-item'; | import TopNItem from '@/components/top-n-item'; | ||||
| import { useTranslate } from '@/hooks/commonHooks'; | |||||
| import { Form } from 'antd'; | import { Form } from 'antd'; | ||||
| import { useSetLlmSetting } from '../hooks'; | |||||
| import { IOperatorForm } from '../interface'; | import { IOperatorForm } from '../interface'; | ||||
| const KeywordExtractForm = ({ onValuesChange, form }: IOperatorForm) => { | const KeywordExtractForm = ({ onValuesChange, form }: IOperatorForm) => { | ||||
| const { t } = useTranslate('flow'); | |||||
| useSetLlmSetting(form); | |||||
| return ( | return ( | ||||
| <Form | <Form | ||||
| name="basic" | name="basic" | ||||
| form={form} | form={form} | ||||
| onValuesChange={onValuesChange} | onValuesChange={onValuesChange} | ||||
| > | > | ||||
| <TopNItem></TopNItem> | |||||
| <Form.Item | |||||
| name={'llm_id'} | |||||
| label={t('model', { keyPrefix: 'chat' })} | |||||
| tooltip={t('modelTip', { keyPrefix: 'chat' })} | |||||
| > | |||||
| <LLMSelect></LLMSelect> | |||||
| </Form.Item> | |||||
| <TopNItem initialValue={1}></TopNItem> | |||||
| </Form> | </Form> | ||||
| ); | ); | ||||
| }; | }; |