Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,11 @@ public class AiEntryParser {
|
||||
|
||||
/** 자유 텍스트 → 파싱 결과. 실패/미설정 시 empty. */
|
||||
public Optional<ParsedEntryResponse> parse(String text, LocalDate today) {
|
||||
if (!enabled() || text == null || text.isBlank()) return Optional.empty();
|
||||
if (!enabled() || text == null || text.isBlank()) {
|
||||
log.info("[ai-parse] 건너뜀 — enabled={}, textBlank={}", enabled(), (text == null || text.isBlank()));
|
||||
return Optional.empty();
|
||||
}
|
||||
log.info("[ai-parse] 요청 수신 — text='{}'", text);
|
||||
try {
|
||||
String system = ("""
|
||||
너는 한국어 가계부 입력 도우미다. 사용자가 자연어로 쓴 한 줄 지출/수입 메모를 구조화한다.
|
||||
@@ -81,6 +85,7 @@ public class AiEntryParser {
|
||||
.body(JsonNode.class);
|
||||
|
||||
String out = stripFences(resp.path("content").path(0).path("text").asText("")).trim();
|
||||
log.info("[ai-parse] 모델 원문='{}'", out);
|
||||
JsonNode j = om.readTree(out);
|
||||
|
||||
String type = "INCOME".equalsIgnoreCase(j.path("type").asText("EXPENSE")) ? "INCOME" : "EXPENSE";
|
||||
@@ -90,13 +95,16 @@ public class AiEntryParser {
|
||||
} catch (Exception e) {
|
||||
date = today;
|
||||
}
|
||||
return Optional.of(ParsedEntryResponse.builder()
|
||||
ParsedEntryResponse result = ParsedEntryResponse.builder()
|
||||
.recognized(j.path("recognized").asBoolean(false))
|
||||
.type(type)
|
||||
.amount(Math.max(0, j.path("amount").asLong(0)))
|
||||
.merchant(j.path("merchant").asText(""))
|
||||
.date(date)
|
||||
.build());
|
||||
.build();
|
||||
log.info("[ai-parse] 결과 — recognized={}, type={}, amount={}, merchant={}, date={}",
|
||||
result.isRecognized(), result.getType(), result.getAmount(), result.getMerchant(), result.getDate());
|
||||
return Optional.of(result);
|
||||
} catch (Exception e) {
|
||||
log.warn("[ai-parse] 실패 → 규칙기반 폴백: {}", e.toString());
|
||||
return Optional.empty();
|
||||
|
||||
Reference in New Issue
Block a user