Skip to content

Commit d8afe47

Browse files
sxjeruarvinxx
andauthored
✨ feat: Support Doubao Models (lobehub#5481)
* feat(config): add Doubao provider * fix * fix * add * fix * fix * src/server/globalConfig/index.ts * src/app/(main)/settings/provider/(detail)/doubao/page.tsx * fix * try * try * rec * follow review * test * 👌try * Update doubao.ts * Update index.ts * Delete src/app/(main)/settings/llm/ProviderList/Doubao/index.tsx * Update providers.tsx * Update providers.tsx --------- Co-authored-by: Arvin Xu <[email protected]>
1 parent 13c3455 commit d8afe47

File tree

15 files changed

+166
-2
lines changed

15 files changed

+166
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use client';
2+
3+
import { DoubaoProviderCard } from '@/config/modelProviders';
4+
import { ModelProvider } from '@/libs/agent-runtime';
5+
import { useUserStore } from '@/store/user';
6+
import { modelProviderSelectors } from '@/store/user/selectors';
7+
8+
import { ProviderItem } from '../../type';
9+
import ProviderDetail from '../[id]';
10+
11+
const providerKey = ModelProvider.Doubao;
12+
13+
const useProviderCard = (): ProviderItem => {
14+
15+
// Get the first model card's deployment name as the check model
16+
const checkModel = useUserStore((s) => {
17+
const chatModelCards = modelProviderSelectors.getModelCardsById(providerKey)(s);
18+
19+
if (chatModelCards.length > 0) {
20+
return chatModelCards[0].deploymentName;
21+
}
22+
23+
return 'Doubao-lite-4k';
24+
});
25+
return {
26+
...DoubaoProviderCard,
27+
checkModel,
28+
modelList: {
29+
azureDeployName: true,
30+
},
31+
};
32+
};
33+
34+
const Page = () => {
35+
const card = useProviderCard();
36+
37+
return <ProviderDetail {...card} />;
38+
};
39+
40+
export default Page;

src/app/(main)/settings/provider/features/ModelList/ModelConfigModal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const ModelConfigModal = memo<ModelConfigModalProps>(({ id, open, setOpen }) =>
6666
idEditable={false}
6767
initialValues={model}
6868
onFormInstanceReady={setFormInstance}
69-
showAzureDeployName={editingProvider === ModelProvider.Azure}
69+
showAzureDeployName={editingProvider === ModelProvider.Azure || editingProvider === ModelProvider.Doubao}
7070
type={model?.type}
7171
/>
7272
</Modal>

src/config/aiModels/doubao.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { AIChatModelCard } from '@/types/aiModel';
2+
3+
const doubaoChatModels: AIChatModelCard[] = [
4+
{
5+
contextWindowTokens: 4096,
6+
description:
7+
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 4k 上下文窗口的推理和精调。',
8+
displayName: 'Doubao Lite 4k',
9+
enabled: true,
10+
id: 'Doubao-lite-4k',
11+
type: 'chat',
12+
},
13+
{
14+
contextWindowTokens: 32_768,
15+
description:
16+
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 32k 上下文窗口的推理和精调。',
17+
displayName: 'Doubao Lite 32k',
18+
enabled: true,
19+
id: 'Doubao-lite-32k',
20+
type: 'chat',
21+
},
22+
{
23+
contextWindowTokens: 128_000,
24+
description:
25+
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 128k 上下文窗口的推理和精调。',
26+
displayName: 'Doubao Lite 128k',
27+
enabled: true,
28+
id: 'Doubao-lite-128k',
29+
type: 'chat',
30+
},
31+
{
32+
contextWindowTokens: 4096,
33+
description:
34+
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 4k 上下文窗口的推理和精调。',
35+
displayName: 'Doubao Pro 4k',
36+
enabled: true,
37+
id: 'Doubao-pro-4k',
38+
type: 'chat',
39+
},
40+
{
41+
config: {
42+
deploymentName: 'Doubao-pro-test',
43+
},
44+
contextWindowTokens: 32_768,
45+
description:
46+
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 32k 上下文窗口的推理和精调。',
47+
displayName: 'Doubao Pro 32k',
48+
enabled: true,
49+
id: 'Doubao-pro-32k',
50+
type: 'chat',
51+
},
52+
{
53+
contextWindowTokens: 128_000,
54+
description:
55+
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 128k 上下文窗口的推理和精调。',
56+
displayName: 'Doubao Pro 128k',
57+
enabled: true,
58+
id: 'Doubao-pro-128k',
59+
type: 'chat',
60+
},
61+
];
62+
63+
export const allModels = [...doubaoChatModels];
64+
65+
export default allModels;

src/config/aiModels/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { default as baichuan } from './baichuan';
88
import { default as bedrock } from './bedrock';
99
import { default as cloudflare } from './cloudflare';
1010
import { default as deepseek } from './deepseek';
11+
import { default as doubao } from './doubao';
1112
import { default as fireworksai } from './fireworksai';
1213
import { default as giteeai } from './giteeai';
1314
import { default as github } from './github';
@@ -67,6 +68,7 @@ export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({
6768
bedrock,
6869
cloudflare,
6970
deepseek,
71+
doubao,
7072
fireworksai,
7173
giteeai,
7274
github,
@@ -107,6 +109,7 @@ export { default as baichuan } from './baichuan';
107109
export { default as bedrock } from './bedrock';
108110
export { default as cloudflare } from './cloudflare';
109111
export { default as deepseek } from './deepseek';
112+
export { default as doubao } from './doubao';
110113
export { default as fireworksai } from './fireworksai';
111114
export { default as giteeai } from './giteeai';
112115
export { default as github } from './github';

src/config/llm.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export const getLLMConfig = () => {
123123

124124
ENABLED_HIGRESS: z.boolean(),
125125
HIGRESS_API_KEY: z.string().optional(),
126+
127+
ENABLED_DOUBAO: z.boolean(),
128+
DOUBAO_API_KEY: z.string().optional(),
126129
},
127130
runtimeEnv: {
128131
API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE,
@@ -244,6 +247,9 @@ export const getLLMConfig = () => {
244247

245248
ENABLED_HIGRESS: !!process.env.HIGRESS_API_KEY,
246249
HIGRESS_API_KEY: process.env.HIGRESS_API_KEY,
250+
251+
ENABLED_DOUBAO: !!process.env.DOUBAO_API_KEY,
252+
DOUBAO_API_KEY: process.env.DOUBAO_API_KEY,
247253
},
248254
});
249255
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ModelProviderCard } from '@/types/llm';
2+
3+
// ref https://www.volcengine.com/docs/82379/1330310
4+
const Doubao: ModelProviderCard = {
5+
chatModels: [],
6+
// checkModel: 'Doubao-lite-4k',
7+
description: '字节跳动推出的自研大模型。通过字节跳动内部50+业务场景实践验证,每日万亿级tokens大使用量持续打磨,提供多种模态能力,以优质模型效果为企业打造丰富的业务体验。',
8+
id: 'doubao',
9+
modelsUrl: 'https://www.volcengine.com/product/doubao',
10+
name: '豆包',
11+
settings: {
12+
disableBrowserRequest: true, // CORS error
13+
sdkType: 'doubao',
14+
// showModelFetcher: false,
15+
smoothing: {
16+
speed: 2,
17+
text: true,
18+
},
19+
},
20+
url: 'https://www.volcengine.com/product/doubao',
21+
};
22+
23+
export default Doubao;

src/config/modelProviders/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import BaichuanProvider from './baichuan';
88
import BedrockProvider from './bedrock';
99
import CloudflareProvider from './cloudflare';
1010
import DeepSeekProvider from './deepseek';
11+
import DoubaoProvider from './doubao';
1112
import FireworksAIProvider from './fireworksai';
1213
import GiteeAIProvider from './giteeai';
1314
import GithubProvider from './github';
@@ -120,6 +121,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
120121
GiteeAIProvider,
121122
TaichuProvider,
122123
Ai360Provider,
124+
DoubaoProvider,
123125
];
124126

125127
export const filterEnabledModels = (provider: ModelProviderCard) => {
@@ -139,6 +141,7 @@ export { default as BaichuanProviderCard } from './baichuan';
139141
export { default as BedrockProviderCard } from './bedrock';
140142
export { default as CloudflareProviderCard } from './cloudflare';
141143
export { default as DeepSeekProviderCard } from './deepseek';
144+
export { default as DoubaoProviderCard } from './doubao';
142145
export { default as FireworksAIProviderCard } from './fireworksai';
143146
export { default as GiteeAIProviderCard } from './giteeai';
144147
export { default as GithubProviderCard } from './github';

src/libs/agent-runtime/AgentRuntime.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LobeBaichuanAI } from './baichuan';
1111
import { LobeBedrockAI, LobeBedrockAIParams } from './bedrock';
1212
import { LobeCloudflareAI, LobeCloudflareParams } from './cloudflare';
1313
import { LobeDeepSeekAI } from './deepseek';
14+
import { LobeDoubaoAI } from './doubao';
1415
import { LobeFireworksAI } from './fireworksai';
1516
import { LobeGiteeAI } from './giteeai';
1617
import { LobeGithubAI } from './github';
@@ -139,6 +140,7 @@ class AgentRuntime {
139140
bedrock: Partial<LobeBedrockAIParams>;
140141
cloudflare: Partial<LobeCloudflareParams>;
141142
deepseek: Partial<ClientOptions>;
143+
doubao: Partial<ClientOptions>;
142144
fireworksai: Partial<ClientOptions>;
143145
giteeai: Partial<ClientOptions>;
144146
github: Partial<ClientOptions>;
@@ -363,6 +365,11 @@ class AgentRuntime {
363365
runtimeModel = new LobeHigressAI(params.higress);
364366
break;
365367
}
368+
369+
case ModelProvider.Doubao: {
370+
runtimeModel = new LobeDoubaoAI(params.doubao);
371+
break;
372+
}
366373
}
367374
return new AgentRuntime(runtimeModel);
368375
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ModelProvider } from '../types';
2+
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';
3+
4+
export const LobeDoubaoAI = LobeOpenAICompatibleFactory({
5+
baseURL: 'https://ark.cn-beijing.volces.com/api/v3',
6+
debug: {
7+
chatCompletion: () => process.env.DEBUG_DOUBAO_CHAT_COMPLETION === '1',
8+
},
9+
provider: ModelProvider.Doubao,
10+
});

src/libs/agent-runtime/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { LobeAzureOpenAI } from './azureOpenai';
44
export * from './BaseAI';
55
export { LobeBedrockAI } from './bedrock';
66
export { LobeDeepSeekAI } from './deepseek';
7+
export { LobeDoubaoAI } from './doubao';
78
export * from './error';
89
export { LobeGoogleAI } from './google';
910
export { LobeGroq } from './groq';

0 commit comments

Comments
 (0)