mirror of
https://github.com/jie65535/JChatGPT.git
synced 2025-12-08 18:31:36 +08:00
Add requestOwnerHelp tool
This commit is contained in:
@@ -717,6 +717,9 @@ object JChatGPT : KotlinPlugin(
|
|||||||
// 好感度调整
|
// 好感度调整
|
||||||
AdjustUserFavorabilityAgent(),
|
AdjustUserFavorabilityAgent(),
|
||||||
|
|
||||||
|
// 请求主人帮助
|
||||||
|
RequestOwner(),
|
||||||
|
|
||||||
// Epic 免费游戏
|
// Epic 免费游戏
|
||||||
// EpicFreeGame(),
|
// EpicFreeGame(),
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import net.mamoe.mirai.console.data.ValueDescription
|
|||||||
import net.mamoe.mirai.console.data.value
|
import net.mamoe.mirai.console.data.value
|
||||||
|
|
||||||
object PluginConfig : AutoSavePluginConfig("Config") {
|
object PluginConfig : AutoSavePluginConfig("Config") {
|
||||||
|
@ValueDescription("主人QQ,AI可以通过工具向主人发起请求,会等待一段时间")
|
||||||
|
val ownerId: Long by value()
|
||||||
|
|
||||||
@ValueDescription("OpenAI API base url")
|
@ValueDescription("OpenAI API base url")
|
||||||
val openAiApi: String by value("https://dashscope.aliyuncs.com/compatible-mode/v1/")
|
val openAiApi: String by value("https://dashscope.aliyuncs.com/compatible-mode/v1/")
|
||||||
|
|
||||||
@@ -107,4 +110,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
|
|||||||
|
|
||||||
@ValueDescription("表情包路径,配置后会加载目录下的文件名,提示词中需要用{meme}来插入上下文")
|
@ValueDescription("表情包路径,配置后会加载目录下的文件名,提示词中需要用{meme}来插入上下文")
|
||||||
val memeDir: String by value("")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user