mirror of
https://github.com/jie65535/JChatGPT.git
synced 2025-06-02 17:39:10 +08:00
Update version to v1.1.0
Add timeout config Add Forward messages when the text is too long
This commit is contained in:
parent
7c26c8e590
commit
a6bd48aa4e
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
val kotlinVersion = "1.8.10"
|
||||
val kotlinVersion = "1.9.24"
|
||||
kotlin("jvm") version kotlinVersion
|
||||
kotlin("plugin.serialization") version kotlinVersion
|
||||
|
||||
@ -7,15 +7,15 @@ plugins {
|
||||
}
|
||||
|
||||
group = "top.jie65535.mirai"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://maven.aliyun.com/repository/public")
|
||||
}
|
||||
|
||||
val openaiClientVersion = "3.6.2"
|
||||
val ktorVersion = "2.3.7"
|
||||
val openaiClientVersion = "3.8.2"
|
||||
val ktorVersion = "2.3.12"
|
||||
|
||||
dependencies {
|
||||
implementation("com.aallam.openai:openai-client:$openaiClientVersion")
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
|
||||
|
@ -3,6 +3,8 @@ package top.jie65535.mirai
|
||||
import com.aallam.openai.api.chat.ChatCompletionRequest
|
||||
import com.aallam.openai.api.chat.ChatMessage
|
||||
import com.aallam.openai.api.chat.ChatRole
|
||||
import com.aallam.openai.api.core.Role
|
||||
import com.aallam.openai.api.http.Timeout
|
||||
import com.aallam.openai.api.model.ModelId
|
||||
import com.aallam.openai.client.OpenAI
|
||||
import com.aallam.openai.client.OpenAIHost
|
||||
@ -23,12 +25,13 @@ import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.message.data.MessageSource.Key.quote
|
||||
import net.mamoe.mirai.message.sourceIds
|
||||
import net.mamoe.mirai.utils.info
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
object JChatGPT : KotlinPlugin(
|
||||
JvmPluginDescription(
|
||||
id = "top.jie65535.mirai.JChatGPT",
|
||||
name = "J ChatGPT",
|
||||
version = "1.0.0",
|
||||
version = "1.1.0",
|
||||
) {
|
||||
author("jie65535")
|
||||
}
|
||||
@ -57,8 +60,10 @@ object JChatGPT : KotlinPlugin(
|
||||
}
|
||||
|
||||
fun updateOpenAiToken(token: String) {
|
||||
val timeout = PluginConfig.timeout.milliseconds
|
||||
openAi = OpenAI(token,
|
||||
host = OpenAIHost(baseUrl = PluginConfig.openAiApi)
|
||||
host = OpenAIHost(baseUrl = PluginConfig.openAiApi),
|
||||
timeout = Timeout(request = timeout, connect = timeout, socket = timeout)
|
||||
)
|
||||
}
|
||||
|
||||
@ -135,7 +140,23 @@ object JChatGPT : KotlinPlugin(
|
||||
}
|
||||
val reply = chatCompletion(history)
|
||||
history.add(reply)
|
||||
val replyMsg = subject.sendMessage(message.quote() + (reply.content ?: "..."))
|
||||
val content = reply.content ?: "..."
|
||||
|
||||
val replyMsg = subject.sendMessage(
|
||||
if (content.length < 100) {
|
||||
message.quote() + content
|
||||
} else {
|
||||
// 消息内容太长则转为转发消息避免刷屏
|
||||
buildForwardMessage {
|
||||
for (item in history) {
|
||||
when (item.role) {
|
||||
Role.User -> sender says (item.content ?: "...")
|
||||
Role.Assistant -> bot says (item.content ?: "...")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
val msgId = replyMsg.sourceIds[0]
|
||||
replyMap[msgId] = history
|
||||
replyQueue.add(msgId)
|
||||
|
@ -22,4 +22,7 @@ object PluginConfig : AutoSavePluginConfig("Config") {
|
||||
|
||||
@ValueDescription("好友是否自动拥有对话权限,默认是")
|
||||
val friendHasChatPermission: Boolean by value(true)
|
||||
|
||||
@ValueDescription("等待响应超时时间,单位毫秒,默认60秒")
|
||||
val timeout: Long by value(60000L)
|
||||
}
|
Loading…
Reference in New Issue
Block a user