Skip to content

Commit

Permalink
πŸ“ :: GPT 닀듬기
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 22, 2023
1 parent f3156e4 commit a593834
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.regex.Pattern

@Service
@Transactional(readOnly = true)
Expand All @@ -35,17 +34,17 @@ class DiaryServiceImpl(
) : DiaryService {

private companion object {
const val M_SET = "λ„ˆμ˜ 이름은 μ˜€λˆ„μ΄μ΄κ³  직업은 상담사야.\nμ•„λž˜ λ¦¬μŠ€νŠΈλŠ” λ‚΄κ°€ μ„ νƒν•œ 감정이야.\n"
const val M_SET = "λ‚΄ 이름은 %sμ•Ό. μ•„λž˜ λ¦¬μŠ€νŠΈλŠ” λ‚΄κ°€ μ„ νƒν•œ 감정이야.\n"
const val M_SET2 = "\nλ‚΄ 감정을 λΆ„μ„ν•˜κ³  λ˜λ„λ‘ 짧게 μ‘΄λŒ“λ§λ‘œ μ†”λ£¨μ…˜μ„ μ œκ³΅ν•΄μ€˜."
const val REGEX = "https://%s.s3.%s.amazonaws.com/%s([\\w-]+)/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}).(png|jpg|jpeg|pdf|svg|HEIC)"
const val IMG_REGEX = "https://%s.s3.%s.amazonaws.com/%s([\\w-]+)/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}).(png|jpg|jpeg|pdf|svg|HEIC)"
}

@Transactional
override fun createDiary(req: CreateDiaryRequest): DiaryDetailResponse {

val user = userFacade.getCurrentUser()

if(req.image != null && !REGEX.format(s3Property.bucket, s3Property.region, s3Property.dir).toRegex().matches(req.image))
if(req.image != null && !IMG_REGEX.format(s3Property.bucket, s3Property.region, s3Property.dir).toRegex().matches(req.image))
throw InvalidImageUrlException

val now = LocalDateTime.now()
Expand Down Expand Up @@ -98,7 +97,7 @@ class DiaryServiceImpl(

override fun chattingWithGPT(req: ChattingWithGPTRequest): ChattingResponse {
val res = gptClient.getGPTQuery(
GPTQueryRequest(arrayOf(Message(M_SET + req.tagList.toString() + M_SET2)))
GPTQueryRequest(arrayOf(Message(M_SET.format(userFacade.getCurrentUser().name) + req.tagList.toString() + M_SET2)))
)

return ChattingResponse(res.choices[0].message.content)
Expand Down

0 comments on commit a593834

Please sign in to comment.