mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
feat: create a chat assistant and extract SimilaritySlider (#67)
* feat: extract SimilaritySlider * feat: create a chat assistant
This commit is contained in:
@ -53,7 +53,7 @@ const RenameModal = () => {
|
||||
|
||||
useEffect(() => {
|
||||
form.setFieldValue('name', initialName);
|
||||
}, [initialName, documentId]);
|
||||
}, [initialName, documentId, form]);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@ -17,13 +17,14 @@ import {
|
||||
UploadFile,
|
||||
} from 'antd';
|
||||
import pick from 'lodash/pick';
|
||||
import { useCallback, useEffect, useMemo } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { useDispatch, useSelector } from 'umi';
|
||||
|
||||
import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llmHooks';
|
||||
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
|
||||
import { IKnowledge } from '@/interfaces/database/knowledge';
|
||||
import { IThirdOAIModelCollection } from '@/interfaces/database/llm';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { LlmModelType } from '../../constant';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Title } = Typography;
|
||||
@ -35,9 +36,6 @@ const Configuration = () => {
|
||||
const knowledgeBaseId = useKnowledgeBaseId();
|
||||
const loading = useOneNamespaceEffectsLoading('kSModel', ['updateKb']);
|
||||
|
||||
const llmInfo: IThirdOAIModelCollection = useSelector(
|
||||
(state: any) => state.settingModel.llmInfo,
|
||||
);
|
||||
const knowledgeDetails: IKnowledge = useSelector(
|
||||
(state: any) => state.kSModel.knowledgeDetails,
|
||||
);
|
||||
@ -51,17 +49,7 @@ const Configuration = () => {
|
||||
|
||||
const parserList = useSelectParserList();
|
||||
|
||||
const embeddingModelOptions = useMemo(() => {
|
||||
return Object.entries(llmInfo).map(([key, value]) => {
|
||||
return {
|
||||
label: key,
|
||||
options: value.map((x) => ({
|
||||
label: x.llm_name,
|
||||
value: x.llm_name,
|
||||
})),
|
||||
};
|
||||
});
|
||||
}, [llmInfo]);
|
||||
const embeddingModelOptions = useSelectLlmOptions();
|
||||
|
||||
const onFinish = async (values: any) => {
|
||||
console.info(values);
|
||||
@ -86,13 +74,6 @@ const Configuration = () => {
|
||||
console.log('Failed:', errorInfo);
|
||||
};
|
||||
|
||||
const fetchLlmList = useCallback(() => {
|
||||
dispatch({
|
||||
type: 'settingModel/llm_list',
|
||||
payload: { model_type: 'embedding' },
|
||||
});
|
||||
}, [dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
const avatar = knowledgeDetails.avatar;
|
||||
let fileList: UploadFile[] = [];
|
||||
@ -115,9 +96,7 @@ const Configuration = () => {
|
||||
useFetchParserList();
|
||||
useFetchKnowledgeBaseConfiguration();
|
||||
|
||||
useEffect(() => {
|
||||
fetchLlmList();
|
||||
}, [fetchLlmList]);
|
||||
useFetchLlmList(LlmModelType.Embedding);
|
||||
|
||||
return (
|
||||
<div className={styles.configurationWrapper}>
|
||||
|
||||
@ -16,14 +16,10 @@ const KnowledgeTesting = () => {
|
||||
const handleTesting = async () => {
|
||||
const values = await form.validateFields();
|
||||
console.info(values);
|
||||
const similarity_threshold = values.similarity_threshold / 100;
|
||||
const vector_similarity_weight = values.vector_similarity_weight / 100;
|
||||
dispatch({
|
||||
type: 'testingModel/testDocumentChunk',
|
||||
payload: {
|
||||
...values,
|
||||
similarity_threshold,
|
||||
vector_similarity_weight,
|
||||
kb_id: knowledgeBaseId,
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import SimilaritySlider from '@/components/similarity-slider';
|
||||
import { DeleteOutlined, HistoryOutlined } from '@ant-design/icons';
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
@ -6,22 +8,15 @@ import {
|
||||
Form,
|
||||
Input,
|
||||
Slider,
|
||||
SliderSingleProps,
|
||||
Space,
|
||||
Tag,
|
||||
} from 'antd';
|
||||
|
||||
import { DeleteOutlined, HistoryOutlined } from '@ant-design/icons';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
|
||||
import styles from './index.less';
|
||||
|
||||
const list = [1, 2, 3];
|
||||
|
||||
const marks: SliderSingleProps['marks'] = {
|
||||
0: '0',
|
||||
100: '1',
|
||||
};
|
||||
|
||||
type FieldType = {
|
||||
similarity_threshold?: number;
|
||||
vector_similarity_weight?: number;
|
||||
@ -29,12 +24,6 @@ type FieldType = {
|
||||
question: string;
|
||||
};
|
||||
|
||||
const formatter = (value: number | undefined) => {
|
||||
return typeof value === 'number' ? value / 100 : 0;
|
||||
};
|
||||
|
||||
const tooltip = { formatter };
|
||||
|
||||
interface IProps {
|
||||
form: FormInstance;
|
||||
handleTesting: () => Promise<any>;
|
||||
@ -59,23 +48,12 @@ const TestingControl = ({ form, handleTesting }: IProps) => {
|
||||
layout="vertical"
|
||||
form={form}
|
||||
initialValues={{
|
||||
similarity_threshold: 20,
|
||||
vector_similarity_weight: 30,
|
||||
similarity_threshold: 0.2,
|
||||
vector_similarity_weight: 0.3,
|
||||
top_k: 1024,
|
||||
}}
|
||||
>
|
||||
<Form.Item<FieldType>
|
||||
label="Similarity threshold"
|
||||
name={'similarity_threshold'}
|
||||
>
|
||||
<Slider marks={marks} defaultValue={0} tooltip={tooltip} />
|
||||
</Form.Item>
|
||||
<Form.Item<FieldType>
|
||||
label="Vector similarity weight"
|
||||
name={'vector_similarity_weight'}
|
||||
>
|
||||
<Slider marks={marks} defaultValue={0} tooltip={tooltip} />
|
||||
</Form.Item>
|
||||
<SimilaritySlider></SimilaritySlider>
|
||||
<Form.Item<FieldType> label="Top k" name={'top_k'}>
|
||||
<Slider marks={{ 0: 0, 2048: 2048 }} defaultValue={0} max={2048} />
|
||||
</Form.Item>
|
||||
|
||||
Reference in New Issue
Block a user