From 6dc3948d12fc32cd5b34a823b3caa4b15d76a746 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Tue, 15 Apr 2025 01:13:15 +0800 Subject: [PATCH] add block list to save unavailable model and prevent use again --- packages/ui/package.json | 3 +- .../boss-operation.ts | 48 ++++++++++++------- .../src/renderer/src/page/LlmConfig/index.vue | 18 +++++-- pnpm-lock.yaml | 8 ++++ 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/packages/ui/package.json b/packages/ui/package.json index ed4cb89..93d3979 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -41,7 +41,8 @@ "minimist": "^1.2.8", "node-machine-id": "^1.1.12", "puppeteer": "20.1.0", - "puppeteer-extra-plugin-stealth": "2.11.2" + "puppeteer-extra-plugin-stealth": "2.11.2", + "uuid": "^11.1.0" }, "devDependencies": { "@electron-toolkit/eslint-config": "^1.0.2", diff --git a/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/boss-operation.ts b/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/boss-operation.ts index a0dc5f1..3a7a8c3 100644 --- a/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/boss-operation.ts +++ b/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/boss-operation.ts @@ -24,26 +24,27 @@ export const sendLookForwardReplyEmotion = async (page: Page) => { await lookForwardReplyEmojiProxy!.click() } +const blockModelSet = new Set() const pickLlmConfigFromList = (llmConfigList) => { if (llmConfigList.length === 1) { llmConfigList[0].enabled = true llmConfigList[0].serveWeight = SINGLE_ITEM_DEFAULT_SERVE_WEIGHT - return llmConfigList[0] } - llmConfigList = llmConfigList.filter((it) => it.enabled) + llmConfigList = llmConfigList.filter((it) => it.enabled && !blockModelSet.has(it.id)) + if (!llmConfigList.length) { + return null + } const pool: number[] = [] for (let i = 0; i < llmConfigList.length; i++) { for (let j = 0; j < Math.floor(llmConfigList[i].serveWeight); j++) { - pool.push(i) + pool.push(llmConfigList[i].id) } } if (!pool.length) { - throw new Error(`cannot find a usable model`) + return null } const index = Math.floor(pool.length * Math.random()) - return llmConfigList[ - pool[index] - ] + return llmConfigList.find(it => it.id === pool[index]) ?? null } // let _index = 0 @@ -135,17 +136,28 @@ export const sendGptContent = async (page: Page, chatRecords) => { }) } console.log(chatList) - const llmConfigList = await readConfigFile('llm.json') - const llmConfig = pickLlmConfigFromList(llmConfigList) - console.log(llmConfig.providerCompleteApiUrl) - const res = await completes( - { - baseURL: llmConfig.providerCompleteApiUrl, - apiKey: llmConfig.providerApiSecret, - model: llmConfig.model - }, - chatList - ) + let res + while (!res) { + const llmConfigList = await readConfigFile('llm.json') + const llmConfig = pickLlmConfigFromList(llmConfigList) + if (!llmConfig) { + throw new Error(`CANNOT_FIND_A_USABLE_MODEL`); + } + console.log(llmConfig.providerCompleteApiUrl) + try { + res = await completes( + { + baseURL: llmConfig.providerCompleteApiUrl, + apiKey: llmConfig.providerApiSecret, + model: llmConfig.model + }, + chatList + ) + } catch (err) { + console.log('request failed', err) + blockModelSet.add(llmConfig.id) + } + } console.log(res) // _index++ let textToSend diff --git a/packages/ui/src/renderer/src/page/LlmConfig/index.vue b/packages/ui/src/renderer/src/page/LlmConfig/index.vue index 181d075..e19e5b5 100644 --- a/packages/ui/src/renderer/src/page/LlmConfig/index.vue +++ b/packages/ui/src/renderer/src/page/LlmConfig/index.vue @@ -76,7 +76,7 @@ class="llm-config-form" :validate-on-rule-change="false" > -
+
添加其它模型,以生成更随机的内容添加备用模型,以生成更随机的内容
@@ -256,8 +256,9 @@ import { ArrowUp, ArrowDown, Delete } from '@element-plus/icons-vue' import { ref, onMounted, watch, nextTick, computed } from 'vue' import { gtagRenderer } from '@renderer/utils/gtag' import { SINGLE_ITEM_DEFAULT_SERVE_WEIGHT } from '../../../../common/constant' - +import { v4 as uuid } from 'uuid' interface LlmConfigItem { + id: string providerCompleteApiUrl: string providerApiSecret: string model: string @@ -267,6 +268,7 @@ interface LlmConfigItem { function getNewConfigItem(): LlmConfigItem { return { + id: uuid(), providerCompleteApiUrl: '', providerApiSecret: '', model: '', @@ -352,17 +354,20 @@ onMounted(async () => { } const keyOfItem = Object.keys(getNewConfigItem()) formContent.value = savedFileContent.map((it) => { - const conf = {} + const conf: any = {} for (const k of keyOfItem) { conf[k] = it[k] } + if (!it.id) { + conf.id = uuid() + } return conf }) }) const llmPresetList: { name: string - config: LlmConfigItem + config: Omit }[] = [ { name: '由 DeepSeek 提供的 DeepSeek-V3 模型', @@ -457,6 +462,9 @@ function handlePresetClick(selected: (typeof llmPresetList)[number], index) { for (const k of Object.keys(formContent.value[index])) { formContent.value[index][k] = selected.config[k] } + if (!formContent.value[index].id) { + formContent.value[index].id = uuid() + } } const firstInputRefList = ref[]>([]) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 419555d..8114f88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -141,6 +141,9 @@ importers: puppeteer-extra-plugin-stealth: specifier: 2.11.2 version: 2.11.2(puppeteer-extra@3.3.6) + uuid: + specifier: ^11.1.0 + version: 11.1.0 devDependencies: '@electron-toolkit/eslint-config': specifier: ^1.0.2 @@ -6410,6 +6413,11 @@ packages: /util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + /uuid@11.1.0: + resolution: {integrity: sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==} + hasBin: true + dev: false + /uuid@8.3.2: resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} hasBin: true