1
0

feat: 优化多个大模型接口失败轮询

This commit is contained in:
2024-11-04 18:46:00 +08:00
parent 5829b6e145
commit 162f9bb569
3 changed files with 41 additions and 24 deletions

View File

@@ -3,6 +3,8 @@ package com.lanyuanxiaoyao.digtal.market
import com.lanyuanxiaoyao.digtal.market.runner.NewsRunner import com.lanyuanxiaoyao.digtal.market.runner.NewsRunner
import com.lanyuanxiaoyao.digtal.market.runner.PushRunner import com.lanyuanxiaoyao.digtal.market.runner.PushRunner
import com.lanyuanxiaoyao.squirrel.core.common.Management import com.lanyuanxiaoyao.squirrel.core.common.Management
import com.lanyuanxiaoyao.squirrel.core.jvm.BINARY_PATH
import com.lanyuanxiaoyao.squirrel.core.jvm.DRIVER_PATH
import com.lanyuanxiaoyao.squirrel.core.jvm.JvmManagement import com.lanyuanxiaoyao.squirrel.core.jvm.JvmManagement
import com.lanyuanxiaoyao.squirrel.core.jvm.LocalFileDatabase import com.lanyuanxiaoyao.squirrel.core.jvm.LocalFileDatabase
import jakarta.annotation.Resource import jakarta.annotation.Resource
@@ -81,7 +83,13 @@ class Configuration {
management.changeDownloader("basicCacheDownloader") management.changeDownloader("basicCacheDownloader")
} }
if (information.browserDownloaderName.isBlank()) { if (information.browserDownloaderName.isBlank()) {
management.changeDownloader("htmlUnitCacheDownloader") management.changeDownloader(
"chromeCacheDownloader",
mapOf(
BINARY_PATH to driverProperties.binaryPath,
DRIVER_PATH to driverProperties.driverPath,
)
)
} }
} }
management.importSites(sites) management.importSites(sites)

View File

@@ -1,14 +1,12 @@
package com.lanyuanxiaoyao.digtal.market.service package com.lanyuanxiaoyao.digtal.market.service
import cn.hutool.json.JSONUtil import cn.hutool.json.JSONUtil
import com.lanyuanxiaoyao.digtal.market.ArticleRepository
import com.lanyuanxiaoyao.digtal.market.ai.Chat import com.lanyuanxiaoyao.digtal.market.ai.Chat
import com.lanyuanxiaoyao.digtal.market.ai.QianfanChat import com.lanyuanxiaoyao.digtal.market.ai.QianfanChat
import com.lanyuanxiaoyao.digtal.market.ai.ZhipuChat import com.lanyuanxiaoyao.digtal.market.ai.ZhipuChat
import dev.failsafe.Failsafe import dev.failsafe.Failsafe
import dev.failsafe.RetryPolicy import dev.failsafe.RetryPolicy
import dev.failsafe.function.CheckedSupplier import dev.failsafe.function.CheckedSupplier
import jakarta.annotation.Resource
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration import kotlin.time.toJavaDuration
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@@ -23,13 +21,18 @@ class DescriptionService {
.withMaxRetries(2) .withMaxRetries(2)
.build() .build()
// private val chat: Chat = ZhipuChat() private val chats = listOf(
private val chat: Chat = QianfanChat() ZhipuChat(),
QianfanChat(),
)
fun parseDescription(content: String?): Triple<String, String, Int>? { fun parseDescription(content: String?): Triple<String, String, Int>? {
return content?.let { return content?.let {
if (it.isNotBlank()) { if (it.isNotBlank()) {
val description = Failsafe var description: String?
for (chat in chats) {
try {
description = Failsafe
.with(retryPolicy) .with(retryPolicy)
.get(CheckedSupplier { .get(CheckedSupplier {
chat.ask( chat.ask(
@@ -41,22 +44,23 @@ class DescriptionService {
) )
}) })
logger.info("description: {}", description) logger.info("description: {}", description)
try { if (description.isNullOrBlank()) {
if (!description.isNullOrBlank()) { continue
}
val root = JSONUtil.parse( val root = JSONUtil.parse(
description description
.replace("```json", "") .replace("```json", "")
.replace("```", "") .replace("```", "")
.replace(Regex("//.+"), "")
) )
val subtitle = root.getByPath("title", String::class.java) val subtitle = root.getByPath("title", String::class.java)
val desc = root.getByPath("description", String::class.java) val desc = root.getByPath("description", String::class.java)
val score = root.getByPath("score", Int::class.java) val score = root.getByPath("score", Int::class.java)
Triple(subtitle, desc, score) return@let Triple(subtitle, desc, score)
} else null
} catch (e: Throwable) { } catch (e: Throwable) {
null continue
} }
}
null
} else null } else null
} }
} }

View File

@@ -28,6 +28,11 @@ logging:
org: org:
htmlunit: htmlunit:
IncorrectnessListenerImpl: error IncorrectnessListenerImpl: error
apache:
http:
impl:
execchain:
RetryExec: error
messenger: messenger:
mail: mail:
targets: targets: