mirror of
https://github.com/jie65535/JChatGPT.git
synced 2025-12-08 18:31:36 +08:00
Compare commits
2 Commits
634f0c1026
...
6705859604
| Author | SHA1 | Date | |
|---|---|---|---|
| 6705859604 | |||
| 621a045a62 |
@@ -717,6 +717,9 @@ object JChatGPT : KotlinPlugin(
|
||||
// 好感度调整
|
||||
AdjustUserFavorabilityAgent(),
|
||||
|
||||
// 请求主人帮助
|
||||
RequestOwner(),
|
||||
|
||||
// Epic 免费游戏
|
||||
// EpicFreeGame(),
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ import net.mamoe.mirai.console.data.ValueDescription
|
||||
import net.mamoe.mirai.console.data.value
|
||||
|
||||
object PluginConfig : AutoSavePluginConfig("Config") {
|
||||
@ValueDescription("主人QQ,AI可以通过工具向主人发起请求,会等待一段时间")
|
||||
val ownerId: Long by value()
|
||||
|
||||
@ValueDescription("OpenAI API base url")
|
||||
val openAiApi: String by value("https://dashscope.aliyuncs.com/compatible-mode/v1/")
|
||||
|
||||
@@ -107,4 +110,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
|
||||
|
||||
@ValueDescription("表情包路径,配置后会加载目录下的文件名,提示词中需要用{meme}来插入上下文")
|
||||
val memeDir: String by value("")
|
||||
|
||||
@ValueDescription("请求主人回复等待时间,单位毫秒,默认300秒")
|
||||
val requestOwnerWaitTimeout: Long by value(300000L)
|
||||
}
|
||||
57
src/main/kotlin/tools/RequestOwner.kt
Normal file
57
src/main/kotlin/tools/RequestOwner.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package top.jie65535.mirai.tools
|
||||
|
||||
import com.aallam.openai.api.chat.Tool
|
||||
import com.aallam.openai.api.core.Parameters
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.add
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlinx.serialization.json.put
|
||||
import kotlinx.serialization.json.putJsonArray
|
||||
import kotlinx.serialization.json.putJsonObject
|
||||
import net.mamoe.mirai.event.EventPriority
|
||||
import net.mamoe.mirai.event.GlobalEventChannel
|
||||
import net.mamoe.mirai.event.events.FriendMessageEvent
|
||||
import net.mamoe.mirai.event.events.MessageEvent
|
||||
import net.mamoe.mirai.event.nextEvent
|
||||
import net.mamoe.mirai.message.data.content
|
||||
import top.jie65535.mirai.JChatGPT
|
||||
import top.jie65535.mirai.PluginConfig
|
||||
import kotlin.collections.getValue
|
||||
|
||||
class RequestOwner : BaseAgent(
|
||||
tool = Tool.function(
|
||||
name = "requestOwnerHelp",
|
||||
description = "当遇到无法处理的问题时,通过私聊请求系统管理员并阻塞等待其回复,默认超时时间5分钟,请求前建议提前告知群友。",
|
||||
parameters = Parameters.buildJsonObject {
|
||||
put("type", "object")
|
||||
putJsonObject("properties") {
|
||||
putJsonObject("content") {
|
||||
put("type", "string")
|
||||
put("description", "请求内容与上下文")
|
||||
}
|
||||
}
|
||||
putJsonArray("required") {
|
||||
add("content")
|
||||
}
|
||||
}
|
||||
)
|
||||
) {
|
||||
override val isEnabled: Boolean
|
||||
get() = PluginConfig.ownerId > 0 && PluginConfig.requestOwnerWaitTimeout > 0
|
||||
|
||||
override suspend fun execute(args: JsonObject?, event: MessageEvent): String {
|
||||
requireNotNull(args)
|
||||
val owner = event.bot.getFriendOrFail(PluginConfig.ownerId)
|
||||
val content = args.getValue("content").jsonPrimitive.content
|
||||
JChatGPT.logger.info("请求主人协助中:$content")
|
||||
owner.sendMessage(JChatGPT.toMessage(owner, content))
|
||||
|
||||
val nextEvent: FriendMessageEvent = withTimeout(PluginConfig.requestOwnerWaitTimeout) {
|
||||
GlobalEventChannel.nextEvent(EventPriority.MONITOR) { it.sender.id == PluginConfig.ownerId }
|
||||
}
|
||||
val response = nextEvent.message.content
|
||||
JChatGPT.logger.info("主人回复:$response")
|
||||
return response
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ class VisitWeb : BaseAgent(
|
||||
}
|
||||
|
||||
override val isEnabled: Boolean
|
||||
get() = PluginConfig.jinaApiKey.isNotEmpty()
|
||||
get() = true // PluginConfig.jinaApiKey.isNotEmpty()
|
||||
|
||||
override val loadingMessage: String
|
||||
get() = "上网中..."
|
||||
@@ -62,7 +62,9 @@ class VisitWeb : BaseAgent(
|
||||
private suspend fun jinaReadPage(url: String): String {
|
||||
return try {
|
||||
httpClient.get(JINA_READER_URL_PREFIX + url) {
|
||||
header("Authorization", "Bearer ${PluginConfig.jinaApiKey}")
|
||||
if (PluginConfig.jinaApiKey.isNotEmpty()) {
|
||||
header("Authorization", "Bearer ${PluginConfig.jinaApiKey}")
|
||||
}
|
||||
}.bodyAsText()
|
||||
} catch (e: Throwable) {
|
||||
"Error fetching \"$url\": ${e.message}"
|
||||
|
||||
Reference in New Issue
Block a user