Skip to content

Commit ef3d347

Browse files
committed
kts 의존성 추가 및 웨더 툴 수정
1 parent 8ec0564 commit ef3d347

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

build.gradle.kts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ plugins {
66
kotlin("plugin.jpa") version "1.9.25"
77
// 코틀린 코드 스타일 린터
88
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
9+
// 빌드 설정 상수 생성
10+
id("com.github.gmazzo.buildconfig") version "5.3.5"
911
}
1012

1113
group = "com.back"
@@ -107,6 +109,38 @@ ktlint {
107109
}
108110
filter {
109111
exclude("**/generated/**")
112+
exclude("**/BuildConfig.kt")
110113
include("**/kotlin/**")
111114
}
112115
}
116+
117+
buildConfig {
118+
useKotlinOutput()
119+
120+
val regionCodes =
121+
file("src/main/resources/region-codes.yml")
122+
.readText()
123+
.substringAfter("codes:")
124+
.lines()
125+
.filter { it.contains(":") }
126+
.joinToString(", ") { line ->
127+
val parts = line.split(":")
128+
"${parts[0].trim()}: ${parts[1].trim().replace("\"", "")}"
129+
}
130+
131+
val promptsText = file("src/main/resources/prompts.yml").readText()
132+
val systemPrompt =
133+
promptsText
134+
.substringAfter("korea-travel-guide: |")
135+
.substringBefore(" errors:")
136+
.trim()
137+
138+
val errorPrompt =
139+
promptsText
140+
.substringAfter("ai-fallback: \"")
141+
.substringBefore("\"")
142+
143+
buildConfigField("String", "REGION_CODES_DESCRIPTION", "\"\"\"$regionCodes\"\"\"")
144+
buildConfigField("String", "KOREA_TRAVEL_GUIDE_SYSTEM", "\"\"\"$systemPrompt\"\"\"")
145+
buildConfigField("String", "AI_ERROR_FALLBACK", "\"\"\"$errorPrompt\"\"\"")
146+
}

src/main/kotlin/com/back/koreaTravelGuide/common/constant/PromptConstant.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/aiChat/service/AiChatService.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.back.koreaTravelGuide.domain.ai.aiChat.service
22

3-
import com.back.koreaTravelGuide.common.constant.PromptConstant.AI_ERROR_FALLBACK
4-
import com.back.koreaTravelGuide.common.constant.PromptConstant.KOREA_TRAVEL_GUIDE_SYSTEM
3+
import com.back.backend.BuildConfig
54
import com.back.koreaTravelGuide.domain.ai.aiChat.entity.AiChatMessage
65
import com.back.koreaTravelGuide.domain.ai.aiChat.entity.AiChatSession
76
import com.back.koreaTravelGuide.domain.ai.aiChat.entity.SenderType
@@ -66,15 +65,15 @@ class AiChatService(
6665
val response =
6766
try {
6867
chatClient.prompt()
69-
.system(KOREA_TRAVEL_GUIDE_SYSTEM)
68+
.system(BuildConfig.KOREA_TRAVEL_GUIDE_SYSTEM)
7069
.user(message)
7170
.advisors { advisor ->
7271
advisor.param(ChatMemory.CONVERSATION_ID, sessionId.toString())
7372
}
7473
.call()
75-
.content() ?: AI_ERROR_FALLBACK
74+
.content() ?: BuildConfig.AI_ERROR_FALLBACK
7675
} catch (e: Exception) {
77-
AI_ERROR_FALLBACK
76+
BuildConfig.AI_ERROR_FALLBACK
7877
}
7978

8079
val aiMessage =

src/main/kotlin/com/back/koreaTravelGuide/domain/ai/aiChat/tool/WeatherTool.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
package com.back.koreaTravelGuide.domain.ai.aiChat.tool
22

3+
import com.back.backend.BuildConfig
34
import com.back.koreaTravelGuide.domain.ai.weather.service.WeatherService
4-
import com.back.koreaTravelGuide.domain.ai.weather.service.tools.Tools
55
import org.springframework.ai.tool.annotation.Tool
66
import org.springframework.ai.tool.annotation.ToolParam
77
import org.springframework.stereotype.Component
88

99
@Component
1010
class WeatherTool(
1111
private val weatherService: WeatherService,
12-
private val tools: Tools,
1312
) {
1413
@Tool(description = "전국 중기예보를 조회합니다")
1514
fun getWeatherForecast(): String {
16-
val actualBaseTime = tools.validBaseTime(null)
17-
val forecasts = weatherService.fetchMidForecast(actualBaseTime)
15+
val forecasts = weatherService.getWeatherForecast()
1816

1917
return forecasts?.toString() ?: "중기예보 데이터를 가져올 수 없습니다."
2018
}
2119

2220
@Tool(description = "특정 지역의 상세 기온 및 날씨 예보를 조회합니다")
2321
fun getRegionalWeatherDetails(
24-
@ToolParam(description = "지역명 (예: 서울, 부산, 대전, 제주 등)", required = true)
22+
@ToolParam(description = BuildConfig.REGION_CODES_DESCRIPTION, required = true)
2523
location: String,
2624
): String {
27-
val regionCode = tools.getRegionCodeFromLocation(location)
28-
val actualBaseTime = tools.validBaseTime(null)
29-
val forecasts = weatherService.fetchTemperatureAndLandForecast(regionCode, actualBaseTime)
25+
val forecasts = weatherService.getTemperatureAndLandForecast(location)
3026

3127
return forecasts?.toString() ?: "$location 지역의 상세 날씨 정보를 가져올 수 없습니다."
3228
}

src/main/resources/prompts.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
prompts:
2+
system:
3+
korea-travel-guide: |
4+
당신은 한국 여행 전문 AI 가이드입니다.
5+
한국의 관광지, 음식, 문화에 대해 정확하고 친근한 정보를 제공하세요.
6+
답변은 한국어로 해주시고, 구체적인 추천과 팁을 포함해주세요.
7+
사용자에게 도움이 되는 실용적인 여행 정보를 제공하는 것이 목표입니다.
8+
errors:
9+
ai-fallback: "죄송합니다. 일시적인 문제로 응답을 생성할 수 없습니다. 다시 시도해 주세요."

0 commit comments

Comments
 (0)