Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style: Add capability inference for web search, image output and video recognition in model parsing and update UI form items to support search, imageOutput and video abilities (#9022)

bbbugg4e445690f164
diff --git a/packages/database/src/repositories/aiInfra/index.test.ts b/packages/database/src/repositories/aiInfra/index.test.ts
index b5a1277a9c1..2c3a380ac43 100644
--- a/packages/database/src/repositories/aiInfra/index.test.ts
+++ b/packages/database/src/repositories/aiInfra/index.test.ts
@@ -298,6 +298,127 @@ describe('AiInfraRepos', () => {
const disabledModels = result.filter((model) => !model.enabled);
expect(disabledModels.length).toBeGreaterThan(0);
});
+
+ it('should allow search=true and add searchImpl=params when user enables it without providing settings (builtin has no search and no settings)', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ] as AiProviderListItem[];
+
+ // User explicitly enables search but provides no settings field
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: true },
+ // no settings on user model
+ };
+
+ // Builtin does NOT have search capability and thus no settings
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([
+ {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: false },
+ // no settings since builtin search is false
+ },
+ ]);
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find(
+ (m) => m.id === 'gpt-4' && m.providerId === 'openai' && m.type === 'chat',
+ );
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toMatchObject({ search: true });
+ // settings should remain undefined because builtin had none and user never has settings
+ expect(merged?.settings).toEqual({ searchImpl: 'params' });
+ });
+
+ it('should remove builtin rearch settings and disable search when user turns search off', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'openai', name: 'OpenAI', source: 'builtin' as const },
+ ] as AiProviderListItem[];
+
+ // User explicitly disables search and provides no settings field
+ const userModel: EnabledAiModel = {
+ id: 'gpt-4',
+ providerId: 'openai',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: false },
+ // no settings on user model
+ };
+
+ const builtinSettings = { searchImpl: 'tool' as const };
+
+ // Builtin has search capability and corresponding settings
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([
+ {
+ id: 'gpt-4',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: true },
+ settings: builtinSettings,
+ },
+ ]);
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([userModel]);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find(
+ (m) => m.id === 'gpt-4' && m.providerId === 'openai' && m.type === 'chat',
+ );
+ expect(merged).toBeDefined();
+ // User's choice takes precedence
+ expect(merged?.abilities).toMatchObject({ search: false });
+ // Builtin settings are preserved on the merged model
+ expect(merged?.settings).toBeUndefined();
+ });
+
+ it('should set search=true and settings=params for custom provider when user enables search and builtin has no search/settings', async () => {
+ const mockProviders = [
+ { enabled: true, id: 'custom', name: 'Custom Provider', source: 'custom' as const },
+ ] as AiProviderListItem[];
+
+ // Builtin (preset) has the model but without search and without settings
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue([
+ {
+ id: 'my-model',
+ enabled: true,
+ type: 'chat' as const,
+ abilities: { search: false },
+ // no settings
+ } as any,
+ ]);
+
+ // User explicitly enables search; user models do not carry settings
+ vi.spyOn(repo.aiModelModel, 'getAllModels').mockResolvedValue([
+ {
+ id: 'my-model',
+ providerId: 'custom',
+ enabled: true,
+ type: 'chat',
+ abilities: { search: true },
+ } as EnabledAiModel,
+ ]);
+
+ vi.spyOn(repo, 'getAiProviderList').mockResolvedValue(mockProviders);
+
+ const result = await repo.getEnabledModels();
+
+ const merged = result.find((m) => m.id === 'my-model' && m.providerId === 'custom');
+ expect(merged).toBeDefined();
+ expect(merged?.abilities).toMatchObject({ search: true });
+ // For custom provider, when user enables search with no builtin settings, default to 'params'
+ expect(merged?.settings).toEqual({ searchImpl: 'params' });
+ });
});
describe('getAiProviderModelList', () => {
@@ -380,6 +501,119 @@ describe('AiInfraRepos', () => {
expect(result).toHaveLength(0);
});
+
+ // New tests for getAiProviderModelList per the corrected behavior
+ it('should allow search=true and add searchImpl=params when user enables it without providing settings (builtin has no search and no settings)', async () => {
+ const providerId = 'openai';
+
+ // User explicitly enables search in custom model, but provides no settings
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true },
+ // user never has settings
+ } as any,
+ ];
+
+ // Builtin has no search and no settings
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false },
+ // no settings
+ } as any,
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ expect(merged.abilities).toMatchObject({ search: true });
+ // when user enables search with no settings, default searchImpl should be 'params'
+ expect(merged.settings).toEqual({ searchImpl: 'params' });
+ });
+
+ it('should remove builtin search settings and disable search when user turns search off', async () => {
+ const providerId = 'openai';
+
+ // User explicitly disables search in custom model, and provides no settings
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false },
+ // user never has settings
+ } as any,
+ ];
+
+ // Builtin has search with settings
+ const builtinModels: AiProviderModelListItem[] = [
+ {
+ id: 'gpt-4',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true },
+ settings: { searchImpl: 'tool' },
+ } as any,
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(builtinModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'gpt-4');
+ expect(merged).toBeDefined();
+ // User's choice takes precedence
+ expect(merged.abilities).toMatchObject({ search: false });
+ // Builtin search settings should be removed since user turned search off
+ expect(merged.settings).toBeUndefined();
+ });
+
+ it('should set search=true and settings=params for custom provider when user enables search and builtin has no search/settings', async () => {
+ const providerId = 'custom';
+
+ // User list: model with search enabled, but no settings
+ const userModels: AiProviderModelListItem[] = [
+ {
+ id: 'my-model',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: true },
+ // user never has settings
+ } as any,
+ ];
+
+ // Default list: same model without search and without settings
+ const defaultModels: AiProviderModelListItem[] = [
+ {
+ id: 'my-model',
+ type: 'chat',
+ enabled: true,
+ abilities: { search: false },
+ // no settings
+ } as any,
+ ];
+
+ vi.spyOn(repo.aiModelModel, 'getModelListByProviderId').mockResolvedValue(userModels);
+ vi.spyOn(repo as any, 'fetchBuiltinModels').mockResolvedValue(defaultModels);
+
+ const result = await repo.getAiProviderModelList(providerId);
+
+ const merged = result.find((m) => m.id === 'my-model') as any;
+ expect(merged).toBeDefined();
+ expect(merged.abilities).toMatchObject({ search: true });
+ // For custom provider, when user enables search with no builtin settings, default to 'params'
+ expect(merged.settings).toEqual({ searchImpl: 'params' });
+ });
});
describe('getAiProviderRuntimeState', () => {
diff --git a/packages/database/src/repositories/aiInfra/index.ts b/packages/database/src/repositories/aiInfra/index.ts
index e05443305de..99b83930874 100644
--- a/packages/database/src/repositories/aiInfra/index.ts
+++ b/packages/database/src/repositories/aiInfra/index.ts
@@ -23,6 +23,97 @@ import { LobeChatDatabase } from '../../type';
type DecryptUserKeyVaults = (encryptKeyVaultsStr: string | null) => Promise<any>;
+/**
+ * Provider 级默认表(只在本地内置模型没给出 settings.searchImpl 和 settings.searchProvider 时使用)
+ * 注意:不在 DB 存储,纯读取时注入
+ */
+const PROVIDER_SEARCH_DEFAULTS: Record<
+ string,
+ { searchImpl?: 'tool' | 'params' | 'internal'; searchProvider?: string }
+> = {
+ ai360: { searchImpl: 'params' },
+ aihubmix: { searchImpl: 'params' },
+ anthropic: { searchImpl: 'params' },
+ baichuan: { searchImpl: 'params' },
+ default: { searchImpl: 'params' },
+ google: { searchImpl: 'params', searchProvider: 'google' },
+ hunyuan: { searchImpl: 'params' },
+ jina: { searchImpl: 'internal' },
+ minimax: { searchImpl: 'params' },
+ // openai: 默认 params,但对 -search- 型号做 internal 特判
+ openai: { searchImpl: 'params' },
+ // perplexity: 默认 internal
+ perplexity: { searchImpl: 'internal' },
+ qwen: { searchImpl: 'params' },
+ spark: { searchImpl: 'params' }, // 某些模型(如 max-32k)若内置标了 internal,会优先使用内置
+ stepfun: { searchImpl: 'params' },
+ vertexai: { searchImpl: 'params', searchProvider: 'google' },
+ wenxin: { searchImpl: 'params' },
+ xai: { searchImpl: 'params' },
+ zhipu: { searchImpl: 'params' },
+};
+
+// 特殊模型配置 - 模型级别的特殊设置会覆盖服务商默认配置
+const MODEL_SEARCH_DEFAULTS: Record<
+ string,
+ Record<string, { searchImpl?: 'tool' | 'params' | 'internal'; searchProvider?: string }>
+> = {
+ openai: {
+ 'gpt-4o-mini-search-preview': { searchImpl: 'internal' },
+ 'gpt-4o-search-preview': { searchImpl: 'internal' },
+ // 可在此处添加其他特殊模型配置
+ },
+ spark: {
+ 'max-32k': { searchImpl: 'internal' },
+ },
+ // 可在此处添加其他服务商的特殊模型配置
+};
+
+// 根据 providerId + modelId 推断默认 settings
+const inferProviderSearchDefaults = (
+ providerId: string | undefined,
+ modelId: string,
+): { searchImpl?: 'tool' | 'params' | 'internal'; searchProvider?: string } => {
+ const modelSpecificConfig = providerId ? MODEL_SEARCH_DEFAULTS[providerId]?.[modelId] : undefined;
+ if (modelSpecificConfig) {
+ return modelSpecificConfig;
+ }
+
+ return (providerId && PROVIDER_SEARCH_DEFAULTS[providerId]) || PROVIDER_SEARCH_DEFAULTS.default;
+};
+
+// 仅在读取时注入 settings; 根据 abilities.search 来添加或删去settings 中的 search 相关字段
+const injectSearchSettings = (providerId: string, item: any) => {
+ const abilities = item?.abilities || {};
+
+ // 模型未开启搜索能力:移除 settings 中的 search 相关字段,确保 UI 不显示启用模型内置搜索
+ if (abilities.search !== true) {
+ if (item?.settings?.searchImpl || item?.settings?.searchProvider) {
+ const next = { ...item } as any;
+ if (next.settings) {
+ const { searchImpl, searchProvider, ...restSettings } = next.settings;
+ next.settings = Object.keys(restSettings).length > 0 ? restSettings : undefined;
+ }
+ return next;
+ }
+ return item;
+ }
+
+ // 内置(本地)模型如果已经带了任一字段,直接保留,不覆盖
+ if (item?.settings?.searchImpl || item?.settings?.searchProvider) return item;
+
+ // 否则按 providerId + modelId
+ const searchSettings = inferProviderSearchDefaults(providerId, item.id);
+
+ return {
+ ...item,
+ settings: {
+ ...item.settings,
+ ...searchSettings,
+ },
+ };
+};
+
export class AiInfraRepos {
private userId: string;
private db: LobeChatDatabase;
@@ -107,6 +198,7 @@ export class AiInfraRepos {
.map<EnabledAiModel & { enabled?: boolean | null }>((item) => {
const user = allModels.find((m) => m.id === item.id && m.providerId === provider.id);
+ // 用户未修改本地模型
if (!user)
return {
...item,
@@ -114,7 +206,7 @@ export class AiInfraRepos {
providerId: provider.id,
};
- return {
+ const mergedModel = {
...item,
abilities: !isEmpty(user.abilities) ? user.abilities : item.abilities || {},
config: !isEmpty(user.config) ? user.config : item.config,
@@ -130,6 +222,7 @@ export class AiInfraRepos {
sort: user.sort || undefined,
type: user.type || item.type,
};
+ return injectSearchSettings(provider.id, mergedModel); // 用户修改本地模型,检查搜索设置
})
.filter((item) => (filterEnabled ? item.enabled : true));
},
@@ -137,13 +230,16 @@ export class AiInfraRepos {
);
const enabledProviderIds = new Set(enabledProviders.map((item) => item.id));
-
- return [
- ...builtinModelList.flat(),
- ...allModels.filter((item) =>
+ // 用户数据库模型,检查搜索设置
+ const appendedUserModels = allModels
+ .filter((item) =>
filterEnabled ? enabledProviderIds.has(item.providerId) && item.enabled : true,
- ),
- ].sort((a, b) => (a?.sort || -1) - (b?.sort || -1)) as EnabledAiModel[];
+ )
+ .map((item) => injectSearchSettings(item.providerId, item));
+
+ return [...builtinModelList.flat(), ...appendedUserModels].sort(
+ (a, b) => (a?.sort || -1) - (b?.sort || -1),
+ ) as EnabledAiModel[];
};
getAiProviderRuntimeState = async (
@@ -181,8 +277,10 @@ export class AiInfraRepos {
const defaultModels: AiProviderModelListItem[] =
(await this.fetchBuiltinModels(providerId)) || [];
+ // 这里不修改搜索设置不影响使用,但是为了get数据统一
+ const mergedModel = mergeArrayById(defaultModels, aiModels) as AiProviderModelListItem[];
- return mergeArrayById(defaultModels, aiModels) as AiProviderModelListItem[];
+ return mergedModel.map((m) => injectSearchSettings(providerId, m));
};
/**
diff --git a/packages/model-bank/src/types/aiModel.ts b/packages/model-bank/src/types/aiModel.ts
index f5af4e899f6..592ac79b433 100644
--- a/packages/model-bank/src/types/aiModel.ts
+++ b/packages/model-bank/src/types/aiModel.ts
@@ -63,8 +63,10 @@ export interface ModelAbilities {
const AiModelAbilitiesSchema = z.object({
// files: z.boolean().optional(),
functionCall: z.boolean().optional(),
+ imageOutput: z.boolean().optional(),
reasoning: z.boolean().optional(),
search: z.boolean().optional(),
+ video: z.boolean().optional(),
vision: z.boolean().optional(),
});
diff --git a/packages/model-runtime/src/providers/google/index.ts b/packages/model-runtime/src/providers/google/index.ts
index 083c12867f6..3e74f3e44e3 100644
--- a/packages/model-runtime/src/providers/google/index.ts
+++ b/packages/model-runtime/src/providers/google/index.ts
@@ -471,7 +471,7 @@ export class LobeGoogleAI implements LobeRuntimeAI {
const { MODEL_LIST_CONFIGS, processModelList } = await import('../../utils/modelParse');
- return processModelList(processedModels, MODEL_LIST_CONFIGS.google);
+ return processModelList(processedModels, MODEL_LIST_CONFIGS.google, 'google');
} catch (error) {
log('Failed to fetch Google models: %O', error);
throw error;
diff --git a/packages/model-runtime/src/providers/novita/__snapshots__/index.test.ts.snap b/packages/model-runtime/src/providers/novita/__snapshots__/index.test.ts.snap
index 7a1f1301566..a252b100c98 100644
--- a/packages/model-runtime/src/providers/novita/__snapshots__/index.test.ts.snap
+++ b/packages/model-runtime/src/providers/novita/__snapshots__/index.test.ts.snap
@@ -9,6 +9,7 @@ exports[`NovitaAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "meta-llama/llama-3-8b-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -28,7 +29,9 @@ exports[`NovitaAI > models > should get models 1`] = `
},
"reasoning": false,
"releasedAt": "2024-04-25",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -38,6 +41,7 @@ exports[`NovitaAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "meta-llama/llama-3-70b-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -57,7 +61,9 @@ exports[`NovitaAI > models > should get models 1`] = `
},
"reasoning": false,
"releasedAt": "2024-04-25",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -67,6 +73,7 @@ exports[`NovitaAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "meta-llama/llama-3.1-8b-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -86,7 +93,9 @@ exports[`NovitaAI > models > should get models 1`] = `
},
"reasoning": false,
"releasedAt": "2024-07-24",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -96,6 +105,7 @@ exports[`NovitaAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "meta-llama/llama-3.1-70b-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -115,7 +125,9 @@ exports[`NovitaAI > models > should get models 1`] = `
},
"reasoning": false,
"releasedAt": "2024-07-24",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -125,6 +137,7 @@ exports[`NovitaAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "meta-llama/llama-3.1-405b-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -144,7 +157,9 @@ exports[`NovitaAI > models > should get models 1`] = `
},
"reasoning": false,
"releasedAt": "2024-07-24",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -155,6 +170,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "google/gemma-2-9b-it",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -174,7 +190,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-07-18",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -184,6 +202,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "jondurbin/airoboros-l2-70b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -203,7 +222,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-07-17",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -213,6 +234,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "nousresearch/hermes-2-pro-llama-3-8b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -232,7 +254,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-06-27",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -242,6 +266,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "mistralai/mistral-7b-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -261,7 +286,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-06-27",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -271,6 +298,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "cognitivecomputations/dolphin-mixtral-8x22b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -290,7 +318,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-06-27",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -300,6 +330,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "sao10k/l3-70b-euryale-v2.1",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -319,7 +350,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-06-18",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -329,6 +362,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "sophosympatheia/midnight-rose-70b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -348,7 +382,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-06-17",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -358,6 +394,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "gryphe/mythomax-l2-13b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -377,7 +414,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-04-25",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -387,6 +426,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "nousresearch/nous-hermes-llama2-13b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -406,7 +446,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-04-25",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -416,6 +458,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "Nous-Hermes-2-Mixtral-8x7B-DPO",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -435,7 +478,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-04-25",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -445,6 +490,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "lzlv_70b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -464,7 +510,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-04-25",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -474,6 +522,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "teknium/openhermes-2.5-mistral-7b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -493,7 +542,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-04-24",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -503,6 +554,7 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
"enabled": false,
"functionCall": false,
"id": "microsoft/wizardlm-2-8x22b",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": {
"units": [
@@ -522,7 +574,9 @@ Designed for a wide variety of tasks, it empowers developers and researchers to
},
"reasoning": false,
"releasedAt": "2024-04-24",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
]
diff --git a/packages/model-runtime/src/providers/openai/__snapshots__/index.test.ts.snap b/packages/model-runtime/src/providers/openai/__snapshots__/index.test.ts.snap
index 37f79299ee3..80b3476e3d1 100644
--- a/packages/model-runtime/src/providers/openai/__snapshots__/index.test.ts.snap
+++ b/packages/model-runtime/src/providers/openai/__snapshots__/index.test.ts.snap
@@ -9,11 +9,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "whisper-1",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-02-27",
+ "search": false,
"type": "stt",
+ "video": false,
"vision": false,
},
{
@@ -23,11 +26,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "davinci-002",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-08-21",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -37,11 +43,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-3.5-turbo",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-02-28",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -51,6 +60,7 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "dall-e-2",
+ "imageOutput": false,
"maxOutput": undefined,
"parameters": {
"imageUrl": {
@@ -71,7 +81,9 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-01",
+ "search": false,
"type": "image",
+ "video": false,
"vision": false,
},
{
@@ -81,11 +93,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-3.5-turbo-16k",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-05-10",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -95,11 +110,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "tts-1-hd-1106",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-03",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -109,11 +127,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "tts-1-hd",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-03",
+ "search": false,
"type": "tts",
+ "video": false,
"vision": false,
},
{
@@ -123,11 +144,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-3.5-turbo-16k-0613",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-05-30",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -137,11 +161,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "text-embedding-3-large",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2024-01-22",
+ "search": false,
"type": "embedding",
+ "video": false,
"vision": false,
},
{
@@ -151,11 +178,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-4-1106-vision-preview",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2024-03-26",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -165,11 +195,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-3.5-turbo-instruct-0914",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-09-07",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -179,11 +212,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-4-0125-preview",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2024-01-23",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -193,11 +229,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-4-turbo-preview",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2024-01-23",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -207,11 +246,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-3.5-turbo-instruct",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-08-24",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -221,11 +263,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-3.5-turbo-0301",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-03-01",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -235,11 +280,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-3.5-turbo-0613",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-06-12",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -249,11 +297,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "tts-1",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-04-19",
+ "search": false,
"type": "tts",
+ "video": false,
"vision": false,
},
{
@@ -263,6 +314,7 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "dall-e-3",
+ "imageOutput": false,
"maxOutput": undefined,
"parameters": {
"prompt": {
@@ -287,7 +339,9 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-10-31",
+ "search": false,
"type": "image",
+ "video": false,
"vision": false,
},
{
@@ -297,11 +351,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-3.5-turbo-1106",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-02",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -311,11 +368,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-4-1106-preview",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-02",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -325,11 +385,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "babbage-002",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-08-21",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -339,11 +402,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "tts-1-1106",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-03",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -353,11 +419,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "gpt-4-vision-preview",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-11-02",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": true,
},
{
@@ -367,11 +436,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "text-embedding-3-small",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2024-01-22",
+ "search": false,
"type": "embedding",
+ "video": false,
"vision": false,
},
{
@@ -381,11 +453,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-4",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-06-27",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -395,11 +470,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": false,
"id": "text-embedding-ada-002",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2022-12-16",
+ "search": false,
"type": "embedding",
+ "video": false,
"vision": false,
},
{
@@ -409,11 +487,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-3.5-turbo-0125",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2024-01-23",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
{
@@ -423,11 +504,14 @@ exports[`LobeOpenAI > models > should get models 1`] = `
"enabled": false,
"functionCall": true,
"id": "gpt-4-0613",
+ "imageOutput": false,
"maxOutput": undefined,
"pricing": undefined,
"reasoning": false,
"releasedAt": "2023-06-12",
+ "search": false,
"type": "chat",
+ "video": false,
"vision": false,
},
]
diff --git a/packages/model-runtime/src/utils/modelParse.test.ts b/packages/model-runtime/src/utils/modelParse.test.ts
index 0e5b27ac197..b3ecd82cc7f 100644
--- a/packages/model-runtime/src/utils/modelParse.test.ts
+++ b/packages/model-runtime/src/utils/modelParse.test.ts
@@ -99,6 +99,14 @@ const mockDefaultModelList: (Partial<ChatModelCard> & { id: string })[] = [
// Mock the import
vi.mock('model-bank', () => ({
LOBE_DEFAULT_MODEL_LIST: mockDefaultModelList,
+ // 新增 provider 专用清单,供 findKnownModelByProvider 使用
+ google: [
+ {
+ id: 'gemini-2.5-pro',
+ displayName: 'Gemini 2.5 Pro',
+ abilities: { search: true, functionCall: true, reasoning: true, vision: true },
+ },
+ ],
}));
describe('modelParse', () => {
@@ -151,6 +159,14 @@ describe('modelParse', () => {
});
});
+ // New sanity tests for your added config
+ describe('MODEL_LIST_CONFIGS sanity', () => {
+ it('google.imageOutputKeywords should include "-image-" for image-output capability inference', () => {
+ expect(MODEL_LIST_CONFIGS.google.imageOutputKeywords).toBeDefined();
+ expect(MODEL_LIST_CONFIGS.google.imageOutputKeywords).toContain('-image-');
+ });
+ });
+
describe('processModelList', () => {
it('should process a list of models with the given provider config', async () => {
const modelList = [{ id: 'gpt-4o' }, { id: 'gpt-3.5-turbo' }];
@@ -220,6 +236,52 @@ describe('modelParse', () => {
expect(Array.isArray(result)).toBe(true);
});
+ // New search & imageOutput focused tests for single provider path
+ describe('search and imageOutput (processModelList)', () => {
+ it('openai: default search keywords should make "*-search" models support search', async () => {
+ // openai config does not define searchKeywords, so DEFAULT_SEARCH_KEYWORDS ['-search'] applies
+ const out = await processModelList([{ id: 'gpt-4o-search' }], MODEL_LIST_CONFIGS.openai, 'openai');
+ expect(out).toHaveLength(1);
+ expect(out[0].search).toBe(true);
+ });
+
+ it('openai: models without "-search" should not get search by default', async () => {
+ const out = await processModelList([{ id: 'gpt-4o' }], MODEL_LIST_CONFIGS.openai, 'openai');
+ expect(out).toHaveLength(1);
+ expect(out[0].search).toBe(false);
+ });
+
+ it('openai: "-search" models with excluded keywords (audio) should not get search', async () => {
+ const out = await processModelList(
+ [{ id: 'gpt-4o-search-audio' }],
+ MODEL_LIST_CONFIGS.openai,
+ 'openai',
+ );
+ expect(out).toHaveLength(1);
+ expect(out[0].search).toBe(false);
+ });
+
+ it('google: gemini-* with "-image-" in id should infer imageOutput=true via keywords and remain chat type', async () => {
+ const out = await processModelList(
+ [{ id: 'gemini-2.5-image-pro' }],
+ MODEL_LIST_CONFIGS.google,
+ 'google',
+ );
+ expect(out).toHaveLength(1);
+ expect(out[0].imageOutput).toBe(true);
+ // due to '!gemini' exclusion in IMAGE_MODEL_KEYWORDS
+ expect(out[0].type).toBe('chat');
+ });
+
+ it('google: gemini-* without "-image-" should not infer imageOutput and get search=true via known google model', async () => {
+ const out = await processModelList([{ id: 'gemini-2.5-pro' }], MODEL_LIST_CONFIGS.google, 'google');
+ expect(out).toHaveLength(1);
+ expect(out[0].displayName).toBe('Gemini 2.5 Pro');
+ expect(out[0].search).toBe(true);
+ expect(out[0].imageOutput).toBe(false);
+ });
+ });
+
describe('Detailed capability and property processing in processModelList', () => {
const config = MODEL_LIST_CONFIGS.openai;
@@ -411,6 +473,47 @@ describe('modelParse', () => {
expect(model.reasoning).toBe(true); // 从 knownModel.abilities.reasoning
});
+ // New search & imageOutput focused tests for multi-provider path
+ describe('search and imageOutput (processMultiProviderModelList)', () => {
+ it('non-google provider gemini-2.5-pro should still get search=true via known google model', async () => {
+ // Simulate a mixed/custom list. Even if called with providerid='openai',
+ // detectModelProvider('gemini-2.5-pro') => 'google'
+ // knownModel (google list) has abilities.search=true, so final search=true
+ const out = await processMultiProviderModelList([{ id: 'gemini-2.5-pro' }], 'openai');
+ expect(out).toHaveLength(1);
+ const m = out[0];
+ expect(m.id).toBe('gemini-2.5-pro');
+ expect(m.displayName).toBe('Gemini 2.5 Pro');
+ expect(m.search).toBe(true);
+ });
+
+ it('default search keywords should make "*-search" models support search', async () => {
+ const out = await processMultiProviderModelList([{ id: 'gpt-4o-search'}]);
+ expect(out).toHaveLength(1);
+ expect(out[0].search).toBe(true);
+ });
+
+ it('google: gemini-* with "-image-" in id should infer imageOutput=true via keywords', async () => {
+ const out = await processMultiProviderModelList([{ id: 'gemini-2.5-image-pro' }]);
+ expect(out).toHaveLength(1);
+ expect(out[0].imageOutput).toBe(true);
+ // and still a chat model due to "!gemini" image-type exclusion
+ expect(out[0].type).toBe('chat');
+ });
+
+ it('openai: "-search" + "audio" should be suppressed by excludeKeywords', async () => {
+ const out = await processMultiProviderModelList([{ id: 'gpt-4o-search-audio' }], 'openai');
+ expect(out).toHaveLength(1);
+ expect(out[0].search).toBe(false);
+ });
+
+ it('google: gemini-* without "-image-" should not infer imageOutput', async () => {
+ const out = await processMultiProviderModelList([{ id: 'gemini-2.5-pro' }]);
+ expect(out).toHaveLength(1);
+ expect(out[0].imageOutput).toBe(false);
+ });
+ });
+
describe('Extended tests for detectModelProvider', () => {
it('should handle unusual casing patterns', () => {
expect(detectModelProvider('gPt-4')).toBe('openai');
diff --git a/packages/model-runtime/src/utils/modelParse.ts b/packages/model-runtime/src/utils/modelParse.ts
index 1b9d18ac6d6..5afffda3b3b 100644
--- a/packages/model-runtime/src/utils/modelParse.ts
+++ b/packages/model-runtime/src/utils/modelParse.ts
@@ -6,10 +6,16 @@ import type { ModelProviderKey } from '../types';
export interface ModelProcessorConfig {
excludeKeywords?: readonly string[]; // 对符合的模型不添加标签
functionCallKeywords?: readonly string[];
+ imageOutputKeywords?: readonly string[];
reasoningKeywords?: readonly string[];
+ searchKeywords?: readonly string[];
+ videoKeywords?: readonly string[];
visionKeywords?: readonly string[];
}
+// 默认关键字:任意包含 -search 的模型 ID 视为支持联网搜索
+const DEFAULT_SEARCH_KEYWORDS = ['-search'] as const;
+
// 模型能力标签关键词配置
export const MODEL_LIST_CONFIGS = {
anthropic: {
@@ -22,8 +28,12 @@ export const MODEL_LIST_CONFIGS = {
reasoningKeywords: ['r1', 'deepseek-reasoner', 'v3.1', 'v3.2'],
},
google: {
- functionCallKeywords: ['gemini'],
- reasoningKeywords: ['thinking', '-2.5-'],
+ excludeKeywords: ['tts'],
+ functionCallKeywords: ['gemini', '!-image-'],
+ imageOutputKeywords: ['-image-'],
+ reasoningKeywords: ['thinking', '-2.5-', '!-image-'],
+ searchKeywords: ['-search', '!-image-'],
+ videoKeywords: ['-2.5-', '!-image-'],
visionKeywords: ['gemini', 'learnlm'],
},
inclusionai: {
@@ -290,6 +300,44 @@ const processDisplayName = (displayName: string): string => {
return displayName;
};
+/**
+ * 获取模型提供商的本地配置
+ * @param provider 模型提供商
+ * @returns 模型提供商的本地配置
+ */
+const getProviderLocalConfig = async (provider?: ModelProviderKey): Promise<any[] | null> => {
+ let providerLocalConfig: any[] | null = null;
+ if (provider) {
+ try {
+ const modules = await import('model-bank');
+
+ providerLocalConfig = modules[provider];
+ } catch {
+ // 如果配置文件不存在或导入失败,保持为 null
+ providerLocalConfig = null;
+ }
+ }
+ return providerLocalConfig;
+};
+
+/**
+ * 获取模型本地配置
+ * @param providerLocalConfig 模型提供商的本地配置
+ * @param model 模型对象
+ * @returns 模型本地配置
+ */
+const getModelLocalEnableConfig = (
+ providerLocalConfig: any[],
+ model: { id: string },
+): any | null => {
+ // 如果提供了 providerid 且有本地配置,尝试从中获取模型的 enabled 状态
+ let providerLocalModelConfig = null;
+ if (providerLocalConfig && Array.isArray(providerLocalConfig)) {
+ providerLocalModelConfig = providerLocalConfig.find((m) => m.id === model.id);
+ }
+ return providerLocalModelConfig;
+};
+
/**
* 处理模型卡片的通用逻辑
*/
@@ -303,6 +351,9 @@ const processModelCard = (
visionKeywords = [],
reasoningKeywords = [],
excludeKeywords = [],
+ searchKeywords = DEFAULT_SEARCH_KEYWORDS,
+ imageOutputKeywords = [],
+ videoKeywords = [],
} = config;
const isExcludedModel = isKeywordListMatch(model.id.toLowerCase(), excludeKeywords);
@@ -315,9 +366,9 @@ const processModelCard = (
)
? 'image'
: isKeywordListMatch(
- model.id.toLowerCase(),
- EMBEDDING_MODEL_KEYWORDS.map((k) => k.toLowerCase()),
- )
+ model.id.toLowerCase(),
+ EMBEDDING_MODEL_KEYWORDS.map((k) => k.toLowerCase()),
+ )
? 'embedding'
: 'chat');
@@ -393,18 +444,32 @@ const processModelCard = (
((isKeywordListMatch(model.id.toLowerCase(), functionCallKeywords) && !isExcludedModel) ||
false),
id: model.id,
+ imageOutput:
+ model.imageOutput ??
+ knownModel?.abilities?.imageOutput ??
+ ((isKeywordListMatch(model.id.toLowerCase(), imageOutputKeywords) && !isExcludedModel) ||
+ false),
maxOutput: model.maxOutput ?? knownModel?.maxOutput ?? undefined,
pricing: formatPricing(model?.pricing) ?? undefined,
reasoning:
model.reasoning ??
knownModel?.abilities?.reasoning ??
- (isKeywordListMatch(model.id.toLowerCase(), reasoningKeywords) || false),
+ ((isKeywordListMatch(model.id.toLowerCase(), reasoningKeywords) && !isExcludedModel) ||
+ false),
releasedAt: processReleasedAt(model, knownModel),
+ search:
+ model.search ??
+ knownModel?.abilities?.search ??
+ ((isKeywordListMatch(model.id.toLowerCase(), searchKeywords) && !isExcludedModel) || false),
type: modelType,
// current, only image model use the parameters field
...(modelType === 'image' && {
parameters: model.parameters ?? knownModel?.parameters,
}),
+ video:
+ model.video ??
+ knownModel?.abilities?.video ??
+ ((isKeywordListMatch(model.id.toLowerCase(), videoKeywords) && !isExcludedModel) || false),
vision:
model.vision ??
knownModel?.abilities?.vision ??
@@ -416,7 +481,7 @@ const processModelCard = (
* 处理单一提供商的模型列表
* @param modelList 模型列表
* @param config 提供商配置
- * @param provider 提供商类型(可选,用于优先匹配对应的本地配置)
+ * @param provider 提供商类型(可选,用于优先匹配对应的本地配置, 当提供了 provider 时,才会尝试从本地配置覆盖 enabled)
* @returns 处理后的模型卡片列表
*/
export const processModelList = async (
@@ -426,6 +491,9 @@ export const processModelList = async (
): Promise<ChatModelCard[]> => {
const { LOBE_DEFAULT_MODEL_LIST } = await import('model-bank');
+ // 如果提供了 provider,尝试获取该提供商的本地配置
+ const providerLocalConfig = await getProviderLocalConfig(provider as ModelProviderKey);
+
return Promise.all(
modelList.map(async (model) => {
let knownModel: any = null;
@@ -442,7 +510,24 @@ export const processModelList = async (
);
}
- return processModelCard(model, config, knownModel);
+ const processedModel = processModelCard(model, config, knownModel);
+
+ // 如果提供了 provider 且有本地配置,尝试从中获取模型的 enabled 状态
+ const providerLocalModelConfig = getModelLocalEnableConfig(
+ providerLocalConfig as any[],
+ model,
+ );
+
+ // 如果找到了本地配置中的模型,使用其 enabled 状态
+ if (
+ processedModel &&
+ providerLocalModelConfig &&
+ typeof providerLocalModelConfig.enabled === 'boolean'
+ ) {
+ processedModel.enabled = providerLocalModelConfig.enabled;
+ }
+
+ return processedModel;
}),
).then((results) => results.filter((result) => !!result));
};
@@ -460,17 +545,7 @@ export const processMultiProviderModelList = async (
const { LOBE_DEFAULT_MODEL_LIST } = await import('model-bank');
// 如果提供了 providerid,尝试获取该提供商的本地配置
- let providerLocalConfig: any[] | null = null;
- if (providerid) {
- try {
- const modules = await import('model-bank');
-
- providerLocalConfig = modules[providerid];
- } catch {
- // 如果配置文件不存在或导入失败,保持为 null
- providerLocalConfig = null;
- }
- }
+ const providerLocalConfig = await getProviderLocalConfig(providerid);
return Promise.all(
modelList.map(async (model) => {
@@ -488,10 +563,10 @@ export const processMultiProviderModelList = async (
}
// 如果提供了 providerid 且有本地配置,尝试从中获取模型的 enabled 状态
- let providerLocalModelConfig = null;
- if (providerLocalConfig && Array.isArray(providerLocalConfig)) {
- providerLocalModelConfig = providerLocalConfig.find((m) => m.id === model.id);
- }
+ const providerLocalModelConfig = getModelLocalEnableConfig(
+ providerLocalConfig as any[],
+ model,
+ );
const processedModel = processModelCard(model, config, knownModel);
diff --git a/packages/model-runtime/src/utils/postProcessModelList.test.ts b/packages/model-runtime/src/utils/postProcessModelList.test.ts
index 9faeace7b6a..1fe06ffed3b 100644
--- a/packages/model-runtime/src/utils/postProcessModelList.test.ts
+++ b/packages/model-runtime/src/utils/postProcessModelList.test.ts
@@ -175,9 +175,6 @@ describe('postProcessModelList', () => {
enabled: true,
contextWindowTokens: 4096,
description: 'A flash model',
- functionCall: true,
- vision: true,
- reasoning: false,
maxOutput: 2048,
type: 'image',
parameters: {
diff --git a/packages/model-runtime/src/utils/postProcessModelList.ts b/packages/model-runtime/src/utils/postProcessModelList.ts
index 7c48a4e543e..227ee37f463 100644
--- a/packages/model-runtime/src/utils/postProcessModelList.ts
+++ b/packages/model-runtime/src/utils/postProcessModelList.ts
@@ -41,12 +41,25 @@ export async function postProcessModelList(
const matchingModels = finalModels.filter((model) => model.id.endsWith(whitelistPattern));
for (const model of matchingModels) {
+ // Blacklist: remove unnecessary properties, keep the rest
+ const {
+ files, // drop
+ functionCall, // drop
+ reasoning, // drop
+ search, // drop
+ imageOutput, // drop
+ video, // drop
+ vision, // drop
+ type: _dropType, // will be overwritten
+ parameters: _dropParams, // will be overwritten
+ ...rest
+ } = model;
+
imageModels.push({
- ...model, // Reuse all configurations from the original model
+ ...rest, // Keep other fields (such as displayName, pricing, enabled, contextWindowTokens, etc.)
id: `${model.id}:image`,
- // Override to image type
- parameters: CHAT_MODEL_IMAGE_GENERATION_PARAMS,
- type: 'image', // Set image parameters
+ parameters: CHAT_MODEL_IMAGE_GENERATION_PARAMS, // Set image parameters
+ type: 'image', // Override to image type
});
}
}
diff --git a/packages/types/src/llm.ts b/packages/types/src/llm.ts
index 66ace3f2ad4..0fe0da06741 100644
--- a/packages/types/src/llm.ts
+++ b/packages/types/src/llm.ts
@@ -30,6 +30,12 @@ export interface ChatModelCard {
*/
functionCall?: boolean;
id: string;
+
+ /**
+ * whether model supports imageOutput
+ */
+ imageOutput?: boolean;
+
/**
* whether model is custom
*/
@@ -53,8 +59,18 @@ export interface ChatModelCard {
*/
releasedAt?: string;
+ /**
+ * whether model supports search
+ */
+ search?: boolean;
+
type?: AiModelType;
+ /**
+ * whether model supports video
+ */
+ video?: boolean;
+
/**
* whether model supports vision
*/
diff --git a/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx b/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx
index 1567e2f16af..6dfebd9c087 100644
--- a/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx
+++ b/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx
@@ -126,6 +126,31 @@ const ModelConfigForm = memo<ModelConfigFormProps>(
>
<Checkbox />
</Form.Item>
+ <Form.Item
+ extra={t('providerModels.item.modelConfig.search.extra')}
+ label={t('providerModels.item.modelConfig.search.title')}
+ name={['abilities', 'search']}
+ valuePropName={'checked'}
+ >
+ <Checkbox />
+ </Form.Item>
+
+ <Form.Item
+ extra={t('providerModels.item.modelConfig.imageOutput.extra')}
+ label={t('providerModels.item.modelConfig.imageOutput.title')}
+ name={['abilities', 'imageOutput']}
+ valuePropName={'checked'}
+ >
+ <Checkbox />
+ </Form.Item>
+ <Form.Item
+ extra={t('providerModels.item.modelConfig.video.extra')}
+ label={t('providerModels.item.modelConfig.video.title')}
+ name={['abilities', 'video']}
+ valuePropName={'checked'}
+ >
+ <Checkbox />
+ </Form.Item>
<Form.Item
extra={t('providerModels.item.modelConfig.type.extra')}
label={t('providerModels.item.modelConfig.type.title')}
diff --git a/src/features/ChatInput/ActionBar/Search/Controls.tsx b/src/features/ChatInput/ActionBar/Search/Controls.tsx
index 6a93083070d..5e30c270092 100644
--- a/src/features/ChatInput/ActionBar/Search/Controls.tsx
+++ b/src/features/ChatInput/ActionBar/Search/Controls.tsx
@@ -3,7 +3,7 @@ import { GlobeOffIcon } from '@lobehub/ui/icons';
import { Divider } from 'antd';
import { createStyles } from 'antd-style';
import { LucideIcon, SparkleIcon } from 'lucide-react';
-import { memo } from 'react';
+import { memo, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Center, Flexbox } from 'react-layout-kit';
@@ -93,9 +93,12 @@ const Item = memo<NetworkOption>(({ value, description, icon, label }) => {
const Controls = memo(() => {
const { t } = useTranslation('chat');
- const [model, provider] = useAgentStore((s) => [
+ const [model, provider, useModelBuiltinSearch, searchMode, updateAgentChatConfig] = useAgentStore((s) => [
agentSelectors.currentAgentModel(s),
agentSelectors.currentAgentModelProvider(s),
+ agentChatConfigSelectors.useModelBuiltinSearch(s),
+ agentChatConfigSelectors.currentChatConfig(s).searchMode,
+ s.updateAgentChatConfig,
]);
const supportFC = useAiInfraStore(aiModelSelectors.isModelSupportToolUse(model, provider));
@@ -105,24 +108,48 @@ const Controls = memo(() => {
const isModelHasBuiltinSearchConfig = useAiInfraStore(
aiModelSelectors.isModelHasBuiltinSearchConfig(model, provider),
);
+ const isModelBuiltinSearchInternal = useAiInfraStore(
+ aiModelSelectors.isModelBuiltinSearchInternal(model, provider),
+ );
+ const modelBuiltinSearchImpl = useAiInfraStore(aiModelSelectors.modelBuiltinSearchImpl(model, provider));
+
+ useEffect(() => {
+ if (isModelBuiltinSearchInternal && (searchMode ?? 'off') === 'off') {
+ updateAgentChatConfig({ searchMode: 'auto' });
+ }
+ }, [isModelBuiltinSearchInternal, searchMode, updateAgentChatConfig]);
+
+ const options: NetworkOption[] = isModelBuiltinSearchInternal
+ ? [
+ {
+ description: t('search.mode.auto.desc'),
+ icon: SparkleIcon,
+ label: t('search.mode.auto.title'),
+ value: 'auto',
+ },
+ ]
+ : [
+ {
+ description: t('search.mode.off.desc'),
+ icon: GlobeOffIcon,
+ label: t('search.mode.off.title'),
+ value: 'off',
+ },
+ {
+ description: t('search.mode.auto.desc'),
+ icon: SparkleIcon,
+ label: t('search.mode.auto.title'),
+ value: 'auto',
+ },
+ ];
+
+ const showModelBuiltinSearch = !isModelBuiltinSearchInternal &&
+ (isModelHasBuiltinSearchConfig || isProviderHasBuiltinSearchConfig);
+
+ const showFCSearchModel =
+ !supportFC && (!modelBuiltinSearchImpl || (!isModelBuiltinSearchInternal && !useModelBuiltinSearch));
- const options: NetworkOption[] = [
- {
- description: t('search.mode.off.desc'),
- icon: GlobeOffIcon,
- label: t('search.mode.off.title'),
- value: 'off',
- },
- {
- description: t('search.mode.auto.desc'),
- icon: SparkleIcon,
- label: t('search.mode.auto.title'),
- value: 'auto',
- },
- ];
-
- const showDivider = isModelHasBuiltinSearchConfig || !supportFC;
- const showModelBuiltinSearch = isModelHasBuiltinSearchConfig || isProviderHasBuiltinSearchConfig;
+ const showDivider = showModelBuiltinSearch || showFCSearchModel;
return (
<Flexbox gap={4}>
@@ -131,7 +158,7 @@ const Controls = memo(() => {
))}
{showDivider && <Divider style={{ margin: 0 }} />}
{showModelBuiltinSearch && <ModelBuiltinSearch />}
- {!supportFC && <FCSearchModel />}
+ {showFCSearchModel && <FCSearchModel />}
</Flexbox>
);
});
diff --git a/src/helpers/getSearchConfig.test.ts b/src/helpers/getSearchConfig.test.ts
index 296c3a07069..fc24f8ad9e9 100644
--- a/src/helpers/getSearchConfig.test.ts
+++ b/src/helpers/getSearchConfig.test.ts
@@ -26,6 +26,7 @@ vi.mock('@/store/aiInfra/selectors', () => ({
},
aiModelSelectors: {
isModelHasBuiltinSearch: vi.fn(),
+ isModelBuiltinSearchInternal: vi.fn(),
},
}));
@@ -49,6 +50,9 @@ describe('getSearchConfig', () => {
vi.mocked(aiInfraSelectors.aiModelSelectors.isModelHasBuiltinSearch).mockReturnValue(
() => false,
);
+ vi.mocked(aiInfraSelectors.aiModelSelectors.isModelBuiltinSearchInternal).mockReturnValue(
+ () => false,
+ );
const result = getSearchConfig(model, provider);
@@ -71,6 +75,7 @@ describe('getSearchConfig', () => {
expect(result.enabledSearch).toBe(false);
expect(result.useApplicationBuiltinSearchTool).toBe(false);
+ expect(result.useModelSearch).toBe(false);
});
it('should prefer model search when available and enabled', () => {
@@ -85,6 +90,9 @@ describe('getSearchConfig', () => {
vi.mocked(aiInfraSelectors.aiModelSelectors.isModelHasBuiltinSearch).mockReturnValue(
() => false,
);
+ vi.mocked(aiInfraSelectors.aiModelSelectors.isModelBuiltinSearchInternal).mockReturnValue(
+ () => false,
+ );
const result = getSearchConfig(model, provider);
@@ -109,6 +117,9 @@ describe('getSearchConfig', () => {
vi.mocked(aiInfraSelectors.aiModelSelectors.isModelHasBuiltinSearch).mockReturnValue(
() => true,
);
+ vi.mocked(aiInfraSelectors.aiModelSelectors.isModelBuiltinSearchInternal).mockReturnValue(
+ () => false,
+ );
const result = getSearchConfig(model, provider);
@@ -133,6 +144,9 @@ describe('getSearchConfig', () => {
vi.mocked(aiInfraSelectors.aiModelSelectors.isModelHasBuiltinSearch).mockReturnValue(
() => true,
);
+ vi.mocked(aiInfraSelectors.aiModelSelectors.isModelBuiltinSearchInternal).mockReturnValue(
+ () => false,
+ );
const result = getSearchConfig(model, provider);
@@ -144,4 +158,31 @@ describe('getSearchConfig', () => {
useApplicationBuiltinSearchTool: true,
});
});
+
+ it('should force use model search when searchImpl is internal', () => {
+ vi.mocked(agentSelectors.agentChatConfigSelectors.currentChatConfig).mockReturnValue({
+ searchMode: 'on',
+ useModelBuiltinSearch: false,
+ } as any);
+
+ vi.mocked(aiInfraSelectors.aiProviderSelectors.isProviderHasBuiltinSearch).mockReturnValue(
+ () => false
+ );
+ vi.mocked(aiInfraSelectors.aiModelSelectors.isModelHasBuiltinSearch).mockReturnValue(
+ () => true
+ );
+ vi.mocked(aiInfraSelectors.aiModelSelectors.isModelBuiltinSearchInternal).mockReturnValue(
+ () => true
+ );
+
+ const result = getSearchConfig(model, provider);
+
+ expect(result).toEqual({
+ enabledSearch: true,
+ isProviderHasBuiltinSearch: false,
+ isModelHasBuiltinSearch: true,
+ useModelSearch: true,
+ useApplicationBuiltinSearchTool: false,
+ });
+ });
});
diff --git a/src/helpers/getSearchConfig.ts b/src/helpers/getSearchConfig.ts
index bbb507ecc46..8f9af6f6d73 100644
--- a/src/helpers/getSearchConfig.ts
+++ b/src/helpers/getSearchConfig.ts
@@ -34,10 +34,14 @@ export const getSearchConfig = (model: string, provider: string): SearchConfig =
model,
provider,
)(aiInfraStoreState);
+ const isModelBuiltinSearchInternal = aiModelSelectors.isModelBuiltinSearchInternal(
+ model,
+ provider!,
+ )(aiInfraStoreState);
const useModelSearch =
((isProviderHasBuiltinSearch || isModelHasBuiltinSearch) && chatConfig.useModelBuiltinSearch) ||
- false;
+ isModelBuiltinSearchInternal || false;
const useApplicationBuiltinSearchTool = enabledSearch && !useModelSearch;
diff --git a/src/locales/default/modelProvider.ts b/src/locales/default/modelProvider.ts
index ca4f82b02b1..c4eb527be9d 100644
--- a/src/locales/default/modelProvider.ts
+++ b/src/locales/default/modelProvider.ts
@@ -288,12 +288,22 @@ export default {
placeholder: '请输入模型 id,例如 gpt-4o 或 claude-3.5-sonnet',
title: '模型 ID',
},
+ imageOutput: {
+ extra:
+ '此配置将仅开启模型生成图片的能力,具体效果完全取决于模型本身,请自行测试该模型是否具备可用的图片生成能力',
+ title: '支持图片生成',
+ },
modalTitle: '自定义模型配置',
reasoning: {
extra:
'此配置将仅开启模型深度思考的能力,具体效果完全取决于模型本身,请自行测试该模型是否具备可用的深度思考能力',
title: '支持深度思考',
},
+ search: {
+ extra:
+ '此配置将仅开启模型内置搜索引擎的联网搜索能力,是否支持内置搜索引擎取决于模型本身,请自行测试该模型的内置搜索引擎能力可用性',
+ title: '支持联网搜索',
+ },
tokens: {
extra: '设置模型支持的最大 Token 数',
title: '最大上下文窗口',
@@ -314,6 +324,11 @@ export default {
placeholder: '请选择模型类型',
title: '模型类型',
},
+ video: {
+ extra:
+ '此配置将仅开启应用中的视频识别配置,是否支持识别完全取决于模型本身,请自行测试该模型的视频识别能力可用性',
+ title: '支持视频识别',
+ },
vision: {
extra:
'此配置将仅开启应用中的图片上传配置,是否支持识别完全取决于模型本身,请自行测试该模型的视觉识别能力可用性',
diff --git a/src/store/aiInfra/slices/aiModel/action.ts b/src/store/aiInfra/slices/aiModel/action.ts
index 94284fb6c1c..f4c7399afba 100644
--- a/src/store/aiInfra/slices/aiModel/action.ts
+++ b/src/store/aiInfra/slices/aiModel/action.ts
@@ -79,7 +79,10 @@ export const createAiModelSlice: StateCreator<
abilities: {
files: model.files,
functionCall: model.functionCall,
+ imageOutput: model.imageOutput,
reasoning: model.reasoning,
+ search: model.search,
+ video: model.video,
vision: model.vision,
},
enabled: model.enabled || false,
diff --git a/src/store/aiInfra/slices/aiModel/selectors.ts b/src/store/aiInfra/slices/aiModel/selectors.ts
index fae1d0fb4bb..533a67753be 100644
--- a/src/store/aiInfra/slices/aiModel/selectors.ts
+++ b/src/store/aiInfra/slices/aiModel/selectors.ts
@@ -111,6 +111,12 @@ const isModelHasBuiltinSearch = (id: string, provider: string) => (s: AIProvider
return !!searchImpl;
};
+const isModelBuiltinSearchInternal = (id: string, provider: string) => (s: AIProviderStoreState): boolean => {
+ const searchImpl = modelBuiltinSearchImpl(id, provider)(s);
+
+ return searchImpl === ModelSearchImplement.Internal;
+};
+
const isModelHasBuiltinSearchConfig =
(id: string, provider: string) => (s: AIProviderStoreState) => {
const searchImpl = modelBuiltinSearchImpl(id, provider)(s);
@@ -133,6 +139,7 @@ export const aiModelSelectors = {
getModelCard,
hasRemoteModels,
isEmptyAiProviderModelList,
+ isModelBuiltinSearchInternal,
isModelEnabled,
isModelHasBuiltinSearch,
isModelHasBuiltinSearchConfig,
diff --git a/src/store/chat/slices/aiChat/actions/generateAIChat.ts b/src/store/chat/slices/aiChat/actions/generateAIChat.ts
index 94ef4aa897a..f5ca828c5b3 100644
--- a/src/store/chat/slices/aiChat/actions/generateAIChat.ts
+++ b/src/store/chat/slices/aiChat/actions/generateAIChat.ts
@@ -384,9 +384,13 @@ export const generateAIChat: StateCreator<
model,
provider!,
)(aiInfraStoreState);
+ const isModelBuiltinSearchInternal = aiModelSelectors.isModelBuiltinSearchInternal(
+ model,
+ provider!,
+ )(aiInfraStoreState);
const useModelBuiltinSearch = agentChatConfigSelectors.useModelBuiltinSearch(agentStoreState);
const useModelSearch =
- (isProviderHasBuiltinSearch || isModelHasBuiltinSearch) && useModelBuiltinSearch;
+ ((isProviderHasBuiltinSearch || isModelHasBuiltinSearch) && useModelBuiltinSearch) || isModelBuiltinSearchInternal;
const isAgentEnableSearch = agentChatConfigSelectors.isAgentEnableSearch(agentStoreState);
if (isAgentEnableSearch && !useModelSearch && !isModelSupportToolUse) {
diff --git a/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts b/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts
index a3d01d2bda6..1a6da616fc9 100644
--- a/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts
+++ b/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts
@@ -382,9 +382,13 @@ export const generateAIChatV2: StateCreator<
model,
provider!,
)(aiInfraStoreState);
+ const isModelBuiltinSearchInternal = aiModelSelectors.isModelBuiltinSearchInternal(
+ model,
+ provider!,
+ )(aiInfraStoreState);
const useModelBuiltinSearch = agentChatConfigSelectors.useModelBuiltinSearch(agentStoreState);
const useModelSearch =
- (isProviderHasBuiltinSearch || isModelHasBuiltinSearch) && useModelBuiltinSearch;
+ ((isProviderHasBuiltinSearch || isModelHasBuiltinSearch) && useModelBuiltinSearch) || isModelBuiltinSearchInternal;
const isAgentEnableSearch = agentChatConfigSelectors.isAgentEnableSearch(agentStoreState);
if (isAgentEnableSearch && !useModelSearch && !isModelSupportToolUse) {