레디스 및 구조 수정중

This commit is contained in:
2026-02-25 16:56:34 +09:00
parent 89f54bae55
commit ec02f27200
10 changed files with 428 additions and 131 deletions

View File

@@ -59,13 +59,25 @@ def _normalize_recommendations(rec: dict) -> dict:
"""
if not rec:
return rec
# 이미 recommendations_by_rule 키가 있으면 그대로 사용
if rec.get("recommendations_by_rule"):
# Case 1: Already normalized (dict)
if isinstance(rec.get("recommendations_by_rule"), dict):
return rec
# recommendations 리스트를 rule 기준으로 그룹화
raw_list = rec.get("recommendations", [])
# Determine the source of the recommendation list
raw_list = []
if "recommendations" in rec and isinstance(rec["recommendations"], list):
raw_list = rec["recommendations"]
elif "recommendations_by_rule" in rec and isinstance(rec["recommendations_by_rule"], list):
# This is the case that causes the bug
raw_list = rec["recommendations_by_rule"]
if not raw_list:
# if there is no list to process, make sure the output has a dict
rec["recommendations_by_rule"] = {}
return rec
# Group the list by rule
by_rule: dict = {}
for item in raw_list:
rule = (
@@ -75,6 +87,8 @@ def _normalize_recommendations(rec: dict) -> dict:
or "general"
)
by_rule.setdefault(rule, []).append(item)
# Return the original dict with the new/replaced 'recommendations_by_rule'
return {**rec, "recommendations_by_rule": by_rule}