This commit is contained in:
2026-04-09 13:17:52 +09:00
parent 8bb099e4f6
commit 95e44b18d0
6 changed files with 11832 additions and 9160 deletions
+13 -1
View File
@@ -618,7 +618,19 @@ object RagService {
return try {
val raw = callLlamaWithSchema(prompt)
println("getAiNewsScore $raw")
val json = Json { ignoreUnknownKeys = true }.parseToJsonElement(raw).jsonObject
// 💡 [핵심 해결책] 마크다운 블록 및 앞뒤 쓸데없는 텍스트 완벽 차단
val startIndex = raw.indexOf("{")
val endIndex = raw.lastIndexOf("}")
// '{' 부터 '}' 까지만 정확하게 잘라냄
val sanitizedRaw = if (startIndex != -1 && endIndex != -1) {
raw.substring(startIndex, endIndex + 1)
} else {
raw // 중괄호를 못 찾았을 경우 대비 (기본 fallback)
}
// 정제된 문자열로 JSON 파싱
val json = Json { ignoreUnknownKeys = true }.parseToJsonElement(sanitizedRaw).jsonObject
val score = json["score"]?.jsonPrimitive?.double ?: 50.0
val reason = json["reason"]?.jsonPrimitive?.content ?: "뉴스 분석 완료"