mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-11 10:00:34 +08:00
add block list to save unavailable model and prevent use again
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
class="llm-config-form"
|
||||
:validate-on-rule-change="false"
|
||||
>
|
||||
<div v-for="(conf, index) in formContent" :key="index" class="flex gap12px">
|
||||
<div v-for="(conf, index) in formContent" :key="conf.id" class="flex gap12px">
|
||||
<div
|
||||
v-if="formContent.length > 1"
|
||||
:style="{
|
||||
@@ -229,7 +229,7 @@
|
||||
<div w480px flex flex-justify-between>
|
||||
<div>
|
||||
<el-button font-size-12px type="text" @click="addConfig"
|
||||
>添加其它模型<span v-if="formContent.length <= 1">,以生成更随机的内容</span></el-button
|
||||
>添加备用模型<span v-if="formContent.length <= 1">,以生成更随机的内容</span></el-button
|
||||
>
|
||||
</div>
|
||||
<div>
|
||||
@@ -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<LlmConfigItem, 'id'>
|
||||
}[] = [
|
||||
{
|
||||
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<InstanceType<typeof ElInput>[]>([])
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user