feat(ai_news): telegram includes article mapping stats line

This commit is contained in:
2026-05-14 02:12:17 +09:00
parent bbe5221e57
commit 19aed304cb
2 changed files with 33 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ def build_message(
top_neg: List[Dict[str, Any]], top_neg: List[Dict[str, Any]],
tokens_input: int, tokens_input: int,
tokens_output: int, tokens_output: int,
mapping: Dict[str, int] | None = None,
) -> str: ) -> str:
lines: List[str] = [ lines: List[str] = [
f"🌅 *AI 뉴스 분석* \\({_escape(asof)} 08:00\\)", f"🌅 *AI 뉴스 분석* \\({_escape(asof)} 08:00\\)",
@@ -57,9 +58,16 @@ def build_message(
lines.append(_escape("- (없음)")) lines.append(_escape("- (없음)"))
cost = _cost_won(tokens_input, tokens_output) cost = _cost_won(tokens_input, tokens_output)
mapping_part = ""
if mapping:
mapping_part = (
f"매핑 {mapping['hit_tickers']}/100 ticker "
f"\\({mapping['matched_pairs']}쌍 / articles {mapping['total_articles']}\\) · "
)
lines += [ lines += [
"", "",
f"_분석: 시총 상위 100종목 · 토큰 {tokens_input:,} in / {tokens_output:,} out · " f"_분석: 시총 상위 100종목 · {mapping_part}"
f"토큰 {tokens_input:,} in / {tokens_output:,} out · "
f"약 ₩{cost:,}_", f"약 ₩{cost:,}_",
] ]
return "\n".join(lines) return "\n".join(lines)

View File

@@ -53,3 +53,27 @@ def test_build_message_empty_lists():
# 빈 리스트라도 헤더는 있어야 함 # 빈 리스트라도 헤더는 있어야 함
assert "호재 Top" in msg assert "호재 Top" in msg
assert "악재 Top" in msg assert "악재 Top" in msg
def test_build_message_includes_mapping_line():
msg = tg.build_message(
asof="2026-05-14",
top_pos=[_row("005930", 8.5, "HBM 호재")],
top_neg=[],
tokens_input=1000, tokens_output=200,
mapping={"total_articles": 35, "matched_pairs": 50, "hit_tickers": 42},
)
assert "매핑" in msg
assert "42" in msg
assert "50" in msg
assert "35" in msg
def test_build_message_without_mapping_omits_line():
msg = tg.build_message(
asof="2026-05-14",
top_pos=[],
top_neg=[],
tokens_input=1000, tokens_output=200,
)
assert "매핑" not in msg