Update version to v1.2.1

Add system prompt replace local time
This commit is contained in:
2024-12-20 19:51:59 +08:00
parent 49b1b0c345
commit 5cef899993
2 changed files with 8 additions and 3 deletions

View File

@ -7,7 +7,7 @@ plugins {
}
group = "top.jie65535.mirai"
version = "1.2.0"
version = "1.2.1"
repositories {
mavenCentral()

View File

@ -27,6 +27,7 @@ import net.mamoe.mirai.message.data.MessageSource.Key.quote
import net.mamoe.mirai.message.sourceIds
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
import net.mamoe.mirai.utils.info
import java.time.OffsetDateTime
import java.util.regex.Pattern
import kotlin.time.Duration.Companion.milliseconds
@ -34,7 +35,7 @@ object JChatGPT : KotlinPlugin(
JvmPluginDescription(
id = "top.jie65535.mirai.JChatGPT",
name = "J ChatGPT",
version = "1.2.0",
version = "1.2.1",
) {
author("jie65535")
}
@ -125,12 +126,16 @@ object JChatGPT : KotlinPlugin(
startChat(context)
}
private fun getSystemPrompt(): String {
return PluginConfig.prompt.replace("{time}", OffsetDateTime.now().toString())
}
private suspend fun MessageEvent.startChat(context: List<ChatMessage>? = null) {
val history = mutableListOf<ChatMessage>()
if (!context.isNullOrEmpty()) {
history.addAll(context)
} else if (PluginConfig.prompt.isNotEmpty()) {
history.add(ChatMessage(ChatRole.System, PluginConfig.prompt))
history.add(ChatMessage(ChatRole.System, getSystemPrompt()))
}
val msg = message.plainText()
if (msg.isNotEmpty()) {