Skip to content

Commit

Permalink
📝 :: response
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 19, 2023
1 parent 06136d1 commit fe7b4cf
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DiaryController(
@GetMapping("/ago")
fun getSevenDaysAgo() = diaryService.getSevenDaysAgo()

@GetMapping("/chatting")
@GetMapping("/chat")
fun test(
@RequestBody @Valid
req: ChattingWithGPTRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.onui.domain.diary.presentation.response

data class ChattingResponse (
val message: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ interface DiaryService {

fun getSevenDaysAgo(): DiaryListResponse

fun chattingWithGPT(req: ChattingWithGPTRequest): Map<*, *>
fun chattingWithGPT(req: ChattingWithGPTRequest): ChattingWithGPTRequest
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.example.onui.domain.diary.exception.DiaryNotFoundException
import com.example.onui.domain.diary.presentation.request.ChattingWithGPTRequest
import com.example.onui.domain.diary.presentation.request.CreateDiaryRequest
import com.example.onui.domain.diary.presentation.request.UpdateDiaryRequest
import com.example.onui.domain.diary.presentation.response.ChattingResponse
import com.example.onui.domain.diary.presentation.response.DiaryDetailResponse
import com.example.onui.domain.diary.presentation.response.DiaryListResponse
import com.example.onui.domain.diary.repository.DiaryRepository
Expand Down Expand Up @@ -86,6 +87,12 @@ class DiaryServiceImpl(
return DiaryListResponse(if (diaries.isEmpty()) null else diaries)
}

override fun chattingWithGPT(req: ChattingWithGPTRequest): Map<*, *> =
gptClient.getGPTQuery(GPTQueryRequest(arrayOf(Message(M_SET1 + req.text!!.toString() + M_SET2 + req.text))))
override fun chattingWithGPT(req: ChattingWithGPTRequest): ChattingResponse {
val res = gptClient.getGPTQuery(
GPTQueryRequest(arrayOf(Message(M_SET1 + req.text!!.toString() + M_SET2 + req.text)))
)

return ChattingResponse(res.choice[0].message.content)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.onui.global.config.feign.GPTFeignConfig
import com.example.onui.infra.feign.gpt.dto.request.GPTQueryRequest
import com.example.onui.infra.feign.gpt.dto.response.GPTResponse
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
Expand All @@ -14,5 +15,5 @@ import org.springframework.web.bind.annotation.RequestBody
interface GPTClient {

@PostMapping(produces = ["application/json"])
fun getGPTQuery(@RequestBody req: GPTQueryRequest): Map<*, *>
fun getGPTQuery(@RequestBody req: GPTQueryRequest): GPTResponse
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.onui.infra.feign.gpt.dto.response

data class Choice (
val index: Int,
val message: GPTMessage,
val finishReason: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.onui.infra.feign.gpt.dto.response

data class GPTMessage (
val content: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.onui.infra.feign.gpt.dto.response

data class GPTResponse (
val choice: MutableList<Choice>
)

0 comments on commit fe7b4cf

Please sign in to comment.