From f72a5c014bfc022b36a628050bb1d38ca5e0c71d Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sat, 12 Apr 2025 14:32:06 +0800 Subject: [PATCH] add logic to random pick a llm config --- .../boss-operation.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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 ffcf13c..7a6379d 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 @@ -19,6 +19,23 @@ export const sendLookForwardReplyEmotion = async (page: Page) => { await lookForwardReplyEmojiProxy!.click() } +const pickLlmConfigFromList = (llmConfigList) => { + if (llmConfigList.length === 1) { + return llmConfigList[0] + } + llmConfigList = llmConfigList.filter((it) => it.enabled) + 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) + } + } + const index = Math.floor(pool.length * Math.random()) + return llmConfigList[ + pool[index] + ] +} + // let _index = 0 export const sendGptContent = async (page: Page, chatRecords) => { @@ -86,7 +103,9 @@ export const sendGptContent = async (page: Page, chatRecords) => { }) } console.log(chatList) - const llmConfig = await readConfigFile('llm.json') + const llmConfigList = await readConfigFile('llm.json') + const llmConfig = pickLlmConfigFromList(llmConfigList) + console.log(llmConfig.providerCompleteApiUrl) const res = await completes( { baseURL: llmConfig.providerCompleteApiUrl,