From 8e0b6345050961806a2521ebc95debfb8a283158 Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Wed, 8 Jan 2025 17:42:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20provider=20enab?= =?UTF-8?q?led=20issue=20(#5337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/repositories/aiInfra/index.ts | 26 ++++++++++++++----- .../server/models/__tests__/aiModel.test.ts | 10 +++---- src/database/server/models/aiModel.ts | 9 ++++--- src/store/aiInfra/slices/aiProvider/action.ts | 2 +- src/types/aiProvider.ts | 1 + 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/database/repositories/aiInfra/index.ts b/src/database/repositories/aiInfra/index.ts index 94f8964a15179..756af2f8d9689 100644 --- a/src/database/repositories/aiInfra/index.ts +++ b/src/database/repositories/aiInfra/index.ts @@ -69,19 +69,28 @@ export class AiInfraRepos { const providers = await this.getAiProviderList(); const enabledProviders = providers.filter((item) => item.enabled); - const userEnabledModels = await this.aiModelModel.getEnabledModels(); + const allModels = await this.aiModelModel.getAllModels(); + const userEnabledModels = allModels.filter((item) => item.enabled); + const modelList = await pMap( enabledProviders, async (provider) => { const aiModels = await this.fetchBuiltinModels(provider.id); return (aiModels || []) - .filter((i) => i.enabled) - .map((item) => ({ - ...item, - abilities: item.abilities || {}, - providerId: provider.id, - })); + .map((item) => { + const user = allModels.find((m) => m.id === item.id && m.providerId === provider.id); + + const enabled = !!user ? user.enabled : item.enabled; + + return { + ...item, + abilities: item.abilities || {}, + enabled, + providerId: provider.id, + }; + }) + .filter((i) => i.enabled); }, { concurrency: 10 }, ); @@ -100,6 +109,9 @@ export class AiInfraRepos { return mergeArrayById(defaultModels, aiModels) as AiProviderModelListItem[]; }; + /** + * Fetch builtin models from config + */ private fetchBuiltinModels = async ( providerId: string, ): Promise => { diff --git a/src/database/server/models/__tests__/aiModel.test.ts b/src/database/server/models/__tests__/aiModel.test.ts index ddd399886faaf..71d5a9c475c98 100644 --- a/src/database/server/models/__tests__/aiModel.test.ts +++ b/src/database/server/models/__tests__/aiModel.test.ts @@ -193,17 +193,15 @@ describe('AiModelModel', () => { }); }); - describe('getEnabledModels', () => { + describe('getAllModels', () => { it('should only return enabled models', async () => { await serverDB.insert(aiModels).values([ { id: 'model1', providerId: 'openai', enabled: true, source: 'custom', userId }, - { id: 'model2', providerId: 'openai', enabled: false, source: 'custom', userId }, + { id: 'model2', providerId: 'b', enabled: false, source: 'custom', userId }, ]); - const models = await aiProviderModel.getEnabledModels(); - expect(models).toHaveLength(1); - expect(models[0].id).toBe('model1'); - expect(models[0].enabled).toBe(true); + const models = await aiProviderModel.getAllModels(); + expect(models).toHaveLength(2); }); }); diff --git a/src/database/server/models/aiModel.ts b/src/database/server/models/aiModel.ts index 225156754d678..571e9bfdf6d2c 100644 --- a/src/database/server/models/aiModel.ts +++ b/src/database/server/models/aiModel.ts @@ -8,6 +8,7 @@ import { AiProviderModelListItem, ToggleAiModelEnableParams, } from '@/types/aiModel'; +import { EnabledAiModel } from '@/types/aiProvider'; import { AiModelSelectItem, NewAiModelItem, aiModels } from '../../schemas'; @@ -83,8 +84,8 @@ export class AiModelModel { return result as AiProviderModelListItem[]; }; - getEnabledModels = async () => { - return this.db + getAllModels = async () => { + const data = await this.db .select({ abilities: aiModels.abilities, config: aiModels.config, @@ -98,7 +99,9 @@ export class AiModelModel { type: aiModels.type, }) .from(aiModels) - .where(and(eq(aiModels.userId, this.userId), eq(aiModels.enabled, true))); + .where(and(eq(aiModels.userId, this.userId))); + + return data as EnabledAiModel[]; }; findById = async (id: string) => { diff --git a/src/store/aiInfra/slices/aiProvider/action.ts b/src/store/aiInfra/slices/aiProvider/action.ts index e972b0285bf99..1db81dbb2ba8f 100644 --- a/src/store/aiInfra/slices/aiProvider/action.ts +++ b/src/store/aiInfra/slices/aiProvider/action.ts @@ -215,7 +215,7 @@ export const createAiProviderSlice: StateCreator< enabledChatModelList, }, false, - 'useInitAiProviderKeyVaults', + 'useFetchAiProviderRuntimeState', ); }, }, diff --git a/src/types/aiProvider.ts b/src/types/aiProvider.ts index c411622d3e66e..d97cc76693367 100644 --- a/src/types/aiProvider.ts +++ b/src/types/aiProvider.ts @@ -192,6 +192,7 @@ export interface EnabledAiModel { config?: AiModelConfig; contextWindowTokens?: number; displayName?: string; + enabled?: boolean; id: string; providerId: string; sort?: number; From 35c459c33d7ca1a9f7154aa5b745ddcc0bd190da Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 8 Jan 2025 09:50:59 +0000 Subject: [PATCH 2/3] :bookmark: chore(release): v1.44.3 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### [Version 1.44.3](https://github.com/lobehub/lobe-chat/compare/v1.44.2...v1.44.3) Released on **2025-01-08** #### 🐛 Bug Fixes - **misc**: Fix provider enabled issue.
Improvements and Fixes #### What's fixed * **misc**: Fix provider enabled issue, closes [#5337](https://github.com/lobehub/lobe-chat/issues/5337) ([8e0b634](https://github.com/lobehub/lobe-chat/commit/8e0b634))
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
--- CHANGELOG.md | 25 +++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62f324109f9cf..bc8cbf93613af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,31 @@ # Changelog +### [Version 1.44.3](https://github.com/lobehub/lobe-chat/compare/v1.44.2...v1.44.3) + +Released on **2025-01-08** + +#### 🐛 Bug Fixes + +- **misc**: Fix provider enabled issue. + +
+ +
+Improvements and Fixes + +#### What's fixed + +- **misc**: Fix provider enabled issue, closes [#5337](https://github.com/lobehub/lobe-chat/issues/5337) ([8e0b634](https://github.com/lobehub/lobe-chat/commit/8e0b634)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ ### [Version 1.44.2](https://github.com/lobehub/lobe-chat/compare/v1.44.1...v1.44.2) Released on **2025-01-08** diff --git a/package.json b/package.json index f9a862e938f2c..15e10c5651d43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lobehub/chat", - "version": "1.44.2", + "version": "1.44.3", "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.", "keywords": [ "framework", From 45aac54df67b181e28e71e254db0c20e51fcfe8a Mon Sep 17 00:00:00 2001 From: lobehubbot Date: Wed, 8 Jan 2025 09:52:03 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20docs(bot):=20Auto=20sync=20a?= =?UTF-8?q?gents=20&=20plugin=20to=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/v1.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/changelog/v1.json b/changelog/v1.json index f3a583cf826e1..70d88b33780b5 100644 --- a/changelog/v1.json +++ b/changelog/v1.json @@ -1,4 +1,11 @@ [ + { + "children": { + "fixes": ["Fix provider enabled issue."] + }, + "date": "2025-01-08", + "version": "1.44.3" + }, { "children": { "fixes": ["Add provider id validate."]