Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/app/(main)/settings/llm/ProviderList/Doubao/index.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/llm 路径下不再做任何变更

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分大概旧版设置页(/settings/llm)还在用吧,貌似本地调试还没有更新到服务端数据库在用的 /settings/provider

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本地的话需要配置 NEXT_PUBLIC_CLIENT_DB=pglite 开启新版,估计再迭代 2~3 个中版本,client db 就准备全量迁移 pglite 了。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我已升级到v1.51.12,但大模型列表中没有豆包选项,请问任何开启?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不是服务端数据库版本,需要在环境变量添加 NEXT_PUBLIC_CLIENT_DB=pglite

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';

import { DoubaoProviderCard } from '@/config/modelProviders';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';
import { GlobalLLMProviderKey } from '@/types/user/settings';

import { ProviderItem } from '../../type';

const providerKey: GlobalLLMProviderKey = 'doubao';

export const useDoubaoProvider = (): ProviderItem => {
// Get the first model card's deployment name as the check model
const checkModel = useUserStore((s) => {
const chatModelCards = modelProviderSelectors.getModelCardsById(providerKey)(s);

if (chatModelCards.length > 0) {
return chatModelCards[0].deploymentName;
}

return 'no-model';
});

return {
...DoubaoProviderCard,
checkModel,
modelList: {
azureDeployName: true,
},
};
};
5 changes: 5 additions & 0 deletions src/app/(main)/settings/llm/ProviderList/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AnthropicProviderCard,
BaichuanProviderCard,
DeepSeekProviderCard,
// DoubaoProviderCard,
FireworksAIProviderCard,
GiteeAIProviderCard,
GoogleProviderCard,
Expand Down Expand Up @@ -36,6 +37,7 @@ import { ProviderItem } from '../type';
import { useAzureProvider } from './Azure';
import { useBedrockProvider } from './Bedrock';
import { useCloudflareProvider } from './Cloudflare';
import { useDoubaoProvider } from './Doubao';
import { useGithubProvider } from './Github';
import { useHuggingFaceProvider } from './HuggingFace';
import { useOllamaProvider } from './Ollama';
Expand All @@ -51,6 +53,7 @@ export const useProviderList = (): ProviderItem[] => {
const GithubProvider = useGithubProvider();
const HuggingFaceProvider = useHuggingFaceProvider();
const WenxinProvider = useWenxinProvider();
const DoubaoProvider = useDoubaoProvider();

return useMemo(
() => [
Expand All @@ -61,6 +64,7 @@ export const useProviderList = (): ProviderItem[] => {
BedrockProvider,
GoogleProviderCard,
DeepSeekProviderCard,
DoubaoProvider,
HuggingFaceProvider,
OpenRouterProviderCard,
CloudflareProvider,
Expand Down Expand Up @@ -101,6 +105,7 @@ export const useProviderList = (): ProviderItem[] => {
GithubProvider,
WenxinProvider,
HuggingFaceProvider,
DoubaoProvider,
],
);
};
40 changes: 40 additions & 0 deletions src/app/(main)/settings/provider/(detail)/doubao/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use client';

import { DoubaoProviderCard } from '@/config/modelProviders';
import { ModelProvider } from '@/libs/agent-runtime';
import { useUserStore } from '@/store/user';
import { modelProviderSelectors } from '@/store/user/selectors';

import { ProviderItem } from '../../type';
import ProviderDetail from '../[id]';

const providerKey = ModelProvider.Doubao;

const useProviderCard = (): ProviderItem => {

// Get the first model card's deployment name as the check model
const checkModel = useUserStore((s) => {
const chatModelCards = modelProviderSelectors.getModelCardsById(providerKey)(s);

if (chatModelCards.length > 0) {
return chatModelCards[0].deploymentName;
}

return 'Doubao-lite-4k';
});
return {
...DoubaoProviderCard,
checkModel,
modelList: {
azureDeployName: true,
},
};
};

const Page = () => {
const card = useProviderCard();

return <ProviderDetail {...card} />;
};

export default Page;
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const ModelConfigModal = memo<ModelConfigModalProps>(({ id, open, setOpen }) =>
idEditable={false}
initialValues={model}
onFormInstanceReady={setFormInstance}
showAzureDeployName={editingProvider === ModelProvider.Azure}
showAzureDeployName={editingProvider === ModelProvider.Azure || editingProvider === ModelProvider.Doubao}
type={model?.type}
/>
</Modal>
Expand Down
65 changes: 65 additions & 0 deletions src/config/aiModels/doubao.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { AIChatModelCard } from '@/types/aiModel';

const doubaoChatModels: AIChatModelCard[] = [
{
contextWindowTokens: 4096,
description:
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 4k 上下文窗口的推理和精调。',
displayName: 'Doubao Lite 4k',
enabled: true,
id: 'Doubao-lite-4k',
type: 'chat',
},
{
contextWindowTokens: 32_768,
description:
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 32k 上下文窗口的推理和精调。',
displayName: 'Doubao Lite 32k',
enabled: true,
id: 'Doubao-lite-32k',
type: 'chat',
},
{
contextWindowTokens: 128_000,
description:
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 128k 上下文窗口的推理和精调。',
displayName: 'Doubao Lite 128k',
enabled: true,
id: 'Doubao-lite-128k',
type: 'chat',
},
{
contextWindowTokens: 4096,
description:
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 4k 上下文窗口的推理和精调。',
displayName: 'Doubao Pro 4k',
enabled: true,
id: 'Doubao-pro-4k',
type: 'chat',
},
{
config: {
deploymentName: 'Doubao-pro-test',
},
contextWindowTokens: 32_768,
description:
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 32k 上下文窗口的推理和精调。',
displayName: 'Doubao Pro 32k',
enabled: true,
id: 'Doubao-pro-32k',
type: 'chat',
},
{
contextWindowTokens: 128_000,
description:
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 128k 上下文窗口的推理和精调。',
displayName: 'Doubao Pro 128k',
enabled: true,
id: 'Doubao-pro-128k',
type: 'chat',
},
];

export const allModels = [...doubaoChatModels];

export default allModels;
3 changes: 3 additions & 0 deletions src/config/aiModels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { default as baichuan } from './baichuan';
import { default as bedrock } from './bedrock';
import { default as cloudflare } from './cloudflare';
import { default as deepseek } from './deepseek';
import { default as doubao } from './doubao';
import { default as fireworksai } from './fireworksai';
import { default as giteeai } from './giteeai';
import { default as github } from './github';
Expand Down Expand Up @@ -67,6 +68,7 @@ export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({
bedrock,
cloudflare,
deepseek,
doubao,
fireworksai,
giteeai,
github,
Expand Down Expand Up @@ -107,6 +109,7 @@ export { default as baichuan } from './baichuan';
export { default as bedrock } from './bedrock';
export { default as cloudflare } from './cloudflare';
export { default as deepseek } from './deepseek';
export { default as doubao } from './doubao';
export { default as fireworksai } from './fireworksai';
export { default as giteeai } from './giteeai';
export { default as github } from './github';
Expand Down
6 changes: 6 additions & 0 deletions src/config/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export const getLLMConfig = () => {

ENABLED_HIGRESS: z.boolean(),
HIGRESS_API_KEY: z.string().optional(),

ENABLED_DOUBAO: z.boolean(),
DOUBAO_API_KEY: z.string().optional(),
},
runtimeEnv: {
API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE,
Expand Down Expand Up @@ -244,6 +247,9 @@ export const getLLMConfig = () => {

ENABLED_HIGRESS: !!process.env.HIGRESS_API_KEY,
HIGRESS_API_KEY: process.env.HIGRESS_API_KEY,

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

// ref https://www.volcengine.com/docs/82379/1330310
const Doubao: ModelProviderCard = {
chatModels: [],
// checkModel: 'Doubao-lite-4k',
description: '字节跳动推出的自研大模型。通过字节跳动内部50+业务场景实践验证,每日万亿级tokens大使用量持续打磨,提供多种模态能力,以优质模型效果为企业打造丰富的业务体验。',
id: 'doubao',
modelsUrl: 'https://www.volcengine.com/product/doubao',
name: '豆包',
settings: {
disableBrowserRequest: true, // CORS error
sdkType: 'doubao',
// showModelFetcher: false,
smoothing: {
speed: 2,
text: true,
},
},
url: 'https://www.volcengine.com/product/doubao',
};

export default Doubao;
3 changes: 3 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BaichuanProvider from './baichuan';
import BedrockProvider from './bedrock';
import CloudflareProvider from './cloudflare';
import DeepSeekProvider from './deepseek';
import DoubaoProvider from './doubao';
import FireworksAIProvider from './fireworksai';
import GiteeAIProvider from './giteeai';
import GithubProvider from './github';
Expand Down Expand Up @@ -120,6 +121,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
GiteeAIProvider,
TaichuProvider,
Ai360Provider,
DoubaoProvider,
];

export const filterEnabledModels = (provider: ModelProviderCard) => {
Expand All @@ -139,6 +141,7 @@ export { default as BaichuanProviderCard } from './baichuan';
export { default as BedrockProviderCard } from './bedrock';
export { default as CloudflareProviderCard } from './cloudflare';
export { default as DeepSeekProviderCard } from './deepseek';
export { default as DoubaoProviderCard } from './doubao';
export { default as FireworksAIProviderCard } from './fireworksai';
export { default as GiteeAIProviderCard } from './giteeai';
export { default as GithubProviderCard } from './github';
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 @@ -11,6 +11,7 @@ import { LobeBaichuanAI } from './baichuan';
import { LobeBedrockAI, LobeBedrockAIParams } from './bedrock';
import { LobeCloudflareAI, LobeCloudflareParams } from './cloudflare';
import { LobeDeepSeekAI } from './deepseek';
import { LobeDoubaoAI } from './doubao';
import { LobeFireworksAI } from './fireworksai';
import { LobeGiteeAI } from './giteeai';
import { LobeGithubAI } from './github';
Expand Down Expand Up @@ -139,6 +140,7 @@ class AgentRuntime {
bedrock: Partial<LobeBedrockAIParams>;
cloudflare: Partial<LobeCloudflareParams>;
deepseek: Partial<ClientOptions>;
doubao: Partial<ClientOptions>;
fireworksai: Partial<ClientOptions>;
giteeai: Partial<ClientOptions>;
github: Partial<ClientOptions>;
Expand Down Expand Up @@ -363,6 +365,11 @@ class AgentRuntime {
runtimeModel = new LobeHigressAI(params.higress);
break;
}

case ModelProvider.Doubao: {
runtimeModel = new LobeDoubaoAI(params.doubao);
break;
}
}
return new AgentRuntime(runtimeModel);
}
Expand Down
10 changes: 10 additions & 0 deletions src/libs/agent-runtime/doubao/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ModelProvider } from '../types';
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';

export const LobeDoubaoAI = LobeOpenAICompatibleFactory({
baseURL: 'https://ark.cn-beijing.volces.com/api/v3',
debug: {
chatCompletion: () => process.env.DEBUG_DOUBAO_CHAT_COMPLETION === '1',
},
provider: ModelProvider.Doubao,
});
1 change: 1 addition & 0 deletions src/libs/agent-runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { LobeAzureOpenAI } from './azureOpenai';
export * from './BaseAI';
export { LobeBedrockAI } from './bedrock';
export { LobeDeepSeekAI } from './deepseek';
export { LobeDoubaoAI } from './doubao';
export * from './error';
export { LobeGoogleAI } from './google';
export { LobeGroq } from './groq';
Expand Down
1 change: 1 addition & 0 deletions src/libs/agent-runtime/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export enum ModelProvider {
Bedrock = 'bedrock',
Cloudflare = 'cloudflare',
DeepSeek = 'deepseek',
Doubao = 'doubao',
FireworksAI = 'fireworksai',
GiteeAI = 'giteeai',
Github = 'github',
Expand Down
3 changes: 3 additions & 0 deletions src/server/globalConfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const getServerGlobalConfig = () => {
enabledKey: 'ENABLED_AWS_BEDROCK',
modelListKey: 'AWS_BEDROCK_MODEL_LIST',
},
doubao: {
withDeploymentName: true,
},
giteeai: {
enabledKey: 'ENABLED_GITEE_AI',
modelListKey: 'GITEE_AI_MODEL_LIST',
Expand Down
2 changes: 1 addition & 1 deletion src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class ChatService {
let model = res.model || DEFAULT_AGENT_CONFIG.model;

// if the provider is Azure, get the deployment name as the request model
if (provider === ModelProvider.Azure) {
if (provider === ModelProvider.Azure || provider === ModelProvider.Doubao) {
model = findAzureDeploymentName(model);
}

Expand Down
1 change: 1 addition & 0 deletions src/types/aiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const AiProviderSDKEnum = {
Azure: 'azure',
Bedrock: 'bedrock',
Cloudflare: 'cloudflare',
Doubao: 'doubao',
Google: 'google',
Huggingface: 'huggingface',
Ollama: 'ollama',
Expand Down
1 change: 1 addition & 0 deletions src/types/user/settings/keyVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface UserKeyVaults {
bedrock?: AWSBedrockKeyVault;
cloudflare?: CloudflareKeyVault;
deepseek?: OpenAICompatibleKeyVault;
doubao?: OpenAICompatibleKeyVault;
fireworksai?: OpenAICompatibleKeyVault;
giteeai?: OpenAICompatibleKeyVault;
github?: OpenAICompatibleKeyVault;
Expand Down
Loading