Add Memory switch

This commit is contained in:
2025-09-10 10:27:04 +08:00
parent e083b7aff9
commit 2c40ef1b16
3 changed files with 14 additions and 3 deletions

View File

@@ -69,7 +69,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
val timeout: Long by value(60000L) val timeout: Long by value(60000L)
@Deprecated("使用外部文件而不是在配置文件内保存提示词") @Deprecated("使用外部文件而不是在配置文件内保存提示词")
@ValueDescription("系统提示词") @ValueDescription("系统提示词,该字段已弃用,使用提示词文件而不是在这里修改")
var prompt: String by value("你是一个乐于助人的助手") var prompt: String by value("你是一个乐于助人的助手")
@ValueDescription("系统提示词文件路径,相对于插件配置目录") @ValueDescription("系统提示词文件路径,相对于插件配置目录")
@@ -95,4 +95,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
@ValueDescription("是否显示工具调用消息,默认是") @ValueDescription("是否显示工具调用消息,默认是")
val showToolCallingMessage by value(true) val showToolCallingMessage by value(true)
@ValueDescription("是否启用记忆编辑功能记忆存在data目录提示词中需要加上{memory}来填充记忆,每个群都有独立记忆")
val memoryEnabled by value(true)
} }

View File

@@ -10,6 +10,7 @@ import kotlinx.serialization.json.putJsonArray
import kotlinx.serialization.json.putJsonObject import kotlinx.serialization.json.putJsonObject
import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.event.events.MessageEvent
import top.jie65535.mirai.JChatGPT import top.jie65535.mirai.JChatGPT
import top.jie65535.mirai.PluginConfig
import top.jie65535.mirai.PluginData import top.jie65535.mirai.PluginData
class MemoryAppend : BaseAgent( class MemoryAppend : BaseAgent(
@@ -30,6 +31,9 @@ class MemoryAppend : BaseAgent(
} }
) )
) { ) {
override val isEnabled: Boolean
get() = PluginConfig.memoryEnabled
override suspend fun execute(args: JsonObject?, event: MessageEvent): String { override suspend fun execute(args: JsonObject?, event: MessageEvent): String {
requireNotNull(args) requireNotNull(args)
val contactId = event.subject.id val contactId = event.subject.id

View File

@@ -10,13 +10,14 @@ import kotlinx.serialization.json.putJsonArray
import kotlinx.serialization.json.putJsonObject import kotlinx.serialization.json.putJsonObject
import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.event.events.MessageEvent
import top.jie65535.mirai.JChatGPT import top.jie65535.mirai.JChatGPT
import top.jie65535.mirai.PluginConfig
import top.jie65535.mirai.PluginData import top.jie65535.mirai.PluginData
class MemoryReplace : BaseAgent( class MemoryReplace : BaseAgent(
tool = Tool.Companion.function( tool = Tool.function(
name = "memoryReplace", name = "memoryReplace",
description = "替换记忆项", description = "替换记忆项",
parameters = Parameters.Companion.buildJsonObject { parameters = Parameters.buildJsonObject {
put("type", "object") put("type", "object")
putJsonObject("properties") { putJsonObject("properties") {
putJsonObject("oldMemory") { putJsonObject("oldMemory") {
@@ -35,6 +36,9 @@ class MemoryReplace : BaseAgent(
} }
) )
) { ) {
override val isEnabled: Boolean
get() = PluginConfig.memoryEnabled
override suspend fun execute(args: JsonObject?, event: MessageEvent): String { override suspend fun execute(args: JsonObject?, event: MessageEvent): String {
requireNotNull(args) requireNotNull(args)
val contactId = event.subject.id val contactId = event.subject.id