Skip to content

Commit

Permalink
⭐ :: chatting with GPT-3.5-turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 19, 2023
1 parent a078883 commit bb16bad
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 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("/test")
@GetMapping("/chat")
fun test(
@RequestBody @Valid
req: ChattingWithGPTRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.example.onui.global.common.facade.UserFacade
import com.example.onui.global.config.error.exception.PermissionDeniedException
import com.example.onui.infra.feign.gpt.GPTClient
import com.example.onui.infra.feign.gpt.dto.request.GPTQueryRequest
import com.example.onui.infra.feign.gpt.dto.request.Message
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand Down Expand Up @@ -86,5 +87,5 @@ class DiaryServiceImpl(
}

override fun chattingWithGPT(req: ChattingWithGPTRequest): Map<*, *> =
gptClient.getGPTQuery(GPTQueryRequest(M_SET1 + req.text!!.toString() + M_SET2 + req.text))
gptClient.getGPTQuery(GPTQueryRequest(arrayOf(Message(M_SET1 + req.text!!.toString() + M_SET2 + req.text))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ class MissionController(
@RequestBody @Valid
req: CompleteMissionRequest
): MissionListResponse = missionService.complete(req.missionId!!)

@GetMapping("/test")
fun test() {missionService.test()}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ interface MissionService {
fun complete(missionId: UUID): MissionListResponse

fun assignMission(user: User, randomMissions: MutableList<Mission>)

fun test()
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ class MissionServiceImpl(
)
)
}

@Transactional
override fun test() {
assignMission(userFacade.getCurrentUser(), missionRepository.findAllByMissionType(MissionType.RANDOM))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@

data class GPTQueryRequest(

val prompt: String,
val model: String = "gpt-4-1106-preview",
val maxTokens: Int = 1000,
val temperature: Int = 2
)
val messages: Array<Message>,
val model: String = "gpt-3.5-turbo-1106",
) {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as GPTQueryRequest

if (!messages.contentEquals(other.messages)) return false
if (model != other.model) return false

return true
}

override fun hashCode(): Int {
var result = messages.contentHashCode()
result = 31 * result + model.hashCode()
return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.onui.infra.feign.gpt.dto.request

data class Message (

val content: String,
val role: String = "user"
)

0 comments on commit bb16bad

Please sign in to comment.