Skip to content

Commit 37cdeb3

Browse files
committed
AI 对话助手接口
1 parent 289c307 commit 37cdeb3

File tree

18 files changed

+470
-10
lines changed

18 files changed

+470
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ bin/
1919

2020
### IntelliJ IDEA ###
2121
.idea
22+
.kotlin
2223
*.iws
2324
*.iml
2425
*.ipr
26+
*.log
2527
out/
2628
!**/src/main/**/out/
2729
!**/src/test/**/out/

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ val kotlin_version: String by project
33
plugins {
44
id("java")
55
application
6-
kotlin("jvm") version "1.8.0"
7-
kotlin("plugin.serialization") version "1.8.0"
6+
kotlin("jvm") version "2.0.0"
7+
kotlin("plugin.serialization") version "2.0.0"
88

99
// 打包用的插件
1010
id("com.github.johnrengelman.shadow") version "7.0.0"

cloudapi-common/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repositories {
1717
}
1818

1919
dependencies {
20-
val ktor_version = "2.1.3"
20+
val ktor_version = "3.0.1"
2121
// ktor client
2222
api("io.ktor:ktor-client-core-jvm:$ktor_version")
2323
api("io.ktor:ktor-client-cio-jvm:$ktor_version")

cloudapi-web/build.gradle.kts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ kotlin {
2020
}
2121

2222
repositories {
23+
maven { setUrl("https://maven.aliyun.com/repository/central") }
24+
maven { setUrl("https://maven.aliyun.com/repository/jcenter") }
25+
maven { setUrl("https://maven.aliyun.com/repository/google") }
26+
maven { setUrl("https://maven.aliyun.com/repository/gradle-plugin") }
27+
maven { setUrl("https://maven.aliyun.com/repository/public") }
28+
maven { setUrl("https://jitpack.io") }
29+
gradlePluginPortal()
30+
google()
2331
mavenCentral()
24-
maven(url = "https://jitpack.io")
2532
}
2633

2734
dependencies {
2835
implementation(project(":cloudapi-model"))
2936

30-
val ktor_version = "2.2.3"
37+
val ktor_version = "3.0.1"
3138
implementation("io.ktor:ktor-server-status-pages:$ktor_version")
3239
implementation("io.ktor:ktor-server-call-id:$ktor_version")
3340
implementation("io.ktor:ktor-server-cors:$ktor_version")
@@ -41,8 +48,11 @@ dependencies {
4148
implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
4249
implementation("io.ktor:ktor-serialization-jackson:$ktor_version")
4350
implementation("io.ktor:ktor-server-status-pages:$ktor_version")
44-
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
45-
testImplementation("io.ktor:ktor-server-test-host-jvm:$ktor_version")
51+
implementation("io.ktor:ktor-server-sse:$ktor_version")
52+
testImplementation("io.ktor:ktor-server-tests-jvm:2.2.3")
53+
testImplementation("io.ktor:ktor-server-test-host-jvm:2.2.3")
54+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:1.7.3")
55+
implementation("ch.qos.logback:logback-classic:1.4.11")
4656

4757
// Redis
4858
implementation("io.lettuce:lettuce-core:6.1.5.RELEASE")

cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/Web.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fun Application.webModule() {
88
configureMonitoring()
99
configureAuth()
1010
configureWebsocket()
11+
configureSSE()
1112
configureCORS()
1213
configureCallID()
1314
configureContentNegotiation()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* cloudapi_v2
3+
* buaa scs cloud api v2
4+
*
5+
* The version of the OpenAPI document: 2.0
6+
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
package cn.edu.buaa.scs.controller.models
13+
14+
/**
15+
*
16+
* @param chatId
17+
* @param stream
18+
* @param detail
19+
* @param messages
20+
* @param customUid
21+
*/
22+
data class ChatCompletionRequest(
23+
val chatId: kotlin.String,
24+
val stream: kotlin.Boolean,
25+
val detail: kotlin.Boolean,
26+
val messages: kotlin.collections.List<ChatCompletionRequestMessagesInner>,
27+
val customUid: kotlin.String? = null
28+
)
29+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* cloudapi_v2
3+
* buaa scs cloud api v2
4+
*
5+
* The version of the OpenAPI document: 2.0
6+
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
package cn.edu.buaa.scs.controller.models
13+
14+
15+
/**
16+
*
17+
* @param role
18+
* @param content
19+
*/
20+
data class ChatCompletionRequestMessagesInner(
21+
val role: kotlin.String,
22+
val content: kotlin.String
23+
)
24+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* cloudapi_v2
3+
* buaa scs cloud api v2
4+
*
5+
* The version of the OpenAPI document: 2.0
6+
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
package cn.edu.buaa.scs.controller.models
13+
14+
15+
/**
16+
*
17+
* @param id
18+
* @param chatId
19+
* @param updateTime
20+
* @param title
21+
* @param top
22+
*/
23+
data class ChatHistoryItem(
24+
val id: kotlin.Int? = null,
25+
val chatId: kotlin.String? = null,
26+
val updateTime: kotlin.Long? = null,
27+
val title: kotlin.String? = null,
28+
val top: kotlin.Boolean? = null
29+
)
30+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* cloudapi_v2
3+
* buaa scs cloud api v2
4+
*
5+
* The version of the OpenAPI document: 2.0
6+
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
package cn.edu.buaa.scs.controller.models
13+
14+
15+
/**
16+
*
17+
* @param chatId
18+
* @param appId
19+
* @param offset
20+
* @param pageSize
21+
* @param loadCustomFeedbacks
22+
*/
23+
data class GetChatRecordsRequest(
24+
val chatId: kotlin.String,
25+
val appId: kotlin.String? = null,
26+
val offset: kotlin.Int? = null,
27+
val pageSize: kotlin.Int? = null,
28+
val loadCustomFeedbacks: kotlin.Boolean? = null
29+
)
30+

cloudapi-web/src/main/kotlin/cn/edu/buaa/scs/controller/plugins/Monitoring.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.ktor.http.*
1111
import io.ktor.server.application.*
1212
import io.ktor.server.application.hooks.*
1313
import io.ktor.server.plugins.*
14-
import io.ktor.server.plugins.callloging.*
14+
import io.ktor.server.plugins.calllogging.*
1515
import io.ktor.server.request.*
1616
import io.ktor.server.response.*
1717
import io.ktor.util.*
@@ -41,7 +41,7 @@ fun Application.configureMonitoring() {
4141
pathDescription = "",
4242
headers = call.request.headers.toMap(),
4343
version = version,
44-
realIp = call.request.headers["X-Custom-Remote-Addr"] ?: call.request.origin.host,
44+
realIp = call.request.headers["X-Custom-Remote-Addr"] ?: call.request.origin.localHost,
4545
userAgent = userAgent,
4646
)
4747
val logRecordResp = LogRecordResp(
@@ -70,7 +70,8 @@ fun Application.configureMonitoring() {
7070
filter { call -> call.request.path().startsWith("/") }
7171
format { call ->
7272
val logRecord = logRecord(call)
73-
"""${logRecord.requestId} - ${logRecord.user?.id} - ${logRecord.request.method} ${logRecord.request.path} ${logRecord.response.status} ${logRecord.request.userAgent}"""
73+
// 使用新的日志格式化方式
74+
"${logRecord.requestId} - ${logRecord.user?.id} - ${logRecord.request.method} ${logRecord.request.path} ${logRecord.response.status} ${logRecord.request.userAgent}"
7475
}
7576
}
7677

0 commit comments

Comments
 (0)