add support for Baidu yiyan (#2049)
### What problem does this PR solve? add support for Baidu yiyan ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
This commit is contained in:
@@ -34,6 +34,7 @@ export const IconMap = {
|
||||
Replicate: 'replicate',
|
||||
'Tencent Hunyuan': 'hunyuan',
|
||||
'XunFei Spark': 'spark',
|
||||
BaiduYiyan: 'yiyan',
|
||||
};
|
||||
|
||||
export const BedrockRegionList = [
|
||||
|
||||
@@ -217,6 +217,33 @@ export const useSubmitSpark = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useSubmityiyan = () => {
|
||||
const { addLlm, loading } = useAddLlm();
|
||||
const {
|
||||
visible: yiyanAddingVisible,
|
||||
hideModal: hideyiyanAddingModal,
|
||||
showModal: showyiyanAddingModal,
|
||||
} = useSetModalState();
|
||||
|
||||
const onyiyanAddingOk = useCallback(
|
||||
async (payload: IAddLlmRequestBody) => {
|
||||
const ret = await addLlm(payload);
|
||||
if (ret === 0) {
|
||||
hideyiyanAddingModal();
|
||||
}
|
||||
},
|
||||
[hideyiyanAddingModal, addLlm],
|
||||
);
|
||||
|
||||
return {
|
||||
yiyanAddingLoading: loading,
|
||||
onyiyanAddingOk,
|
||||
yiyanAddingVisible,
|
||||
hideyiyanAddingModal,
|
||||
showyiyanAddingModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const useSubmitBedrock = () => {
|
||||
const { addLlm, loading } = useAddLlm();
|
||||
const {
|
||||
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
useSubmitSpark,
|
||||
useSubmitSystemModelSetting,
|
||||
useSubmitVolcEngine,
|
||||
useSubmityiyan,
|
||||
} from './hooks';
|
||||
import HunyuanModal from './hunyuan-modal';
|
||||
import styles from './index.less';
|
||||
@@ -46,6 +47,7 @@ import OllamaModal from './ollama-modal';
|
||||
import SparkModal from './spark-modal';
|
||||
import SystemModelSettingModal from './system-model-setting-modal';
|
||||
import VolcEngineModal from './volcengine-modal';
|
||||
import YiyanModal from './yiyan-modal';
|
||||
|
||||
const LlmIcon = ({ name }: { name: string }) => {
|
||||
const icon = IconMap[name as keyof typeof IconMap];
|
||||
@@ -95,7 +97,8 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => {
|
||||
{isLocalLlmFactory(item.name) ||
|
||||
item.name === 'VolcEngine' ||
|
||||
item.name === 'Tencent Hunyuan' ||
|
||||
item.name === 'XunFei Spark'
|
||||
item.name === 'XunFei Spark' ||
|
||||
item.name === 'BaiduYiyan'
|
||||
? t('addTheModel')
|
||||
: 'API-Key'}
|
||||
<SettingOutlined />
|
||||
@@ -185,6 +188,14 @@ const UserSettingModel = () => {
|
||||
SparkAddingLoading,
|
||||
} = useSubmitSpark();
|
||||
|
||||
const {
|
||||
yiyanAddingVisible,
|
||||
hideyiyanAddingModal,
|
||||
showyiyanAddingModal,
|
||||
onyiyanAddingOk,
|
||||
yiyanAddingLoading,
|
||||
} = useSubmityiyan();
|
||||
|
||||
const {
|
||||
bedrockAddingLoading,
|
||||
onBedrockAddingOk,
|
||||
@@ -199,12 +210,14 @@ const UserSettingModel = () => {
|
||||
VolcEngine: showVolcAddingModal,
|
||||
'Tencent Hunyuan': showHunyuanAddingModal,
|
||||
'XunFei Spark': showSparkAddingModal,
|
||||
BaiduYiyan: showyiyanAddingModal,
|
||||
}),
|
||||
[
|
||||
showBedrockAddingModal,
|
||||
showVolcAddingModal,
|
||||
showHunyuanAddingModal,
|
||||
showSparkAddingModal,
|
||||
showyiyanAddingModal,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -330,6 +343,13 @@ const UserSettingModel = () => {
|
||||
loading={SparkAddingLoading}
|
||||
llmFactory={'XunFei Spark'}
|
||||
></SparkModal>
|
||||
<YiyanModal
|
||||
visible={yiyanAddingVisible}
|
||||
hideModal={hideyiyanAddingModal}
|
||||
onOk={onyiyanAddingOk}
|
||||
loading={yiyanAddingLoading}
|
||||
llmFactory={'BaiduYiyan'}
|
||||
></YiyanModal>
|
||||
<BedrockModal
|
||||
visible={bedrockAddingVisible}
|
||||
hideModal={hideBedrockAddingModal}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { IModalProps } from '@/interfaces/common';
|
||||
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
||||
import { Form, Input, Modal, Select } from 'antd';
|
||||
import omit from 'lodash/omit';
|
||||
|
||||
type FieldType = IAddLlmRequestBody & {
|
||||
vision: boolean;
|
||||
yiyan_ak: string;
|
||||
yiyan_sk: string;
|
||||
};
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
const YiyanModal = ({
|
||||
visible,
|
||||
hideModal,
|
||||
onOk,
|
||||
loading,
|
||||
llmFactory,
|
||||
}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => {
|
||||
const [form] = Form.useForm<FieldType>();
|
||||
|
||||
const { t } = useTranslate('setting');
|
||||
|
||||
const handleOk = async () => {
|
||||
const values = await form.validateFields();
|
||||
const modelType =
|
||||
values.model_type === 'chat' && values.vision
|
||||
? 'image2text'
|
||||
: values.model_type;
|
||||
|
||||
const data = {
|
||||
...omit(values, ['vision']),
|
||||
model_type: modelType,
|
||||
llm_factory: llmFactory,
|
||||
};
|
||||
console.info(data);
|
||||
|
||||
onOk?.(data);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t('addLlmTitle', { name: llmFactory })}
|
||||
open={visible}
|
||||
onOk={handleOk}
|
||||
onCancel={hideModal}
|
||||
okButtonProps={{ loading }}
|
||||
confirmLoading={loading}
|
||||
>
|
||||
<Form
|
||||
name="basic"
|
||||
style={{ maxWidth: 600 }}
|
||||
autoComplete="off"
|
||||
layout={'vertical'}
|
||||
form={form}
|
||||
>
|
||||
<Form.Item<FieldType>
|
||||
label={t('modelType')}
|
||||
name="model_type"
|
||||
initialValue={'chat'}
|
||||
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')} />
|
||||
</Form.Item>
|
||||
<Form.Item<FieldType>
|
||||
label={t('addyiyanAK')}
|
||||
name="yiyan_ak"
|
||||
rules={[{ required: true, message: t('yiyanAKMessage') }]}
|
||||
>
|
||||
<Input placeholder={t('yiyanAKMessage')} />
|
||||
</Form.Item>
|
||||
<Form.Item<FieldType>
|
||||
label={t('addyiyanSK')}
|
||||
name="yiyan_sk"
|
||||
rules={[{ required: true, message: t('yiyanSKMessage') }]}
|
||||
>
|
||||
<Input placeholder={t('yiyanSKMessage')} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default YiyanModal;
|
||||
Reference in New Issue
Block a user