add support for Tencent Hunyuan (#2015)

### What problem does this PR solve?

#1853 

### 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:
黄腾
2024-08-20 15:27:13 +08:00
committed by GitHub
parent 5efb3476f2
commit 6f438e0a49
15 changed files with 327 additions and 9 deletions

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1724045693347" class="icon" viewBox="0 0 1032 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4302" xmlns:xlink="http://www.w3.org/1999/xlink" width="201.5625" height="200"><path d="M3.796984 0h1018.143079v1018.143079h-1018.143079z" fill="#CCCCCC" fill-opacity="0" p-id="4303"></path><path d="M448.476277 1016.17573l-13.151015-498.465883c-26.514143-9.720085 80.597691-135.736502 124.563442-124.61647 128.917065-32.400282 269.060217-237.58793 13.204043-389.757898-774.159938 0-689.33059 951.857722-124.61647 1012.840251z" fill="#B3DDF2" p-id="4304"></path><path d="M446.021067 1015.942405c-230.673041-53.028285-456.425058-375.800853-180.29617-665.504981 63.421829-55.902418-63.262744-220.942351-167.039099-129.919299-275.725873 381.3264 86.908057 796.458332 347.335269 795.42428z" fill="#0055E9" p-id="4305"></path><path d="M408.827028 536.27505c0-2.651414-6.363394 4.576341 0 0z m0 0v39.771214c0 5.302829-7.42396 40.566638-10.605657 55.679699l39.771214 84.845257s26.514143 7.954243 29.165557 10.605657 15.643344 4.507404 21.211314 5.302829l55.6797 34.468385 92.799499-13.257071 119.313642-37.1198 111.359399-95.450914 34.468386-58.331113 29.165557-148.479199-5.302829-68.936771v-60.982529l-60.982528-111.359399-31.816971-39.771214-55.6797-50.376871-47.725457-29.165557-13.257071-7.954243-15.908486-5.302828-29.165557-10.605657-92.799499-23.862729c201.507484 66.285357 217.41597 270.444255 159.084856 368.546583s-184.713426 154.736537-307.564055 143.176371l-21.211314 18.5599z" fill="#00BCFF" p-id="4306"></path><path d="M461.828799 1016.207546c180.29617 47.698943 575.192508-124.425569 570.054068-493.163053 13.267677-164.414199-140.196181-491.471452-389.757898-503.768711 278.218202 56.660723 384.508097 567.720823 23.915757 694.670538-180.338593 45.074043-246.608041-92.799499-233.324456-190.901827-185.535365 9.375401-283.955862 407.209506 29.112529 493.163053z" fill="#0055DF" p-id="4307"></path></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -521,6 +521,10 @@ The above is the content you need to summarize.`,
'eu-central-1': 'Europe (Frankfurt)',
'us-gov-west-1': 'AWS GovCloud (US-West)',
'ap-southeast-2': 'Asia Pacific (Sydney)',
addHunyuanSID: 'Hunyuan Secret ID',
HunyuanSIDMessage: 'Please input your Secret ID',
addHunyuanSK: 'Hunyuan Secret Key',
HunyuanSKMessage: 'Please input your Secret Key',
},
message: {
registered: 'Registered!',

View File

@ -484,6 +484,10 @@ export default {
'eu-central-1': '歐洲 (法蘭克福)',
'us-gov-west-1': 'AWS GovCloud (US-West)',
'ap-southeast-2': '亞太地區 (雪梨)',
addHunyuanSID: '混元 Secret ID',
HunyuanSIDMessage: '請輸入 Secret ID',
addHunyuanSK: '混元 Secret Key',
HunyuanSKMessage: '請輸入 Secret Key',
},
message: {
registered: '註冊成功',

View File

@ -501,6 +501,10 @@ export default {
'eu-central-1': '欧洲 (法兰克福)',
'us-gov-west-1': 'AWS GovCloud (US-West)',
'ap-southeast-2': '亚太地区 (悉尼)',
addHunyuanSID: '混元 Secret ID',
HunyuanSIDMessage: '请输入 Secret ID',
addHunyuanSK: '混元 Secret Key',
HunyuanSKMessage: '请输入 Secret Key',
},
message: {
registered: '注册成功',

View File

@ -30,8 +30,9 @@ export const IconMap = {
Upstage: 'upstage',
'novita.ai': 'novita-ai',
SILICONFLOW: 'siliconflow',
"01.AI": 'yi',
"Replicate": 'replicate'
'01.AI': 'yi',
Replicate: 'replicate',
'Tencent Hunyuan': 'hunyuan',
};
export const BedrockRegionList = [

View File

@ -163,6 +163,33 @@ export const useSubmitVolcEngine = () => {
};
};
export const useSubmitHunyuan = () => {
const { addLlm, loading } = useAddLlm();
const {
visible: HunyuanAddingVisible,
hideModal: hideHunyuanAddingModal,
showModal: showHunyuanAddingModal,
} = useSetModalState();
const onHunyuanAddingOk = useCallback(
async (payload: IAddLlmRequestBody) => {
const ret = await addLlm(payload);
if (ret === 0) {
hideHunyuanAddingModal();
}
},
[hideHunyuanAddingModal, addLlm],
);
return {
HunyuanAddingLoading: loading,
onHunyuanAddingOk,
HunyuanAddingVisible,
hideHunyuanAddingModal,
showHunyuanAddingModal,
};
};
export const useSubmitBedrock = () => {
const { addLlm, loading } = useAddLlm();
const {

View File

@ -0,0 +1,78 @@
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;
hunyuan_sid: string;
hunyuan_sk: string;
};
const { Option } = Select;
const HunyuanModal = ({
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('addHunyuanSID')}
name="hunyuan_sid"
rules={[{ required: true, message: t('HunyuanSIDMessage') }]}
>
<Input placeholder={t('HunyuanSIDMessage')} />
</Form.Item>
<Form.Item<FieldType>
label={t('addHunyuanSK')}
name="hunyuan_sk"
rules={[{ required: true, message: t('HunyuanSKMessage') }]}
>
<Input placeholder={t('HunyuanSKMessage')} />
</Form.Item>
</Form>
</Modal>
);
};
export default HunyuanModal;

View File

@ -34,10 +34,12 @@ import {
useHandleDeleteLlm,
useSubmitApiKey,
useSubmitBedrock,
useSubmitHunyuan,
useSubmitOllama,
useSubmitSystemModelSetting,
useSubmitVolcEngine,
} from './hooks';
import HunyuanModal from './hunyuan-modal';
import styles from './index.less';
import OllamaModal from './ollama-modal';
import SystemModelSettingModal from './system-model-setting-modal';
@ -88,7 +90,9 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => {
<Col span={12} className={styles.factoryOperationWrapper}>
<Space size={'middle'}>
<Button onClick={handleApiKeyClick}>
{isLocalLlmFactory(item.name) || item.name === 'VolcEngine'
{isLocalLlmFactory(item.name) ||
item.name === 'VolcEngine' ||
item.name === 'Tencent Hunyuan'
? t('addTheModel')
: 'API-Key'}
<SettingOutlined />
@ -162,6 +166,14 @@ const UserSettingModel = () => {
volcAddingLoading,
} = useSubmitVolcEngine();
const {
HunyuanAddingVisible,
hideHunyuanAddingModal,
showHunyuanAddingModal,
onHunyuanAddingOk,
HunyuanAddingLoading,
} = useSubmitHunyuan();
const {
bedrockAddingLoading,
onBedrockAddingOk,
@ -174,8 +186,9 @@ const UserSettingModel = () => {
() => ({
Bedrock: showBedrockAddingModal,
VolcEngine: showVolcAddingModal,
'Tencent Hunyuan': showHunyuanAddingModal,
}),
[showBedrockAddingModal, showVolcAddingModal],
[showBedrockAddingModal, showVolcAddingModal, showHunyuanAddingModal],
);
const handleAddModel = useCallback(
@ -286,6 +299,13 @@ const UserSettingModel = () => {
loading={volcAddingLoading}
llmFactory={'VolcEngine'}
></VolcEngineModal>
<HunyuanModal
visible={HunyuanAddingVisible}
hideModal={hideHunyuanAddingModal}
onOk={onHunyuanAddingOk}
loading={HunyuanAddingLoading}
llmFactory={'Tencent Hunyuan'}
></HunyuanModal>
<BedrockModal
visible={bedrockAddingVisible}
hideModal={hideBedrockAddingModal}