From 3e24386264156027c2d0af60bb0b8b1879e1921b Mon Sep 17 00:00:00 2001 From: Imsung Date: Fri, 18 Nov 2022 18:28:34 +0900 Subject: [PATCH] =?UTF-8?q?-=20url=20=EC=88=98=EC=A0=95=20-=20=EC=BD=94?= =?UTF-8?q?=EB=A3=A8=ED=8B=B4=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20QueryResponseDto=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 + .../CoTEVer/controller/ClientController.kt | 9 ++--- .../example/CoTEVer/dto/QueryRequestDto.kt | 5 --- .../example/CoTEVer/dto/QueryResponseDto.kt | 16 -------- .../example/CoTEVer/dto/QuestionRequestDto.kt | 5 +++ .../CoTEVer/dto/QuestionResponseDto.kt | 25 +++++++++++++ .../example/CoTEVer/service/QueryService.kt | 37 ++++++++----------- 7 files changed, 51 insertions(+), 48 deletions(-) delete mode 100644 src/main/kotlin/com/example/CoTEVer/dto/QueryRequestDto.kt delete mode 100644 src/main/kotlin/com/example/CoTEVer/dto/QueryResponseDto.kt create mode 100644 src/main/kotlin/com/example/CoTEVer/dto/QuestionRequestDto.kt create mode 100644 src/main/kotlin/com/example/CoTEVer/dto/QuestionResponseDto.kt diff --git a/build.gradle.kts b/build.gradle.kts index 5c5fa0e..5a8ac7c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,8 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.springframework.boot:spring-boot-starter-data-mongodb") implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") testImplementation("org.springframework.boot:spring-boot-starter-test") } diff --git a/src/main/kotlin/com/example/CoTEVer/controller/ClientController.kt b/src/main/kotlin/com/example/CoTEVer/controller/ClientController.kt index c5d9594..016cf7d 100644 --- a/src/main/kotlin/com/example/CoTEVer/controller/ClientController.kt +++ b/src/main/kotlin/com/example/CoTEVer/controller/ClientController.kt @@ -1,11 +1,10 @@ package com.example.CoTEVer.controller -import com.example.CoTEVer.dto.QueryRequestDto -import com.example.CoTEVer.dto.QueryResponseDto +import com.example.CoTEVer.dto.QuestionResponseDto +import com.example.CoTEVer.dto.QuestionRequestDto import com.example.CoTEVer.dto.ResultRequestDto import com.example.CoTEVer.service.QueryService import org.springframework.web.bind.annotation.CrossOrigin -import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController @@ -16,8 +15,8 @@ class ClientController( val queryService: QueryService ){ @PostMapping("/query") - fun userQuery(@RequestBody queryRequestDto: QueryRequestDto) : QueryResponseDto{ - return queryService.getAnswer(queryRequestDto.query) + suspend fun userQuery(@RequestBody questionRequestDto: QuestionRequestDto) : QuestionResponseDto{ + return queryService.getAnswer(questionRequestDto) } @PostMapping("/result") diff --git a/src/main/kotlin/com/example/CoTEVer/dto/QueryRequestDto.kt b/src/main/kotlin/com/example/CoTEVer/dto/QueryRequestDto.kt deleted file mode 100644 index b0bfa43..0000000 --- a/src/main/kotlin/com/example/CoTEVer/dto/QueryRequestDto.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.example.CoTEVer.dto - -data class QueryRequestDto( - val query: String -) diff --git a/src/main/kotlin/com/example/CoTEVer/dto/QueryResponseDto.kt b/src/main/kotlin/com/example/CoTEVer/dto/QueryResponseDto.kt deleted file mode 100644 index 8778eb4..0000000 --- a/src/main/kotlin/com/example/CoTEVer/dto/QueryResponseDto.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.example.CoTEVer.dto - -data class QueryResponseDto( - val query : String, - val stepCount : Int, - val finalAnswer : String, - val finalExplanation : String, - val nodeList: List -) - -data class QueryNode( - val subQuestion : String, - val subQuestionKeyword : String, - val subAnswer : String, - val top5List : List>, -) \ No newline at end of file diff --git a/src/main/kotlin/com/example/CoTEVer/dto/QuestionRequestDto.kt b/src/main/kotlin/com/example/CoTEVer/dto/QuestionRequestDto.kt new file mode 100644 index 0000000..b97df11 --- /dev/null +++ b/src/main/kotlin/com/example/CoTEVer/dto/QuestionRequestDto.kt @@ -0,0 +1,5 @@ +package com.example.CoTEVer.dto + +data class QuestionRequestDto( + val question: String +) diff --git a/src/main/kotlin/com/example/CoTEVer/dto/QuestionResponseDto.kt b/src/main/kotlin/com/example/CoTEVer/dto/QuestionResponseDto.kt new file mode 100644 index 0000000..483afdf --- /dev/null +++ b/src/main/kotlin/com/example/CoTEVer/dto/QuestionResponseDto.kt @@ -0,0 +1,25 @@ +package com.example.CoTEVer.dto + +data class QuestionResponseDto( + val question:String, + val explanation:Map, + val output:ApiOutput +) + +data class ApiNode( + val sub_question:String, + val sub_answer:String, + val evidence_document:Map +) + +data class Document( + val url : String, + val title : String, + val document : String, + val score : Float +) + +data class ApiOutput( + val final_explanation:String, + val final_answer:String, +) \ No newline at end of file diff --git a/src/main/kotlin/com/example/CoTEVer/service/QueryService.kt b/src/main/kotlin/com/example/CoTEVer/service/QueryService.kt index 878316d..a40c0be 100644 --- a/src/main/kotlin/com/example/CoTEVer/service/QueryService.kt +++ b/src/main/kotlin/com/example/CoTEVer/service/QueryService.kt @@ -1,34 +1,27 @@ package com.example.CoTEVer.service -import com.example.CoTEVer.dto.QueryResponseDto -import com.example.CoTEVer.dto.QueryNode -import com.example.CoTEVer.dto.ResultRequestDto -import com.example.CoTEVer.entity.Log +import com.example.CoTEVer.dto.* import com.example.CoTEVer.repository.LogRepository +import org.springframework.http.MediaType import org.springframework.stereotype.Service +import org.springframework.web.reactive.function.client.WebClient +import org.springframework.web.reactive.function.client.awaitBody +import org.springframework.web.reactive.function.client.body +import reactor.core.publisher.Mono @Service class QueryService( val logRepository: LogRepository ) { - fun getAnswer(query : String) : QueryResponseDto{ - val res = QueryResponseDto(query, 2, finalAnswer = "A", finalExplanation = "B", - listOf( - QueryNode("subquery1", subQuestionKeyword = "keyword1", subAnswer = "solution1", top5List = listOf( - Pair("www.naver.com","A"), - Pair("www.naverB.com","B"), - Pair("www.naverC.com","C"), - Pair("www.naverC.com","D"), - Pair("www.naverC.com","E"))), - QueryNode("subquery2", subQuestionKeyword = "keyword2", subAnswer = "solution2", top5List = listOf( - Pair("www.google.com","A"), - Pair("www.googleB.com","B"), - Pair("www.googleC.com","C"), - Pair("www.googleD.com","D"), - Pair("www.googleE.com","E"))) - )) - //logRepository.save(Log(test = "A")) - return res + suspend fun getAnswer(questionRequestDto: QuestionRequestDto) : QuestionResponseDto{ + val client = WebClient.create("http://35.206.248.188:8000/test") + val ret = client.post() + .uri("http://35.206.248.188:8000/test") + .contentType(MediaType.APPLICATION_JSON) + .body(Mono.just(questionRequestDto)) + .retrieve() + .awaitBody() + return ret } fun saveResult(resultRequestDto: ResultRequestDto){