mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 00:17:17 +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",
|
"minimist": "^1.2.8",
|
||||||
"node-machine-id": "^1.1.12",
|
"node-machine-id": "^1.1.12",
|
||||||
"puppeteer": "20.1.0",
|
"puppeteer": "20.1.0",
|
||||||
"puppeteer-extra-plugin-stealth": "2.11.2"
|
"puppeteer-extra-plugin-stealth": "2.11.2",
|
||||||
|
"uuid": "^11.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@electron-toolkit/eslint-config": "^1.0.2",
|
"@electron-toolkit/eslint-config": "^1.0.2",
|
||||||
|
|||||||
@@ -24,26 +24,27 @@ export const sendLookForwardReplyEmotion = async (page: Page) => {
|
|||||||
await lookForwardReplyEmojiProxy!.click()
|
await lookForwardReplyEmojiProxy!.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const blockModelSet = new Set()
|
||||||
const pickLlmConfigFromList = (llmConfigList) => {
|
const pickLlmConfigFromList = (llmConfigList) => {
|
||||||
if (llmConfigList.length === 1) {
|
if (llmConfigList.length === 1) {
|
||||||
llmConfigList[0].enabled = true
|
llmConfigList[0].enabled = true
|
||||||
llmConfigList[0].serveWeight = SINGLE_ITEM_DEFAULT_SERVE_WEIGHT
|
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[] = []
|
const pool: number[] = []
|
||||||
for (let i = 0; i < llmConfigList.length; i++) {
|
for (let i = 0; i < llmConfigList.length; i++) {
|
||||||
for (let j = 0; j < Math.floor(llmConfigList[i].serveWeight); j++) {
|
for (let j = 0; j < Math.floor(llmConfigList[i].serveWeight); j++) {
|
||||||
pool.push(i)
|
pool.push(llmConfigList[i].id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pool.length) {
|
if (!pool.length) {
|
||||||
throw new Error(`cannot find a usable model`)
|
return null
|
||||||
}
|
}
|
||||||
const index = Math.floor(pool.length * Math.random())
|
const index = Math.floor(pool.length * Math.random())
|
||||||
return llmConfigList[
|
return llmConfigList.find(it => it.id === pool[index]) ?? null
|
||||||
pool[index]
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// let _index = 0
|
// let _index = 0
|
||||||
@@ -135,17 +136,28 @@ export const sendGptContent = async (page: Page, chatRecords) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
console.log(chatList)
|
console.log(chatList)
|
||||||
const llmConfigList = await readConfigFile('llm.json')
|
let res
|
||||||
const llmConfig = pickLlmConfigFromList(llmConfigList)
|
while (!res) {
|
||||||
console.log(llmConfig.providerCompleteApiUrl)
|
const llmConfigList = await readConfigFile('llm.json')
|
||||||
const res = await completes(
|
const llmConfig = pickLlmConfigFromList(llmConfigList)
|
||||||
{
|
if (!llmConfig) {
|
||||||
baseURL: llmConfig.providerCompleteApiUrl,
|
throw new Error(`CANNOT_FIND_A_USABLE_MODEL`);
|
||||||
apiKey: llmConfig.providerApiSecret,
|
}
|
||||||
model: llmConfig.model
|
console.log(llmConfig.providerCompleteApiUrl)
|
||||||
},
|
try {
|
||||||
chatList
|
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)
|
console.log(res)
|
||||||
// _index++
|
// _index++
|
||||||
let textToSend
|
let textToSend
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
class="llm-config-form"
|
class="llm-config-form"
|
||||||
:validate-on-rule-change="false"
|
: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
|
<div
|
||||||
v-if="formContent.length > 1"
|
v-if="formContent.length > 1"
|
||||||
:style="{
|
:style="{
|
||||||
@@ -229,7 +229,7 @@
|
|||||||
<div w480px flex flex-justify-between>
|
<div w480px flex flex-justify-between>
|
||||||
<div>
|
<div>
|
||||||
<el-button font-size-12px type="text" @click="addConfig"
|
<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>
|
||||||
<div>
|
<div>
|
||||||
@@ -256,8 +256,9 @@ import { ArrowUp, ArrowDown, Delete } from '@element-plus/icons-vue'
|
|||||||
import { ref, onMounted, watch, nextTick, computed } from 'vue'
|
import { ref, onMounted, watch, nextTick, computed } from 'vue'
|
||||||
import { gtagRenderer } from '@renderer/utils/gtag'
|
import { gtagRenderer } from '@renderer/utils/gtag'
|
||||||
import { SINGLE_ITEM_DEFAULT_SERVE_WEIGHT } from '../../../../common/constant'
|
import { SINGLE_ITEM_DEFAULT_SERVE_WEIGHT } from '../../../../common/constant'
|
||||||
|
import { v4 as uuid } from 'uuid'
|
||||||
interface LlmConfigItem {
|
interface LlmConfigItem {
|
||||||
|
id: string
|
||||||
providerCompleteApiUrl: string
|
providerCompleteApiUrl: string
|
||||||
providerApiSecret: string
|
providerApiSecret: string
|
||||||
model: string
|
model: string
|
||||||
@@ -267,6 +268,7 @@ interface LlmConfigItem {
|
|||||||
|
|
||||||
function getNewConfigItem(): LlmConfigItem {
|
function getNewConfigItem(): LlmConfigItem {
|
||||||
return {
|
return {
|
||||||
|
id: uuid(),
|
||||||
providerCompleteApiUrl: '',
|
providerCompleteApiUrl: '',
|
||||||
providerApiSecret: '',
|
providerApiSecret: '',
|
||||||
model: '',
|
model: '',
|
||||||
@@ -352,17 +354,20 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
const keyOfItem = Object.keys(getNewConfigItem())
|
const keyOfItem = Object.keys(getNewConfigItem())
|
||||||
formContent.value = savedFileContent.map((it) => {
|
formContent.value = savedFileContent.map((it) => {
|
||||||
const conf = {}
|
const conf: any = {}
|
||||||
for (const k of keyOfItem) {
|
for (const k of keyOfItem) {
|
||||||
conf[k] = it[k]
|
conf[k] = it[k]
|
||||||
}
|
}
|
||||||
|
if (!it.id) {
|
||||||
|
conf.id = uuid()
|
||||||
|
}
|
||||||
return conf
|
return conf
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const llmPresetList: {
|
const llmPresetList: {
|
||||||
name: string
|
name: string
|
||||||
config: LlmConfigItem
|
config: Omit<LlmConfigItem, 'id'>
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
name: '由 DeepSeek 提供的 DeepSeek-V3 模型',
|
name: '由 DeepSeek 提供的 DeepSeek-V3 模型',
|
||||||
@@ -457,6 +462,9 @@ function handlePresetClick(selected: (typeof llmPresetList)[number], index) {
|
|||||||
for (const k of Object.keys(formContent.value[index])) {
|
for (const k of Object.keys(formContent.value[index])) {
|
||||||
formContent.value[index][k] = selected.config[k]
|
formContent.value[index][k] = selected.config[k]
|
||||||
}
|
}
|
||||||
|
if (!formContent.value[index].id) {
|
||||||
|
formContent.value[index].id = uuid()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstInputRefList = ref<InstanceType<typeof ElInput>[]>([])
|
const firstInputRefList = ref<InstanceType<typeof ElInput>[]>([])
|
||||||
|
|||||||
Generated
+8
@@ -141,6 +141,9 @@ importers:
|
|||||||
puppeteer-extra-plugin-stealth:
|
puppeteer-extra-plugin-stealth:
|
||||||
specifier: 2.11.2
|
specifier: 2.11.2
|
||||||
version: 2.11.2(puppeteer-extra@3.3.6)
|
version: 2.11.2(puppeteer-extra@3.3.6)
|
||||||
|
uuid:
|
||||||
|
specifier: ^11.1.0
|
||||||
|
version: 11.1.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@electron-toolkit/eslint-config':
|
'@electron-toolkit/eslint-config':
|
||||||
specifier: ^1.0.2
|
specifier: ^1.0.2
|
||||||
@@ -6410,6 +6413,11 @@ packages:
|
|||||||
/util-deprecate@1.0.2:
|
/util-deprecate@1.0.2:
|
||||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
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:
|
/uuid@8.3.2:
|
||||||
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|||||||
Reference in New Issue
Block a user