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

♻️ refactor: improve model fetch behavior #6055

Merged
merged 10 commits into from
Feb 14, 2025
9 changes: 9 additions & 0 deletions src/config/aiModels/spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const sparkChatModels: AIChatModelCard[] = [
type: 'chat',
},
{
abilities: {
functionCall: true,
},
contextWindowTokens: 8192,
description:
'Spark Max 为功能最为全面的版本,支持联网搜索及众多内置插件。其全面优化的核心能力以及系统角色设定和函数调用功能,使其在各种复杂应用场景中的表现极为优异和出色。',
Expand All @@ -42,6 +45,9 @@ const sparkChatModels: AIChatModelCard[] = [
type: 'chat',
},
{
abilities: {
functionCall: true,
},
contextWindowTokens: 32_768,
description:
'Spark Max 32K 配置了大上下文处理能力,更强的上下文理解和逻辑推理能力,支持32K tokens的文本输入,适用于长文档阅读、私有知识问答等场景',
Expand All @@ -52,6 +58,9 @@ const sparkChatModels: AIChatModelCard[] = [
type: 'chat',
},
{
abilities: {
functionCall: true,
},
contextWindowTokens: 8192,
description:
'Spark Ultra 是星火大模型系列中最为强大的版本,在升级联网搜索链路同时,提升对文本内容的理解和总结能力。它是用于提升办公生产力和准确响应需求的全方位解决方案,是引领行业的智能产品。',
Expand Down
16 changes: 12 additions & 4 deletions src/libs/agent-runtime/ai360/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,25 @@ export const LobeAi360AI = LobeOpenAICompatibleFactory({

const model = m as unknown as Ai360ModelCard;

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: model.total_tokens,
displayName: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.displayName ?? undefined,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
functionCall: model.id === '360gpt-pro',
displayName: knownModel?.displayName ?? undefined,
enabled: knownModel?.enabled || false,
functionCall:
model.id === '360gpt-pro'
|| knownModel?.abilities?.functionCall
|| false,
id: model.id,
maxTokens:
typeof model.max_tokens === 'number'
? model.max_tokens
: undefined,
reasoning: reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)),
reasoning:
reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword))
|| knownModel?.abilities?.reasoning
|| false,
};
},
},
Expand Down
16 changes: 12 additions & 4 deletions src/libs/agent-runtime/anthropic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,21 @@ export class LobeAnthropicAI implements LobeRuntimeAI {

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.contextWindowTokens ?? undefined,
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
displayName: model.display_name,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
functionCall: model.id.toLowerCase().includes('claude-3'),
enabled: knownModel?.enabled || false,
functionCall:
model.id.toLowerCase().includes('claude-3')
|| knownModel?.abilities?.functionCall
|| false,
id: model.id,
vision: model.id.toLowerCase().includes('claude-3') && !model.id.toLowerCase().includes('claude-3-5-haiku'),
vision:
model.id.toLowerCase().includes('claude-3') && !model.id.toLowerCase().includes('claude-3-5-haiku')
|| knownModel?.abilities?.vision
|| false,
};
})
.filter(Boolean) as ChatModelCard[];
Expand Down
4 changes: 3 additions & 1 deletion src/libs/agent-runtime/baichuan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export const LobeBaichuanAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.model === m.id);

return {
contextWindowTokens: model.max_input_length,
displayName: model.model_show_name,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.model === m.id)?.enabled || false,
enabled: knownModel?.enabled || false,
functionCall: model.function_call,
id: model.model,
maxTokens: model.max_tokens,
Expand Down
26 changes: 20 additions & 6 deletions src/libs/agent-runtime/cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,30 @@ export class LobeCloudflareAI implements LobeRuntimeAI {

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id);

return {
contextWindowTokens: model.properties?.max_total_tokens
? Number(model.properties.max_total_tokens)
: LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id)?.contextWindowTokens ?? undefined,
displayName: LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id)?.displayName ?? (model.properties?.["beta"] === "true" ? `${model.name} (Beta)` : undefined),
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id)?.enabled || false,
functionCall: model.description.toLowerCase().includes('function call') || model.properties?.["function_calling"] === "true",
: knownModel?.contextWindowTokens ?? undefined,
displayName: knownModel?.displayName ?? (model.properties?.["beta"] === "true" ? `${model.name} (Beta)` : undefined),
enabled: knownModel?.enabled || false,
functionCall:
model.description.toLowerCase().includes('function call')
|| model.properties?.["function_calling"] === "true"
|| knownModel?.abilities?.functionCall
|| false,
id: model.name,
reasoning: model.name.toLowerCase().includes('deepseek-r1'),
vision: model.name.toLowerCase().includes('vision') || model.task?.name.toLowerCase().includes('image-to-text') || model.description.toLowerCase().includes('vision'),
reasoning:
model.name.toLowerCase().includes('deepseek-r1')
|| knownModel?.abilities?.reasoning
|| false,
vision:
model.name.toLowerCase().includes('vision')
|| model.task?.name.toLowerCase().includes('image-to-text')
|| model.description.toLowerCase().includes('vision')
|| knownModel?.abilities?.vision
|| false,
};
})
.filter(Boolean) as ChatModelCard[];
Expand Down
18 changes: 13 additions & 5 deletions src/libs/agent-runtime/deepseek/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ export const LobeDeepSeekAI = LobeOpenAICompatibleFactory({
transformModel: (m) => {
const model = m as unknown as DeepSeekModelCard;

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.contextWindowTokens ?? undefined,
displayName: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.displayName ?? undefined,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
functionCall: !model.id.toLowerCase().includes('deepseek-reasoner'),
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
displayName: knownModel?.displayName ?? undefined,
enabled: knownModel?.enabled || false,
functionCall:
!model.id.toLowerCase().includes('reasoner')
|| knownModel?.abilities?.functionCall
|| false,
id: model.id,
reasoning: model.id.toLowerCase().includes('deepseek-reasoner'),
reasoning:
model.id.toLowerCase().includes('reasoner')
|| knownModel?.abilities?.reasoning
|| false,
};
},
},
Expand Down
15 changes: 11 additions & 4 deletions src/libs/agent-runtime/fireworksai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ export const LobeFireworksAI = LobeOpenAICompatibleFactory({

const model = m as unknown as FireworksAIModelCard;

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: model.context_length,
displayName: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.displayName ?? undefined,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
functionCall: model.supports_tools || model.id.toLowerCase().includes('function'),
displayName: knownModel?.displayName ?? undefined,
enabled: knownModel?.enabled || false,
functionCall:
model.supports_tools
|| model.id.toLowerCase().includes('function'),
id: model.id,
reasoning: reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)),
reasoning:
reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword))
|| knownModel?.abilities?.reasoning
|| false,
vision: model.supports_image_input,
};
},
Expand Down
23 changes: 17 additions & 6 deletions src/libs/agent-runtime/giteeai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,25 @@ export const LobeGiteeAI = LobeOpenAICompatibleFactory({

const model = m as unknown as GiteeAIModelCard;

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.contextWindowTokens ?? undefined,
displayName: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.displayName ?? undefined,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
functionCall: functionCallKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) && !model.id.toLowerCase().includes('qwen2.5-coder'),
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
displayName: knownModel?.displayName ?? undefined,
enabled: knownModel?.enabled || false,
functionCall:
functionCallKeywords.some(keyword => model.id.toLowerCase().includes(keyword)) && !model.id.toLowerCase().includes('qwen2.5-coder')
|| knownModel?.abilities?.functionCall
|| false,
id: model.id,
reasoning: reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)),
vision: visionKeywords.some(keyword => model.id.toLowerCase().includes(keyword)),
reasoning:
reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword))
|| knownModel?.abilities?.reasoning
|| false,
vision:
visionKeywords.some(keyword => model.id.toLowerCase().includes(keyword))
|| knownModel?.abilities?.vision
|| false,
};
},
},
Expand Down
21 changes: 16 additions & 5 deletions src/libs/agent-runtime/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,26 @@ export const LobeGithubAI = LobeOpenAICompatibleFactory({

return modelList
.map((model) => {
const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id);

return {
contextWindowTokens: LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id)?.contextWindowTokens ?? undefined,
contextWindowTokens: knownModel?.contextWindowTokens ?? undefined,
description: model.description,
displayName: model.friendly_name,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.name === m.id)?.enabled || false,
functionCall: functionCallKeywords.some(keyword => model.description.toLowerCase().includes(keyword)),
enabled: knownModel?.enabled || false,
functionCall:
functionCallKeywords.some(keyword => model.description.toLowerCase().includes(keyword))
|| knownModel?.abilities?.functionCall
|| false,
id: model.name,
reasoning: reasoningKeywords.some(keyword => model.name.toLowerCase().includes(keyword)),
vision: visionKeywords.some(keyword => model.description.toLowerCase().includes(keyword)),
reasoning:
reasoningKeywords.some(keyword => model.name.toLowerCase().includes(keyword))
|| knownModel?.abilities?.reasoning
|| false,
vision:
visionKeywords.some(keyword => model.description.toLowerCase().includes(keyword))
|| knownModel?.abilities?.vision
|| false,
};
})
.filter(Boolean) as ChatModelCard[];
Expand Down
21 changes: 15 additions & 6 deletions src/libs/agent-runtime/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,26 @@ export class LobeGoogleAI implements LobeRuntimeAI {
.map((model) => {
const modelName = model.name.replace(/^models\//, '');

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => modelName === m.id);

return {
contextWindowTokens: model.inputTokenLimit + model.outputTokenLimit,
displayName: model.displayName,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => modelName === m.id)?.enabled || false,
functionCall: modelName.toLowerCase().includes('gemini'),
enabled: knownModel?.enabled || false,
functionCall:
modelName.toLowerCase().includes('gemini') && !modelName.toLowerCase().includes('thinking')
|| knownModel?.abilities?.functionCall
|| false,
id: modelName,
reasoning: modelName.toLowerCase().includes('thinking'),
reasoning:
modelName.toLowerCase().includes('thinking')
|| knownModel?.abilities?.reasoning
|| false,
vision:
modelName.toLowerCase().includes('vision') ||
(modelName.toLowerCase().includes('gemini') &&
!modelName.toLowerCase().includes('gemini-1.0')),
modelName.toLowerCase().includes('vision')
|| (modelName.toLowerCase().includes('gemini') && !modelName.toLowerCase().includes('gemini-1.0'))
|| knownModel?.abilities?.vision
|| false,
};
})
.filter(Boolean) as ChatModelCard[];
Expand Down
21 changes: 16 additions & 5 deletions src/libs/agent-runtime/groq/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@ export const LobeGroq = LobeOpenAICompatibleFactory({

const model = m as unknown as GroqModelCard;

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: model.context_window,
displayName: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.displayName ?? undefined,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
functionCall: functionCallKeywords.some(keyword => model.id.toLowerCase().includes(keyword)),
displayName: knownModel?.displayName ?? undefined,
enabled: knownModel?.enabled || false,
functionCall:
functionCallKeywords.some(keyword => model.id.toLowerCase().includes(keyword))
|| knownModel?.abilities?.functionCall
|| false,
id: model.id,
reasoning: reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword)),
vision: model.id.toLowerCase().includes('vision'),
reasoning:
reasoningKeywords.some(keyword => model.id.toLowerCase().includes(keyword))
|| knownModel?.abilities?.reasoning
|| false,
vision:
model.id.toLowerCase().includes('vision')
|| knownModel?.abilities?.vision
|| false,
};
},
},
Expand Down
26 changes: 17 additions & 9 deletions src/libs/agent-runtime/higress/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { uniqueId } from 'lodash-es';

import { LOBE_DEFAULT_MODEL_LIST } from '@/config/modelProviders';

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

// import { OpenRouterModelCard } from './type';
import { LOBE_DEFAULT_MODEL_LIST } from '@/config/aiModels';

export const LobeHigressAI = LobeOpenAICompatibleFactory({
constructorOptions: {
Expand All @@ -22,23 +20,33 @@ export const LobeHigressAI = LobeOpenAICompatibleFactory({
transformModel: (m) => {
const model = m as any;

const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id);

return {
contextWindowTokens: model.context_length,
description: model.description,
displayName: model.name,
enabled: LOBE_DEFAULT_MODEL_LIST.find((m) => model.id === m.id)?.enabled || false,
enabled: knownModel?.enabled || false,
functionCall:
model.description.includes('function calling') || model.description.includes('tools'),
model.description.includes('function calling')
|| model.description.includes('tools')
|| knownModel?.abilities?.functionCall
|| false,
id: model.id,
maxTokens:
typeof model.top_provider.max_completion_tokens === 'number'
? model.top_provider.max_completion_tokens
: undefined,
reasoning: model.description.includes('reasoning'),
reasoning:
model.description.includes('reasoning')
|| knownModel?.abilities?.reasoning
|| false,
vision:
model.description.includes('vision') ||
model.description.includes('multimodal') ||
model.id.includes('vision'),
model.description.includes('vision')
|| model.description.includes('multimodal')
|| model.id.includes('vision')
|| knownModel?.abilities?.vision
|| false,
};
},
},
Expand Down
Loading