Skip to content

Commit

Permalink
✨ feat: add Hunyuan(Tencent) model provider (lobehub#4147)
Browse files Browse the repository at this point in the history
* ✨ feat: add Hunyuan(Tencent) model provider

* 💄 style: add `HUNYUAN_MODEL_LIST` support

* 💄 style: update model price & provider description

* 💄 style: enable `hunyuan-standard-256K` as default, sort model provider list

* 💄 style: update model tokens info

* 💄 style: update pricing

* 💄 style: update `hunyuan-turbo` model info
  • Loading branch information
hezhijie0327 authored Sep 27, 2024
1 parent ac8de6b commit 8ddb41b
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ ENV \
GOOGLE_API_KEY="" GOOGLE_PROXY_URL="" \
# Groq
GROQ_API_KEY="" GROQ_MODEL_LIST="" GROQ_PROXY_URL="" \
# Hunyuan
HUNYUAN_API_KEY="" HUNYUAN_MODEL_LIST="" \
# Minimax
MINIMAX_API_KEY="" \
# Mistral
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.database
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ ENV \
GOOGLE_API_KEY="" GOOGLE_PROXY_URL="" \
# Groq
GROQ_API_KEY="" GROQ_MODEL_LIST="" GROQ_PROXY_URL="" \
# Hunyuan
HUNYUAN_API_KEY="" HUNYUAN_MODEL_LIST="" \
# Minimax
MINIMAX_API_KEY="" \
# Mistral
Expand Down
2 changes: 2 additions & 0 deletions src/app/(main)/settings/llm/ProviderList/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FireworksAIProviderCard,
GoogleProviderCard,
GroqProviderCard,
HunyuanProviderCard,
MinimaxProviderCard,
MistralProviderCard,
MoonshotProviderCard,
Expand Down Expand Up @@ -60,6 +61,7 @@ export const useProviderList = (): ProviderItem[] => {
Ai21ProviderCard,
UpstageProviderCard,
QwenProviderCard,
HunyuanProviderCard,
SparkProviderCard,
ZhiPuProviderCard,
ZeroOneProviderCard,
Expand Down
7 changes: 7 additions & 0 deletions src/app/api/chat/agentRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ const getLlmOptionsFromPayload = (provider: string, payload: JWTPayload) => {

const apiKey = apiKeyManager.pick(payload?.apiKey || AI21_API_KEY);

return { apiKey };
}
case ModelProvider.Hunyuan: {
const { HUNYUAN_API_KEY } = getLLMConfig();

const apiKey = apiKeyManager.pick(payload?.apiKey || HUNYUAN_API_KEY);

return { apiKey };
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/config/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export const getLLMConfig = () => {

ENABLED_AI21: z.boolean(),
AI21_API_KEY: z.string().optional(),

ENABLED_HUNYUAN: z.boolean(),
HUNYUAN_API_KEY: z.string().optional(),
HUNYUAN_MODEL_LIST: z.string().optional(),
},
runtimeEnv: {
API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE,
Expand Down Expand Up @@ -231,6 +235,10 @@ export const getLLMConfig = () => {

ENABLED_AI21: !!process.env.AI21_API_KEY,
AI21_API_KEY: process.env.AI21_API_KEY,

ENABLED_HUNYUAN: !!process.env.HUNYUAN_API_KEY,
HUNYUAN_API_KEY: process.env.HUNYUAN_API_KEY,
HUNYUAN_MODEL_LIST: process.env.HUNYUAN_MODEL_LIST,
},
});
};
Expand Down
137 changes: 137 additions & 0 deletions src/config/modelProviders/hunyuan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { ModelProviderCard } from '@/types/llm';

// ref https://cloud.tencent.com/document/product/1729/104753
const Hunyuan: ModelProviderCard = {
chatModels: [
{
description: '升级为 MOE 结构,上下文窗口为 256k ,在 NLP,代码,数学,行业等多项评测集上领先众多开源模型。',
displayName: 'Hunyuan Lite',
enabled: true,
id: 'hunyuan-lite',
maxOutput: 6000,
pricing: {
currency: 'CNY',
input: 0,
output: 0,
},
tokens: 256_000,
},
{
description: '采用更优的路由策略,同时缓解了负载均衡和专家趋同的问题。长文方面,大海捞针指标达到99.9%。MOE-32K 性价比相对更高,在平衡效果、价格的同时,可对实现对长文本输入的处理。',
displayName: 'Hunyuan Standard',
enabled: true,
id: 'hunyuan-standard',
maxOutput: 2000,
pricing: {
currency: 'CNY',
input: 4.5,
output: 5,
},
tokens: 32_000,
},
{
description: '采用更优的路由策略,同时缓解了负载均衡和专家趋同的问题。长文方面,大海捞针指标达到99.9%。MOE-256K 在长度和效果上进一步突破,极大的扩展了可输入长度。',
displayName: 'Hunyuan Standard 256K',
enabled: true,
id: 'hunyuan-standard-256K',
maxOutput: 6000,
pricing: {
currency: 'CNY',
input: 15,
output: 60,
},
tokens: 256_000,
},
{
description: '混元全新一代大语言模型的预览版,采用全新的混合专家模型(MoE)结构,相比hunyuan-pro推理效率更快,效果表现更强。',
displayName: 'Hunyuan Turbo',
enabled: true,
functionCall: true,
id: 'hunyuan-turbo',
maxOutput: 4000,
pricing: {
currency: 'CNY',
input: 15,
output: 50,
},
tokens: 32_000,
},
{
description: '万亿级参数规模 MOE-32K 长文模型。在各种 benchmark 上达到绝对领先的水平,复杂指令和推理,具备复杂数学能力,支持 functioncall,在多语言翻译、金融法律医疗等领域应用重点优化。',
displayName: 'Hunyuan Pro',
enabled: true,
functionCall: true,
id: 'hunyuan-pro',
maxOutput: 4000,
pricing: {
currency: 'CNY',
input: 30,
output: 100,
},
tokens: 32_000,
},
{
description: '混元最新代码生成模型,经过 200B 高质量代码数据增训基座模型,迭代半年高质量 SFT 数据训练,上下文长窗口长度增大到 8K,五大语言代码生成自动评测指标上位居前列;五大语言10项考量各方面综合代码任务人工高质量评测上,性能处于第一梯队',
displayName: 'Hunyuan Code',
enabled: true,
id: 'hunyuan-code',
maxOutput: 4000,
pricing: {
currency: 'CNY',
input: 4,
output: 8,
},
tokens: 8000,
},
{
description: '混元最新多模态模型,支持图片+文本输入生成文本内容。',
displayName: 'Hunyuan Vision',
enabled: true,
id: 'hunyuan-vision',
maxOutput: 4000,
pricing: {
currency: 'CNY',
input: 18,
output: 18,
},
tokens: 8000,
vision: true,
},
{
description: '混元最新 MOE 架构 FunctionCall 模型,经过高质量的 FunctionCall 数据训练,上下文窗口达 32K,在多个维度的评测指标上处于领先。',
displayName: 'Hunyuan FunctionCall',
functionCall: true,
id: 'hunyuan-functioncall',
maxOutput: 4000,
pricing: {
currency: 'CNY',
input: 4,
output: 8,
},
tokens: 32_000,
},
{
description: '混元最新版角色扮演模型,混元官方精调训练推出的角色扮演模型,基于混元模型结合角色扮演场景数据集进行增训,在角色扮演场景具有更好的基础效果。',
displayName: 'Hunyuan Role',
id: 'hunyuan-role',
maxOutput: 4000,
pricing: {
currency: 'CNY',
input: 4,
output: 8,
},
tokens: 8000,
},
],
checkModel: 'hunyuan-lite',
description:
'由腾讯研发的大语言模型,具备强大的中文创作能力,复杂语境下的逻辑推理能力,以及可靠的任务执行能力',
disableBrowserRequest: true,
id: 'hunyuan',
modelList: { showModelFetcher: true },
modelsUrl: 'https://cloud.tencent.com/document/product/1729/104753',
name: 'Hunyuan',
url: 'https://hunyuan.tencent.com',
};

export default Hunyuan;
4 changes: 4 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import FireworksAIProvider from './fireworksai';
import GithubProvider from './github';
import GoogleProvider from './google';
import GroqProvider from './groq';
import HunyuanProvider from './hunyuan';
import MinimaxProvider from './minimax';
import MistralProvider from './mistral';
import MoonshotProvider from './moonshot';
Expand Down Expand Up @@ -57,6 +58,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [
UpstageProvider.chatModels,
SparkProvider.chatModels,
Ai21Provider.chatModels,
HunyuanProvider.chatModels,
].flat();

export const DEFAULT_MODEL_PROVIDER_LIST = [
Expand All @@ -78,6 +80,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
Ai21Provider,
UpstageProvider,
QwenProvider,
HunyuanProvider,
SparkProvider,
ZhiPuProvider,
ZeroOneProvider,
Expand Down Expand Up @@ -110,6 +113,7 @@ export { default as FireworksAIProviderCard } from './fireworksai';
export { default as GithubProviderCard } from './github';
export { default as GoogleProviderCard } from './google';
export { default as GroqProviderCard } from './groq';
export { default as HunyuanProviderCard } from './hunyuan';
export { default as MinimaxProviderCard } from './minimax';
export { default as MistralProviderCard } from './mistral';
export { default as MoonshotProviderCard } from './moonshot';
Expand Down
5 changes: 5 additions & 0 deletions src/const/settings/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GithubProviderCard,
GoogleProviderCard,
GroqProviderCard,
HunyuanProviderCard,
MinimaxProviderCard,
MistralProviderCard,
MoonshotProviderCard,
Expand Down Expand Up @@ -75,6 +76,10 @@ export const DEFAULT_LLM_CONFIG: UserModelProviderConfig = {
enabled: false,
enabledModels: filterEnabledModels(GroqProviderCard),
},
hunyuan: {
enabled: false,
enabledModels: filterEnabledModels(HunyuanProviderCard),
},
minimax: {
enabled: false,
enabledModels: filterEnabledModels(MinimaxProviderCard),
Expand Down
7 changes: 7 additions & 0 deletions src/libs/agent-runtime/AgentRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { LobeFireworksAI } from './fireworksai';
import { LobeGithubAI } from './github';
import { LobeGoogleAI } from './google';
import { LobeGroq } from './groq';
import { LobeHunyuanAI } from './hunyuan';
import { LobeMinimaxAI } from './minimax';
import { LobeMistralAI } from './mistral';
import { LobeMoonshotAI } from './moonshot';
Expand Down Expand Up @@ -133,6 +134,7 @@ class AgentRuntime {
github: Partial<ClientOptions>;
google: { apiKey?: string; baseURL?: string };
groq: Partial<ClientOptions>;
hunyuan: Partial<ClientOptions>;
minimax: Partial<ClientOptions>;
mistral: Partial<ClientOptions>;
moonshot: Partial<ClientOptions>;
Expand Down Expand Up @@ -300,6 +302,11 @@ class AgentRuntime {
runtimeModel = new LobeAi21AI(params.ai21);
break;
}

case ModelProvider.Hunyuan: {
runtimeModel = new LobeHunyuanAI(params.hunyuan);
break;
}
}

return new AgentRuntime(runtimeModel);
Expand Down
Loading

0 comments on commit 8ddb41b

Please sign in to comment.