Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: Improve Doubao provider && Rename Doubao to Volcano Ark #5612

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ 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);

console.log(chatModelCards);
if (chatModelCards.length > 0) {
return chatModelCards[0].deploymentName;
return chatModelCards[0].id.split('->')[1];
}

return 'Doubao-lite-4k';
return 'no-model';
});
return {
...DoubaoProviderCard,
Expand All @@ -32,9 +31,9 @@ const useProviderCard = (): ProviderItem => {
};

const Page = () => {
const card = useProviderCard();
return <ProviderDetail {...card} />;
};
export default Page;
const card = useProviderCard();

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

export default Page;
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const ModelConfigModal = memo<ModelConfigModalProps>(({ open, setOpen }) => {
>
<ModelConfigForm
onFormInstanceReady={setFormInstance}
showAzureDeployName={editingProvider === ModelProvider.Azure}
showAzureDeployName={
editingProvider === ModelProvider.Azure || editingProvider === ModelProvider.Doubao
}
/>
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const ModelConfigModal = memo<ModelConfigModalProps>(({ id, open, setOpen }) =>
idEditable={false}
initialValues={model}
onFormInstanceReady={setFormInstance}
showAzureDeployName={editingProvider === ModelProvider.Azure || editingProvider === ModelProvider.Doubao}
showAzureDeployName={
editingProvider === ModelProvider.Azure || editingProvider === ModelProvider.Doubao
}
type={model?.type}
/>
</Modal>
Expand Down
105 changes: 48 additions & 57 deletions src/config/aiModels/doubao.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,54 @@
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',
},
{
contextWindowTokens: 4096,
description:
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 4k 上下文窗口的推理和精调。',
displayName: 'Doubao Lite 4k',
id: 'Doubao-lite-4k',
type: 'chat',
},
{
contextWindowTokens: 32_768,
description:
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 32k 上下文窗口的推理和精调。',
displayName: 'Doubao Lite 32k',
id: 'Doubao-lite-32k',
type: 'chat',
},
{
contextWindowTokens: 128_000,
description:
'拥有极致的响应速度,更好的性价比,为客户不同场景提供更灵活的选择。支持 128k 上下文窗口的推理和精调。',
displayName: 'Doubao Lite 128k',
id: 'Doubao-lite-128k',
type: 'chat',
},
{
contextWindowTokens: 4096,
description:
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 4k 上下文窗口的推理和精调。',
displayName: 'Doubao Pro 4k',
id: 'Doubao-pro-4k',
type: 'chat',
},
{
contextWindowTokens: 32_768,
description:
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 32k 上下文窗口的推理和精调。',
displayName: 'Doubao Pro 32k',
id: 'Doubao-pro-32k',
type: 'chat',
},
{
contextWindowTokens: 128_000,
description:
'效果最好的主力模型,适合处理复杂任务,在参考问答、总结摘要、创作、文本分类、角色扮演等场景都有很好的效果。支持 128k 上下文窗口的推理和精调。',
displayName: 'Doubao Pro 128k',
id: 'Doubao-pro-128k',
type: 'chat',
},
];

export const allModels = [...doubaoChatModels];
Expand Down
4 changes: 2 additions & 2 deletions src/config/modelProviders/doubao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ModelProviderCard } from '@/types/llm';
// ref https://www.volcengine.com/docs/82379/1330310
const Doubao: ModelProviderCard = {
chatModels: [],
// checkModel: 'Doubao-lite-4k',
description: '字节跳动推出的自研大模型。通过字节跳动内部50+业务场景实践验证,每日万亿级tokens大使用量持续打磨,提供多种模态能力,以优质模型效果为企业打造丰富的业务体验。',
description:
'字节跳动推出的自研大模型。通过字节跳动内部50+业务场景实践验证,每日万亿级tokens大使用量持续打磨,提供多种模态能力,以优质模型效果为企业打造丰富的业务体验。',
id: 'doubao',
modelsUrl: 'https://www.volcengine.com/product/doubao',
name: '豆包',
Expand Down
26 changes: 25 additions & 1 deletion src/libs/agent-runtime/doubao/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import { LOBE_DEFAULT_MODEL_LIST } from '@/config/aiModels';

import { ModelProvider } from '../types';
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory';

export interface DoubaoModelCard {
context_window: number;
id: string;
}

export const LobeDoubaoAI = LobeOpenAICompatibleFactory({
baseURL: 'https://ark.cn-beijing.volces.com/api/v3',
debug: {
chatCompletion: () => process.env.DEBUG_DOUBAO_CHAT_COMPLETION === '1',
},
models: {
transformModel: (m) => {
const functionCallKeywords = ['tool'];

const model = m as unknown as DoubaoModelCard;

return {
contextWindowTokens: model.context_window,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id.endsWith(m.id))?.enabled || false,
functionCall: functionCallKeywords.some((keyword) =>
model.id.toLowerCase().includes(keyword),
),
id: model.id,
vision: model.id.toLowerCase().includes('vision'),
};
},
},
provider: ModelProvider.Doubao,
});
});
29 changes: 28 additions & 1 deletion src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ const findAzureDeploymentName = (model: string) => {
return deploymentId;
};

const findDoubaoDeploymentName = (model: string) => {
let deploymentId = model;

// TODO: remove isDeprecatedEdition condition in V2.0
if (isDeprecatedEdition) {
const chatModelCards = modelProviderSelectors.getModelCardsById(ModelProvider.Doubao)(
useUserStore.getState(),
);

const deploymentName = chatModelCards.find((i) => i.id === model)?.deploymentName;
if (deploymentName) deploymentId = deploymentName;
} else {
// find the model by id
const modelItem = useAiInfraStore.getState().enabledAiModels?.find((i) => i.id === model);

if (modelItem && modelItem.config?.deploymentName) {
deploymentId = modelItem.config?.deploymentName;
}
}

return deploymentId;
};

const isEnableFetchOnClient = (provider: string) => {
// TODO: remove this condition in V2.0
if (isDeprecatedEdition) {
Expand Down Expand Up @@ -222,10 +245,14 @@ 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 || provider === ModelProvider.Doubao) {
if (provider === ModelProvider.Azure) {
model = findAzureDeploymentName(model);
}

if (provider === ModelProvider.Doubao) {
model = findDoubaoDeploymentName(model);
}

const payload = merge(
{ model: DEFAULT_AGENT_CONFIG.model, stream: true, ...DEFAULT_AGENT_CONFIG.params },
{ ...res, model },
Expand Down