From 7fae55863e62c3b6243b75314696de44d354dca2 Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Thu, 3 Jul 2025 23:22:35 +0800 Subject: [PATCH] refactor(llm, migrate): reorganize PH8 provider configuration and migration logic - Moved the PH8 provider configuration within the INITIAL_PROVIDERS array for better structure. - Updated migration logic to ensure the PH8 provider is added and positioned correctly in the state during configuration migration. - Removed redundant code related to provider initialization in the migration process, streamlining the overall logic. --- src/renderer/src/config/models.ts | 2 +- src/renderer/src/i18n/locales/zh-cn.json | 2 +- src/renderer/src/i18n/locales/zh-tw.json | 2 +- src/renderer/src/store/llm.ts | 20 ++++----- src/renderer/src/store/migrate.ts | 53 ++---------------------- 5 files changed, 16 insertions(+), 63 deletions(-) diff --git a/src/renderer/src/config/models.ts b/src/renderer/src/config/models.ts index 5c47b0077b..94a92c53ca 100644 --- a/src/renderer/src/config/models.ts +++ b/src/renderer/src/config/models.ts @@ -50,8 +50,8 @@ import { default as GoogleModelLogo, default as GoogleModelLogoDark } from '@ren import ChatGPT35ModelLogo from '@renderer/assets/images/models/gpt_3.5.png' import ChatGPT4ModelLogo from '@renderer/assets/images/models/gpt_4.png' import { - default as ChatGPT35ModelLogoDark, default as ChatGPT4ModelLogoDark, + default as ChatGPT35ModelLogoDark, default as ChatGptModelLogoDakr, default as ChatGPTo1ModelLogoDark } from '@renderer/assets/images/models/gpt_dark.png' diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index 1ce540577d..953ea0e796 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -1061,7 +1061,7 @@ "302ai": "302.AI", "lanyun": "蓝耘科技", "vertexai": "Vertex AI", - "ph8": "PH8大模型开放平台" + "ph8": "PH8 大模型开放平台" }, "restore": { "confirm": "确定要恢复数据吗?", diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index 5f214b77bd..0098e45368 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -1061,7 +1061,7 @@ "302ai": "302.AI", "lanyun": "藍耘", "vertexai": "Vertex AI", - "ph8": "PH8大模型開放平台" + "ph8": "PH8 大模型開放平台" }, "restore": { "confirm": "確定要復原資料嗎?", diff --git a/src/renderer/src/store/llm.ts b/src/renderer/src/store/llm.ts index 880770cbae..9f3a5a0e59 100644 --- a/src/renderer/src/store/llm.ts +++ b/src/renderer/src/store/llm.ts @@ -144,16 +144,6 @@ export const INITIAL_PROVIDERS: Provider[] = [ isSystem: true, enabled: false }, - { - id: 'ph8', - name: 'PH8', - type: 'openai', - apiKey: '', - apiHost: 'https://ph8.co', - models: SYSTEM_MODELS.ph8, - isSystem: true, - enabled: false - }, { id: 'cephalon', name: 'Cephalon', @@ -174,6 +164,16 @@ export const INITIAL_PROVIDERS: Provider[] = [ isSystem: true, enabled: false }, + { + id: 'ph8', + name: 'PH8', + type: 'openai', + apiKey: '', + apiHost: 'https://ph8.co', + models: SYSTEM_MODELS.ph8, + isSystem: true, + enabled: false + }, { id: 'openrouter', name: 'OpenRouter', diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index 91c7051d8c..1cc830a2bb 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -1699,6 +1699,9 @@ const migrateConfig = { }, '118': (state: RootState) => { try { + addProvider(state, 'ph8') + state.llm.providers = moveProvider(state.llm.providers, 'ph8', 14) + if (!state.settings.userId) { state.settings.userId = uuid() } @@ -1709,56 +1712,6 @@ const migrateConfig = { } }) - if (!state.preprocess) { - state.preprocess = { - defaultProvider: '', - providers: [] - } - } - - if (state.preprocess.providers.length === 0) { - state.preprocess.providers = [ - { - id: 'doc2x', - name: 'Doc2x', - apiKey: '', - apiHost: 'https://v2.doc2x.noedgeai.com' - }, - { - id: 'mistral', - name: 'Mistral', - model: 'mistral-ocr-latest', - apiKey: '', - apiHost: 'https://api.mistral.ai' - }, - { - id: 'mineru', - name: 'MinerU', - apiKey: '', - apiHost: 'https://mineru.net' - } - ] - } - - if (!state.ocr.providers.find((provider) => provider.id === 'system')) { - state.ocr.providers.push({ - id: 'system', - name: 'System(Mac Only)', - options: { - recognitionLevel: 0, - minConfidence: 0.5 - } - }) - } - return state - } catch (error) { - return state - } - }, - '119': (state: RootState) => { - try { - addProvider(state, 'ph8') - state.llm.providers = moveProvider(state.llm.providers, 'ph8', 3) return state } catch (error) { return state