mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 01:25:52 +08:00
add support for XunFei Spark (#2017)
### What problem does this PR solve? #1853 add support for XunFei Spark ### 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:
parent
02985fc905
commit
be431449bd
@ -138,6 +138,9 @@ def add_llm():
|
||||
elif factory == "OpenAI-API-Compatible":
|
||||
llm_name = req["llm_name"]+"___OpenAI-API"
|
||||
api_key = req.get("api_key","xxxxxxxxxxxxxxx")
|
||||
elif factory =="XunFei Spark":
|
||||
llm_name = req["llm_name"]
|
||||
api_key = req.get("spark_api_password","")
|
||||
else:
|
||||
llm_name = req["llm_name"]
|
||||
api_key = req.get("api_key","xxxxxxxxxxxxxxx")
|
||||
@ -165,7 +168,7 @@ def add_llm():
|
||||
msg += f"\nFail to access embedding model({llm['llm_name']})." + str(e)
|
||||
elif llm["model_type"] == LLMType.CHAT.value:
|
||||
mdl = ChatModel[factory](
|
||||
key=llm['api_key'] if factory in ["VolcEngine", "Bedrock","OpenAI-API-Compatible","Replicate"] else None,
|
||||
key=llm['api_key'] if factory in ["VolcEngine", "Bedrock","OpenAI-API-Compatible","Replicate","XunFei Spark"] else None,
|
||||
model_name=llm["llm_name"],
|
||||
base_url=llm["api_base"]
|
||||
)
|
||||
|
@ -3194,6 +3194,13 @@
|
||||
"model_type": "image2text"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "XunFei Spark",
|
||||
"logo": "",
|
||||
"tags": "LLM",
|
||||
"status": "1",
|
||||
"llm": []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -100,7 +100,8 @@ ChatModel = {
|
||||
"SILICONFLOW": SILICONFLOWChat,
|
||||
"01.AI": YiChat,
|
||||
"Replicate": ReplicateChat,
|
||||
"Tencent Hunyuan": HunyuanChat
|
||||
"Tencent Hunyuan": HunyuanChat,
|
||||
"XunFei Spark": SparkChat
|
||||
}
|
||||
|
||||
|
||||
|
@ -1133,12 +1133,12 @@ class HunyuanChat(Base):
|
||||
from tencentcloud.common.exception.tencent_cloud_sdk_exception import (
|
||||
TencentCloudSDKException,
|
||||
)
|
||||
|
||||
|
||||
_gen_conf = {}
|
||||
_history = [{k.capitalize(): v for k, v in item.items() } for item in history]
|
||||
if system:
|
||||
_history.insert(0, {"Role": "system", "Content": system})
|
||||
|
||||
|
||||
if "temperature" in gen_conf:
|
||||
_gen_conf["Temperature"] = gen_conf["temperature"]
|
||||
if "top_p" in gen_conf:
|
||||
@ -1168,3 +1168,20 @@ class HunyuanChat(Base):
|
||||
yield ans + "\n**ERROR**: " + str(e)
|
||||
|
||||
yield total_tokens
|
||||
|
||||
|
||||
class SparkChat(Base):
|
||||
def __init__(
|
||||
self, key, model_name, base_url="https://spark-api-open.xf-yun.com/v1"
|
||||
):
|
||||
if not base_url:
|
||||
base_url = "https://spark-api-open.xf-yun.com/v1"
|
||||
model2version = {
|
||||
"Spark-Max": "generalv3.5",
|
||||
"Spark-Lite": "general",
|
||||
"Spark-Pro": "generalv3",
|
||||
"Spark-Pro-128K": "pro-128k",
|
||||
"Spark-4.0-Ultra": "4.0Ultra",
|
||||
}
|
||||
model_version = model2version[model_name]
|
||||
super().__init__(key, model_version, base_url)
|
||||
|
1
web/src/assets/svg/llm/spark.svg
Normal file
1
web/src/assets/svg/llm/spark.svg
Normal 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="1724133188868" class="icon" viewBox="0 0 1090 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4224" xmlns:xlink="http://www.w3.org/1999/xlink" width="212.890625" height="200"><path d="M830.55997787 864.25249396c-20.71261235 29.13574137-47.5009243 51.91961495-76.08432934 72.49414321-84.23129021 60.75699621-178.81888658 85.47404695-281.829612 77.32708608-167.49599184-13.11798782-320.35507095-139.05067088-363.71347278-302.12797207-43.49648592-163.21538528-5.5233633-306.27049455 114.05745198-426.40364615 58.96190314-59.23807131 119.02847895-117.23338587 178.68080251-175.78103678 3.0378498-3.0378498 5.5233633-7.04228819 11.32289474-8.69929719 2.62359757 7.59462453-1.10467265 14.7749968-1.93317714 21.67920093-9.66588576 84.78362653 15.46541722 160.59178771 59.37615539 231.42892193 31.75933893 51.36727861 71.25138647 96.52077353 118.06189037 134.217728 57.85723049 46.67241982 64.20909827 123.03291733 30.51658219 175.50486861-38.66354305 60.20465988-121.23782427 77.60325425-180.06164333 37.00653406-3.0378498-2.07126124-7.45654045-3.31401797-8.28504493-9.25163351 8.00887677 0.27616816 15.74158539 2.62359757 23.47429398 0.82850449 18.50326702-4.41869063 31.2070026-15.46541722 36.03994549-33.96868425 4.83294288-18.64135111-0.8285045-34.65910465-15.60350131-46.67241982-42.66798143-34.79718875-82.57428122-72.4941432-115.4382928-117.09530178-12.42756741-16.84625804-23.61237808-34.65910465-34.65910466-54.12896027-16.57008987 18.64135111-27.89298463 39.0777953-36.45419772 60.8950803-42.9441496 109.63876134-6.76612003 225.76747457 90.99741024 294.25717939 7.18037229 4.97102697 14.7749968 9.52780169 21.26494867 15.46541723 1.51892491 1.51892491 2.89976573 3.31401797 4.69485879 4.5567747 56.20022149 37.69695447 116.81913363 64.62335052 184.06608171 75.11774078 47.77709247 7.45654045 95.69226903 8.14696086 143.88361378 3.45210205 34.93527282-3.31401797 67.24694809-13.2560719 97.62544617-30.10232994z" fill="#3EC7F8" p-id="4225"></path><path d="M513.93317715 5.78375427c61.44741663 60.34274397 122.06632875 119.85698343 182.54715681 179.23313883 36.31611363 35.62569324 72.90839547 71.25138647 108.94834094 107.15324788 66.41844358 66.14227541 105.77240705 146.09295908 120.27123568 238.47121013 0.55233633 3.59018613 0.8285045 7.04228819 0.96658859 10.63247434 0 1.10467265-0.55233633 2.20934532-0.8285045 3.31401796-3.31401797 0.27616816-4.00443838-2.20934532-4.83294288-4.14252246-22.92195766-47.36284023-60.8950803-77.05091792-109.63876136-94.3114282-25.68363931-9.11354943-52.47195126-14.36074457-78.7079269-21.40303276-65.72802318-17.39859437-124.96609449-45.98199941-168.18641227-100.663296-35.07335691-44.46307451-53.8527921-95.1399327-53.57662391-152.3067428 0.27616816-50.53877413 0-100.93946416 0.13808406-151.47823828-0.13808409-4.28060655-2.20934532-9.52780169 2.89976574-14.49882864z" fill="#E90302" p-id="4226"></path><path d="M830.55997787 864.25249396c-30.3784981 16.84625804-62.69017337 26.65022788-97.34927802 30.10232994-48.19134474 4.69485881-96.10652128 4.00443838-143.88361377-3.45210205-67.24694809-10.49439025-127.86586021-37.42078631-184.0660817-75.11774078-1.79509307-1.24275675-3.1759339-3.0378498-4.6948588-4.5567747 5.3852792-1.79509307 9.3897176 1.79509307 13.80840822 3.72827022 151.06398604 65.86610725 321.73591177-36.03994548 335.6824041-200.36000344 3.72827022-43.35840185-3.45210207-84.50745837-21.40303276-123.86142183-1.10467265-2.48551348-2.20934532-4.83294288-3.17593389-7.31845635-0.27616816-0.69042042 0.13808409-1.65700898 0.13808407-2.62359757 3.86635431-3.31401797 7.7327086-0.41425225 11.32289476 0.41425223 46.67241982 10.21822208 88.64998083 30.10232993 124.41375815 61.99975297 48.3294288 43.22031776 67.9373685 97.34927803 53.16237168 160.59178771-13.80840823 60.06657581-41.97756103 114.19553606-83.95512204 160.45370365z" fill="#1753D7" p-id="4227"></path></svg>
|
After Width: | Height: | Size: 3.9 KiB |
@ -525,6 +525,9 @@ The above is the content you need to summarize.`,
|
||||
HunyuanSIDMessage: 'Please input your Secret ID',
|
||||
addHunyuanSK: 'Hunyuan Secret Key',
|
||||
HunyuanSKMessage: 'Please input your Secret Key',
|
||||
SparkModelNameMessage: 'Please select Spark model',
|
||||
addSparkAPIPassword: 'Spark APIPassword',
|
||||
SparkAPIPasswordMessage: 'please input your APIPassword',
|
||||
},
|
||||
message: {
|
||||
registered: 'Registered!',
|
||||
|
@ -488,6 +488,9 @@ export default {
|
||||
HunyuanSIDMessage: '請輸入 Secret ID',
|
||||
addHunyuanSK: '混元 Secret Key',
|
||||
HunyuanSKMessage: '請輸入 Secret Key',
|
||||
SparkModelNameMessage: '請選擇星火模型!',
|
||||
addSparkAPIPassword: '星火 APIPassword',
|
||||
SparkAPIPasswordMessage: '請輸入 APIPassword',
|
||||
},
|
||||
message: {
|
||||
registered: '註冊成功',
|
||||
|
@ -505,6 +505,9 @@ export default {
|
||||
HunyuanSIDMessage: '请输入 Secret ID',
|
||||
addHunyuanSK: '混元 Secret Key',
|
||||
HunyuanSKMessage: '请输入 Secret Key',
|
||||
SparkModelNameMessage: '请选择星火模型!',
|
||||
addSparkAPIPassword: '星火 APIPassword',
|
||||
SparkAPIPasswordMessage: '请输入 APIPassword',
|
||||
},
|
||||
message: {
|
||||
registered: '注册成功',
|
||||
|
@ -33,6 +33,7 @@ export const IconMap = {
|
||||
'01.AI': 'yi',
|
||||
Replicate: 'replicate',
|
||||
'Tencent Hunyuan': 'hunyuan',
|
||||
'XunFei Spark': 'spark',
|
||||
};
|
||||
|
||||
export const BedrockRegionList = [
|
||||
|
@ -190,6 +190,33 @@ export const useSubmitHunyuan = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useSubmitSpark = () => {
|
||||
const { addLlm, loading } = useAddLlm();
|
||||
const {
|
||||
visible: SparkAddingVisible,
|
||||
hideModal: hideSparkAddingModal,
|
||||
showModal: showSparkAddingModal,
|
||||
} = useSetModalState();
|
||||
|
||||
const onSparkAddingOk = useCallback(
|
||||
async (payload: IAddLlmRequestBody) => {
|
||||
const ret = await addLlm(payload);
|
||||
if (ret === 0) {
|
||||
hideSparkAddingModal();
|
||||
}
|
||||
},
|
||||
[hideSparkAddingModal, addLlm],
|
||||
);
|
||||
|
||||
return {
|
||||
SparkAddingLoading: loading,
|
||||
onSparkAddingOk,
|
||||
SparkAddingVisible,
|
||||
hideSparkAddingModal,
|
||||
showSparkAddingModal,
|
||||
};
|
||||
};
|
||||
|
||||
export const useSubmitBedrock = () => {
|
||||
const { addLlm, loading } = useAddLlm();
|
||||
const {
|
||||
|
@ -36,12 +36,14 @@ import {
|
||||
useSubmitBedrock,
|
||||
useSubmitHunyuan,
|
||||
useSubmitOllama,
|
||||
useSubmitSpark,
|
||||
useSubmitSystemModelSetting,
|
||||
useSubmitVolcEngine,
|
||||
} from './hooks';
|
||||
import HunyuanModal from './hunyuan-modal';
|
||||
import styles from './index.less';
|
||||
import OllamaModal from './ollama-modal';
|
||||
import SparkModal from './spark-modal';
|
||||
import SystemModelSettingModal from './system-model-setting-modal';
|
||||
import VolcEngineModal from './volcengine-modal';
|
||||
|
||||
@ -92,7 +94,8 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => {
|
||||
<Button onClick={handleApiKeyClick}>
|
||||
{isLocalLlmFactory(item.name) ||
|
||||
item.name === 'VolcEngine' ||
|
||||
item.name === 'Tencent Hunyuan'
|
||||
item.name === 'Tencent Hunyuan' ||
|
||||
item.name === 'XunFei Spark'
|
||||
? t('addTheModel')
|
||||
: 'API-Key'}
|
||||
<SettingOutlined />
|
||||
@ -174,6 +177,14 @@ const UserSettingModel = () => {
|
||||
HunyuanAddingLoading,
|
||||
} = useSubmitHunyuan();
|
||||
|
||||
const {
|
||||
SparkAddingVisible,
|
||||
hideSparkAddingModal,
|
||||
showSparkAddingModal,
|
||||
onSparkAddingOk,
|
||||
SparkAddingLoading,
|
||||
} = useSubmitSpark();
|
||||
|
||||
const {
|
||||
bedrockAddingLoading,
|
||||
onBedrockAddingOk,
|
||||
@ -187,8 +198,14 @@ const UserSettingModel = () => {
|
||||
Bedrock: showBedrockAddingModal,
|
||||
VolcEngine: showVolcAddingModal,
|
||||
'Tencent Hunyuan': showHunyuanAddingModal,
|
||||
'XunFei Spark': showSparkAddingModal,
|
||||
}),
|
||||
[showBedrockAddingModal, showVolcAddingModal, showHunyuanAddingModal],
|
||||
[
|
||||
showBedrockAddingModal,
|
||||
showVolcAddingModal,
|
||||
showHunyuanAddingModal,
|
||||
showSparkAddingModal,
|
||||
],
|
||||
);
|
||||
|
||||
const handleAddModel = useCallback(
|
||||
@ -306,6 +323,13 @@ const UserSettingModel = () => {
|
||||
loading={HunyuanAddingLoading}
|
||||
llmFactory={'Tencent Hunyuan'}
|
||||
></HunyuanModal>
|
||||
<SparkModal
|
||||
visible={SparkAddingVisible}
|
||||
hideModal={hideSparkAddingModal}
|
||||
onOk={onSparkAddingOk}
|
||||
loading={SparkAddingLoading}
|
||||
llmFactory={'XunFei Spark'}
|
||||
></SparkModal>
|
||||
<BedrockModal
|
||||
visible={bedrockAddingVisible}
|
||||
hideModal={hideBedrockAddingModal}
|
||||
|
@ -0,0 +1,94 @@
|
||||
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;
|
||||
spark_api_password: string;
|
||||
};
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
const SparkModal = ({
|
||||
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>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item<FieldType>
|
||||
label={t('modelName')}
|
||||
name="llm_name"
|
||||
initialValue={'Spark-Max'}
|
||||
rules={[{ required: true, message: t('SparkModelNameMessage') }]}
|
||||
>
|
||||
<Select placeholder={t('modelTypeMessage')}>
|
||||
<Option value="Spark-Max">Spark-Max</Option>
|
||||
<Option value="Spark-Lite">Spark-Lite</Option>
|
||||
<Option value="Spark-Pro">Spark-Pro</Option>
|
||||
<Option value="Spark-Pro-128K">Spark-Pro-128K</Option>
|
||||
<Option value="Spark-4.0-Ultra">Spark-4.0-Ultra</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item<FieldType>
|
||||
label={t('addSparkAPIPassword')}
|
||||
name="spark_api_password"
|
||||
rules={[{ required: true, message: t('SparkPasswordMessage') }]}
|
||||
>
|
||||
<Input placeholder={t('SparkSIDMessage')} />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SparkModal;
|
Loading…
x
Reference in New Issue
Block a user