mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-30 02:12:38 +00:00
doc and config rerank (#475)
This commit is contained in:
@@ -16,7 +16,7 @@ import { BillSourceEnum } from '@fastgpt/global/support/wallet/bill/constants';
|
||||
export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
await connectToDatabase();
|
||||
const { datasetId, text, limit = 20 } = req.body as SearchTestProps;
|
||||
const { datasetId, text, limit = 20, rerank } = req.body as SearchTestProps;
|
||||
|
||||
if (!datasetId || !text) {
|
||||
throw new Error('缺少参数');
|
||||
@@ -38,7 +38,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
text,
|
||||
model: dataset.vectorModel,
|
||||
limit: Math.min(limit, 50),
|
||||
datasetIds: [datasetId]
|
||||
datasetIds: [datasetId],
|
||||
rerank
|
||||
});
|
||||
|
||||
// push bill
|
||||
|
@@ -52,7 +52,7 @@ import MyIcon from '@/components/Icon';
|
||||
import ChatBox, { type ComponentRef, type StartChatFnProps } from '@/components/ChatBox';
|
||||
|
||||
import { addVariable } from '@/components/core/module/VariableEditModal';
|
||||
import { KbParamsModal } from '@/components/core/module/DatasetSelectModal';
|
||||
import { DatasetParamsModal } from '@/components/core/module/DatasetSelectModal';
|
||||
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
|
||||
import { useDatasetStore } from '@/web/core/dataset/store/dataset';
|
||||
import { useAppStore } from '@/web/core/app/store/useAppStore';
|
||||
@@ -585,15 +585,15 @@ const Settings = ({ appId }: { appId: string }) => {
|
||||
)}
|
||||
|
||||
{isOpenKbParams && (
|
||||
<KbParamsModal
|
||||
searchEmptyText={getValues('dataset.searchEmptyText')}
|
||||
searchLimit={getValues('dataset.searchLimit')}
|
||||
searchSimilarity={getValues('dataset.searchSimilarity')}
|
||||
<DatasetParamsModal
|
||||
{...getValues('dataset')}
|
||||
onClose={onCloseKbParams}
|
||||
onChange={({ searchEmptyText, searchLimit, searchSimilarity }) => {
|
||||
setValue('dataset.searchEmptyText', searchEmptyText);
|
||||
setValue('dataset.searchLimit', searchLimit);
|
||||
setValue('dataset.searchSimilarity', searchSimilarity);
|
||||
onChange={(e) => {
|
||||
setValue('dataset', {
|
||||
...getValues('dataset'),
|
||||
...e
|
||||
});
|
||||
|
||||
setRefresh((state) => !state);
|
||||
}}
|
||||
/>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { Box, Textarea, Button, Flex, useTheme, Grid, Progress } from '@chakra-ui/react';
|
||||
import { Box, Textarea, Button, Flex, useTheme, Grid, Progress, Switch } from '@chakra-ui/react';
|
||||
import { useDatasetStore } from '@/web/core/dataset/store/dataset';
|
||||
import { useSearchTestStore, SearchTestStoreItemType } from '@/web/core/dataset/store/searchTest';
|
||||
import { getDatasetDataItemById, postSearchText } from '@/web/core/dataset/api';
|
||||
@@ -15,6 +15,7 @@ import MyTooltip from '@/components/MyTooltip';
|
||||
import { QuestionOutlineIcon } from '@chakra-ui/icons';
|
||||
import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { feConfigs } from '@/web/common/system/staticData';
|
||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 12);
|
||||
|
||||
const Test = ({ datasetId }: { datasetId: string }) => {
|
||||
@@ -28,6 +29,7 @@ const Test = ({ datasetId }: { datasetId: string }) => {
|
||||
const [inputText, setInputText] = useState('');
|
||||
const [datasetTestItem, setDatasetTestItem] = useState<SearchTestStoreItemType>();
|
||||
const [editInputData, setEditInputData] = useState<InputDataType & { collectionId: string }>();
|
||||
const [rerank, setRerank] = useState(false);
|
||||
|
||||
const kbTestHistory = useMemo(
|
||||
() => datasetTestList.filter((item) => item.datasetId === datasetId),
|
||||
@@ -35,7 +37,7 @@ const Test = ({ datasetId }: { datasetId: string }) => {
|
||||
);
|
||||
|
||||
const { mutate, isLoading } = useRequest({
|
||||
mutationFn: () => postSearchText({ datasetId, text: inputText.trim() }),
|
||||
mutationFn: () => postSearchText({ datasetId, text: inputText.trim(), rerank, limit: 20 }),
|
||||
onSuccess(res: SearchDataResponseItemType[]) {
|
||||
if (!res || res.length === 0) {
|
||||
return toast({
|
||||
@@ -91,7 +93,13 @@ const Test = ({ datasetId }: { datasetId: string }) => {
|
||||
onChange={(e) => setInputText(e.target.value)}
|
||||
/>
|
||||
<Flex alignItems={'center'} justifyContent={'flex-end'}>
|
||||
<Box mr={3} color={'myGray.500'}>
|
||||
{feConfigs?.isPlus && (
|
||||
<Flex alignItems={'center'}>
|
||||
{t('dataset.recall.rerank')}
|
||||
<Switch ml={1} isChecked={rerank} onChange={(e) => setRerank(e.target.checked)} />
|
||||
</Flex>
|
||||
)}
|
||||
<Box mx={3} color={'myGray.500'}>
|
||||
{inputText.length}
|
||||
</Box>
|
||||
<Button isDisabled={inputText === ''} isLoading={isLoading} onClick={mutate}>
|
||||
|
Reference in New Issue
Block a user