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.PushRunner
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.LocalFileDatabase
import jakarta.annotation.Resource
@@ -81,7 +83,13 @@ class Configuration {
management.changeDownloader("basicCacheDownloader")
}
if (information.browserDownloaderName.isBlank()) {
management.changeDownloader("htmlUnitCacheDownloader")
management.changeDownloader(
"chromeCacheDownloader",
mapOf(
BINARY_PATH to driverProperties.binaryPath,
DRIVER_PATH to driverProperties.driverPath,
)
)
}
}
management.importSites(sites)

View File

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

View File

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