Skip to content

Commit 6ccfd7d

Browse files
committed
1
1 parent 0e10d66 commit 6ccfd7d

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/main/kotlin/API.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.ktor.client.*
44
import io.ktor.client.call.*
55
import io.ktor.client.engine.*
66
import io.ktor.client.engine.okhttp.*
7+
import io.ktor.client.plugins.*
78
import io.ktor.client.plugins.contentnegotiation.*
89
import io.ktor.client.request.*
910
import io.ktor.http.*
@@ -63,6 +64,10 @@ object Client {
6364
install(ContentNegotiation) {
6465
json()
6566
}
67+
install(HttpTimeout) {
68+
requestTimeoutMillis = Config.timeout
69+
socketTimeoutMillis = Config.timeout
70+
}
6671
engine {
6772
if (Config.httpProxyUrl != "")
6873
proxy = ProxyBuilder.http(Config.httpProxyUrl)
@@ -75,6 +80,10 @@ object Client {
7580
fun sendRequest(requestObject: RequestObject): ReceivedObject {
7681
return runBlocking {
7782
return@runBlocking client.post(Config.apiUrl) {
83+
timeout {
84+
requestTimeoutMillis = Config.timeout
85+
socketTimeoutMillis = Config.timeout
86+
}
7887
headers {
7988
headers {
8089
append(HttpHeaders.Authorization, "Bearer ${Config.token}")

src/main/kotlin/Command.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fun chatEventHandler(idL: Long, message: String, quote: QuoteReply): MessageChai
3939
val content = (response.choices[0].message.content).trim()
4040
MessageChainBuilder().append(quote).append(PlainText(content)).build()
4141
} catch (e: Exception) {
42+
BotGPT.logger.warning(e.message)
4243
MessageChainBuilder().append(quote).append(PlainText("内部错误")).build()
4344
}
4445
} else

src/main/kotlin/Config.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object Config : AutoSavePluginConfig("config") {
1010
val socksProxyPort by value(0)
1111
val token by value("ChatGPTToken")
1212
val expirationTime by value(60)
13+
val timeout by value<Long>(100000)
1314
val cooldown by value(30)
1415
val model by value("gpt-3.5-turbo")
1516
val separator by value(" ")

0 commit comments

Comments
 (0)