mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-01 16:15:07 +08:00
### What problem does this PR solve? Refactor: Refactoring VolcEngine and Yiyan modal using shadcn. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -3,7 +3,7 @@ export interface IAddLlmRequestBody {
|
|||||||
llm_name: string;
|
llm_name: string;
|
||||||
model_type: string;
|
model_type: string;
|
||||||
api_base?: string; // chat|embedding|speech2text|image2text
|
api_base?: string; // chat|embedding|speech2text|image2text
|
||||||
api_key: string | Record<string, any>;
|
api_key?: string | Record<string, any>;
|
||||||
max_tokens: number;
|
max_tokens: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
import { Form } from 'antd';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
export const useValidateSubmittable = () => {
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const [submittable, setSubmittable] = useState<boolean>(false);
|
|
||||||
|
|
||||||
// Watch all values
|
|
||||||
const values = Form.useWatch([], form);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
form
|
|
||||||
.validateFields({ validateOnly: true })
|
|
||||||
.then(() => setSubmittable(true))
|
|
||||||
.catch(() => setSubmittable(false));
|
|
||||||
}, [form, values]);
|
|
||||||
|
|
||||||
return { submittable, form };
|
|
||||||
};
|
|
||||||
@ -1,20 +1,20 @@
|
|||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import {
|
||||||
|
DynamicForm,
|
||||||
|
FormFieldConfig,
|
||||||
|
FormFieldType,
|
||||||
|
} from '@/components/dynamic-form';
|
||||||
|
import { Modal } from '@/components/ui/modal/modal';
|
||||||
|
import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks';
|
||||||
import { IModalProps } from '@/interfaces/common';
|
import { IModalProps } from '@/interfaces/common';
|
||||||
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
||||||
import { Flex, Form, Input, InputNumber, Modal, Select, Space } from 'antd';
|
import { FieldValues } from 'react-hook-form';
|
||||||
import omit from 'lodash/omit';
|
|
||||||
import { LLMHeader } from '../../components/llm-header';
|
import { LLMHeader } from '../../components/llm-header';
|
||||||
|
|
||||||
type FieldType = IAddLlmRequestBody & {
|
type VolcEngineLlmRequest = IAddLlmRequestBody & {
|
||||||
vision: boolean;
|
|
||||||
volc_ak: string;
|
|
||||||
volc_sk: string;
|
|
||||||
endpoint_id: string;
|
endpoint_id: string;
|
||||||
ark_api_key: string;
|
ark_api_key: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { Option } = Select;
|
|
||||||
|
|
||||||
const VolcEngineModal = ({
|
const VolcEngineModal = ({
|
||||||
visible,
|
visible,
|
||||||
hideModal,
|
hideModal,
|
||||||
@ -22,115 +22,122 @@ const VolcEngineModal = ({
|
|||||||
loading,
|
loading,
|
||||||
llmFactory,
|
llmFactory,
|
||||||
}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => {
|
}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => {
|
||||||
const [form] = Form.useForm<FieldType>();
|
|
||||||
|
|
||||||
const { t } = useTranslate('setting');
|
const { t } = useTranslate('setting');
|
||||||
|
const { t: tc } = useCommonTranslation();
|
||||||
|
|
||||||
|
const fields: FormFieldConfig[] = [
|
||||||
|
{
|
||||||
|
name: 'model_type',
|
||||||
|
label: t('modelType'),
|
||||||
|
type: FormFieldType.Select,
|
||||||
|
required: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'chat', value: 'chat' },
|
||||||
|
{ label: 'embedding', value: 'embedding' },
|
||||||
|
{ label: 'image2text', value: 'image2text' },
|
||||||
|
],
|
||||||
|
defaultValue: 'chat',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'llm_name',
|
||||||
|
label: t('modelName'),
|
||||||
|
type: FormFieldType.Text,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('volcModelNameMessage'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'endpoint_id',
|
||||||
|
label: t('addEndpointID'),
|
||||||
|
type: FormFieldType.Text,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('endpointIDMessage'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'ark_api_key',
|
||||||
|
label: t('addArkApiKey'),
|
||||||
|
type: FormFieldType.Text,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('ArkApiKeyMessage'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'max_tokens',
|
||||||
|
label: t('maxTokens'),
|
||||||
|
type: FormFieldType.Number,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('maxTokensTip'),
|
||||||
|
validation: {
|
||||||
|
min: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleOk = async (values?: FieldValues) => {
|
||||||
|
if (!values) return;
|
||||||
|
|
||||||
const handleOk = async () => {
|
|
||||||
const values = await form.validateFields();
|
|
||||||
const modelType =
|
const modelType =
|
||||||
values.model_type === 'chat' && values.vision
|
values.model_type === 'chat' && values.vision
|
||||||
? 'image2text'
|
? 'image2text'
|
||||||
: values.model_type;
|
: values.model_type;
|
||||||
|
|
||||||
const data = {
|
const data: VolcEngineLlmRequest = {
|
||||||
...omit(values, ['vision']),
|
|
||||||
model_type: modelType,
|
|
||||||
llm_factory: llmFactory,
|
llm_factory: llmFactory,
|
||||||
max_tokens: values.max_tokens,
|
llm_name: values.llm_name as string,
|
||||||
|
model_type: modelType,
|
||||||
|
endpoint_id: values.endpoint_id as string,
|
||||||
|
ark_api_key: values.ark_api_key as string,
|
||||||
|
max_tokens: values.max_tokens as number,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.info(data);
|
console.info(data);
|
||||||
|
|
||||||
onOk?.(data);
|
await onOk?.(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={<LLMHeader name={llmFactory} />}
|
title={<LLMHeader name={llmFactory} />}
|
||||||
open={visible}
|
open={visible || false}
|
||||||
onOk={handleOk}
|
onOpenChange={(open) => !open && hideModal?.()}
|
||||||
onCancel={hideModal}
|
maskClosable={false}
|
||||||
okButtonProps={{ loading }}
|
footer={<div className="p-4"></div>}
|
||||||
footer={(originNode: React.ReactNode) => {
|
|
||||||
return (
|
|
||||||
<Flex justify={'space-between'}>
|
|
||||||
<a
|
|
||||||
href="https://www.volcengine.com/docs/82379/1302008"
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
{t('ollamaLink', { name: llmFactory })}
|
|
||||||
</a>
|
|
||||||
<Space>{originNode}</Space>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Form
|
<DynamicForm.Root
|
||||||
name="basic"
|
fields={fields}
|
||||||
style={{ maxWidth: 600 }}
|
onSubmit={(data) => {
|
||||||
autoComplete="off"
|
console.log(data);
|
||||||
layout={'vertical'}
|
}}
|
||||||
form={form}
|
defaultValues={
|
||||||
|
{
|
||||||
|
model_type: 'chat',
|
||||||
|
vision: false,
|
||||||
|
} as FieldValues
|
||||||
|
}
|
||||||
|
labelClassName="font-normal"
|
||||||
>
|
>
|
||||||
<Form.Item<FieldType>
|
<div className="absolute bottom-0 right-0 left-0 flex items-center justify-between w-full py-6 px-6">
|
||||||
label={t('modelType')}
|
<a
|
||||||
name="model_type"
|
href="https://www.volcengine.com/docs/82379/1302008"
|
||||||
initialValue={'chat'}
|
target="_blank"
|
||||||
rules={[{ required: true, message: t('modelTypeMessage') }]}
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
<Select placeholder={t('modelTypeMessage')}>
|
{t('ollamaLink', { name: llmFactory })}
|
||||||
<Option value="chat">chat</Option>
|
</a>
|
||||||
<Option value="embedding">embedding</Option>
|
<div className="flex gap-2">
|
||||||
<Option value="image2text">image2text</Option>
|
<DynamicForm.CancelButton
|
||||||
</Select>
|
handleCancel={() => {
|
||||||
</Form.Item>
|
hideModal?.();
|
||||||
<Form.Item<FieldType>
|
}}
|
||||||
label={t('modelName')}
|
/>
|
||||||
name="llm_name"
|
<DynamicForm.SavingButton
|
||||||
rules={[{ required: true, message: t('volcModelNameMessage') }]}
|
submitLoading={loading || false}
|
||||||
>
|
buttonText={tc('ok')}
|
||||||
<Input placeholder={t('volcModelNameMessage')} />
|
submitFunc={(values: FieldValues) => {
|
||||||
</Form.Item>
|
handleOk(values);
|
||||||
<Form.Item<FieldType>
|
}}
|
||||||
label={t('addEndpointID')}
|
/>
|
||||||
name="endpoint_id"
|
</div>
|
||||||
rules={[{ required: true, message: t('endpointIDMessage') }]}
|
</div>
|
||||||
>
|
</DynamicForm.Root>
|
||||||
<Input placeholder={t('endpointIDMessage')} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item<FieldType>
|
|
||||||
label={t('addArkApiKey')}
|
|
||||||
name="ark_api_key"
|
|
||||||
rules={[{ required: true, message: t('ArkApiKeyMessage') }]}
|
|
||||||
>
|
|
||||||
<Input placeholder={t('ArkApiKeyMessage')} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item<FieldType>
|
|
||||||
label={t('maxTokens')}
|
|
||||||
name="max_tokens"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('maxTokensMessage') },
|
|
||||||
{
|
|
||||||
type: 'number',
|
|
||||||
message: t('maxTokensInvalidMessage'),
|
|
||||||
},
|
|
||||||
({}) => ({
|
|
||||||
validator(_, value) {
|
|
||||||
if (value < 0) {
|
|
||||||
return Promise.reject(new Error(t('maxTokensMinMessage')));
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<InputNumber
|
|
||||||
placeholder={t('maxTokensTip')}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import {
|
||||||
|
DynamicForm,
|
||||||
|
FormFieldConfig,
|
||||||
|
FormFieldType,
|
||||||
|
} from '@/components/dynamic-form';
|
||||||
|
import { Modal } from '@/components/ui/modal/modal';
|
||||||
|
import { useCommonTranslation, useTranslate } from '@/hooks/common-hooks';
|
||||||
import { IModalProps } from '@/interfaces/common';
|
import { IModalProps } from '@/interfaces/common';
|
||||||
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
||||||
import { Form, Input, InputNumber, Modal, Select } from 'antd';
|
import { FieldValues } from 'react-hook-form';
|
||||||
import omit from 'lodash/omit';
|
|
||||||
import { LLMHeader } from '../../components/llm-header';
|
import { LLMHeader } from '../../components/llm-header';
|
||||||
|
|
||||||
type FieldType = IAddLlmRequestBody & {
|
|
||||||
vision: boolean;
|
|
||||||
yiyan_ak: string;
|
|
||||||
yiyan_sk: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const { Option } = Select;
|
|
||||||
|
|
||||||
const YiyanModal = ({
|
const YiyanModal = ({
|
||||||
visible,
|
visible,
|
||||||
hideModal,
|
hideModal,
|
||||||
@ -20,111 +17,115 @@ const YiyanModal = ({
|
|||||||
loading,
|
loading,
|
||||||
llmFactory,
|
llmFactory,
|
||||||
}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => {
|
}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => {
|
||||||
const [form] = Form.useForm<FieldType>();
|
|
||||||
|
|
||||||
const { t } = useTranslate('setting');
|
const { t } = useTranslate('setting');
|
||||||
|
const { t: tc } = useCommonTranslation();
|
||||||
|
|
||||||
|
const fields: FormFieldConfig[] = [
|
||||||
|
{
|
||||||
|
name: 'model_type',
|
||||||
|
label: t('modelType'),
|
||||||
|
type: FormFieldType.Select,
|
||||||
|
required: true,
|
||||||
|
options: [
|
||||||
|
{ label: 'chat', value: 'chat' },
|
||||||
|
{ label: 'embedding', value: 'embedding' },
|
||||||
|
{ label: 'rerank', value: 'rerank' },
|
||||||
|
],
|
||||||
|
defaultValue: 'chat',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'llm_name',
|
||||||
|
label: t('modelName'),
|
||||||
|
type: FormFieldType.Text,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('yiyanModelNameMessage'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'yiyan_ak',
|
||||||
|
label: t('addyiyanAK'),
|
||||||
|
type: FormFieldType.Text,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('yiyanAKMessage'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'yiyan_sk',
|
||||||
|
label: t('addyiyanSK'),
|
||||||
|
type: FormFieldType.Text,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('yiyanSKMessage'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'max_tokens',
|
||||||
|
label: t('maxTokens'),
|
||||||
|
type: FormFieldType.Number,
|
||||||
|
required: true,
|
||||||
|
placeholder: t('maxTokensTip'),
|
||||||
|
validation: {
|
||||||
|
min: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleOk = async (values?: FieldValues) => {
|
||||||
|
if (!values) return;
|
||||||
|
|
||||||
const handleOk = async () => {
|
|
||||||
const values = await form.validateFields();
|
|
||||||
const modelType =
|
const modelType =
|
||||||
values.model_type === 'chat' && values.vision
|
values.model_type === 'chat' && values.vision
|
||||||
? 'image2text'
|
? 'image2text'
|
||||||
: values.model_type;
|
: values.model_type;
|
||||||
|
|
||||||
const data = {
|
const data: IAddLlmRequestBody = {
|
||||||
...omit(values, ['vision']),
|
|
||||||
model_type: modelType,
|
|
||||||
llm_factory: llmFactory,
|
llm_factory: llmFactory,
|
||||||
max_tokens: values.max_tokens,
|
llm_name: values.llm_name as string,
|
||||||
|
model_type: modelType,
|
||||||
|
api_key: {
|
||||||
|
yiyan_ak: values.yiyan_ak,
|
||||||
|
yiyan_sk: values.yiyan_sk,
|
||||||
|
},
|
||||||
|
max_tokens: values.max_tokens as number,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.info(data);
|
console.info(data);
|
||||||
|
|
||||||
onOk?.(data);
|
await onOk?.(data);
|
||||||
};
|
|
||||||
|
|
||||||
const handleKeyDown = async (e: React.KeyboardEvent) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
await handleOk();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={<LLMHeader name={llmFactory} />}
|
title={<LLMHeader name={llmFactory} />}
|
||||||
open={visible}
|
open={visible || false}
|
||||||
onOk={handleOk}
|
onOpenChange={(open) => !open && hideModal?.()}
|
||||||
onCancel={hideModal}
|
maskClosable={false}
|
||||||
okButtonProps={{ loading }}
|
footer={<div className="p-4"></div>}
|
||||||
confirmLoading={loading}
|
|
||||||
>
|
>
|
||||||
<Form
|
<DynamicForm.Root
|
||||||
name="basic"
|
fields={fields}
|
||||||
style={{ maxWidth: 600 }}
|
onSubmit={(data) => {
|
||||||
autoComplete="off"
|
console.log(data);
|
||||||
layout={'vertical'}
|
}}
|
||||||
form={form}
|
defaultValues={
|
||||||
|
{
|
||||||
|
model_type: 'chat',
|
||||||
|
vision: false,
|
||||||
|
} as FieldValues
|
||||||
|
}
|
||||||
|
labelClassName="font-normal"
|
||||||
>
|
>
|
||||||
<Form.Item<FieldType>
|
<div className="absolute bottom-0 right-0 left-0 flex items-center justify-end w-full gap-2 py-6 px-6">
|
||||||
label={t('modelType')}
|
<DynamicForm.CancelButton
|
||||||
name="model_type"
|
handleCancel={() => {
|
||||||
initialValue={'chat'}
|
hideModal?.();
|
||||||
rules={[{ required: true, message: t('modelTypeMessage') }]}
|
}}
|
||||||
>
|
|
||||||
<Select placeholder={t('modelTypeMessage')}>
|
|
||||||
<Option value="chat">chat</Option>
|
|
||||||
<Option value="embedding">embedding</Option>
|
|
||||||
<Option value="rerank">rerank</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item<FieldType>
|
|
||||||
label={t('modelName')}
|
|
||||||
name="llm_name"
|
|
||||||
rules={[{ required: true, message: t('yiyanModelNameMessage') }]}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={t('yiyanModelNameMessage')}
|
|
||||||
onKeyDown={handleKeyDown}
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
<DynamicForm.SavingButton
|
||||||
<Form.Item<FieldType>
|
submitLoading={loading || false}
|
||||||
label={t('addyiyanAK')}
|
buttonText={tc('ok')}
|
||||||
name="yiyan_ak"
|
submitFunc={(values: FieldValues) => {
|
||||||
rules={[{ required: true, message: t('yiyanAKMessage') }]}
|
handleOk(values);
|
||||||
>
|
}}
|
||||||
<Input placeholder={t('yiyanAKMessage')} onKeyDown={handleKeyDown} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item<FieldType>
|
|
||||||
label={t('addyiyanSK')}
|
|
||||||
name="yiyan_sk"
|
|
||||||
rules={[{ required: true, message: t('yiyanSKMessage') }]}
|
|
||||||
>
|
|
||||||
<Input placeholder={t('yiyanSKMessage')} onKeyDown={handleKeyDown} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item<FieldType>
|
|
||||||
label={t('maxTokens')}
|
|
||||||
name="max_tokens"
|
|
||||||
rules={[
|
|
||||||
{ required: true, message: t('maxTokensMessage') },
|
|
||||||
{
|
|
||||||
type: 'number',
|
|
||||||
message: t('maxTokensInvalidMessage'),
|
|
||||||
},
|
|
||||||
({}) => ({
|
|
||||||
validator(_, value) {
|
|
||||||
if (value < 0) {
|
|
||||||
return Promise.reject(new Error(t('maxTokensMinMessage')));
|
|
||||||
}
|
|
||||||
return Promise.resolve();
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<InputNumber
|
|
||||||
placeholder={t('maxTokensTip')}
|
|
||||||
style={{ width: '100%' }}
|
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</div>
|
||||||
</Form>
|
</DynamicForm.Root>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user