diff --git a/stock-lab/app/screener/ai_news/telegram.py b/stock-lab/app/screener/ai_news/telegram.py index b92717c..2f56a63 100644 --- a/stock-lab/app/screener/ai_news/telegram.py +++ b/stock-lab/app/screener/ai_news/telegram.py @@ -37,6 +37,7 @@ def build_message( top_neg: List[Dict[str, Any]], tokens_input: int, tokens_output: int, + mapping: Dict[str, int] | None = None, ) -> str: lines: List[str] = [ f"πŸŒ… *AI λ‰΄μŠ€ 뢄석* \\({_escape(asof)} 08:00\\)", @@ -57,9 +58,16 @@ def build_message( lines.append(_escape("- (μ—†μŒ)")) 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 += [ "", - f"_뢄석: μ‹œμ΄ μƒμœ„ 100μ’…λͺ© Β· 토큰 {tokens_input:,} in / {tokens_output:,} out Β· " + f"_뢄석: μ‹œμ΄ μƒμœ„ 100μ’…λͺ© Β· {mapping_part}" + f"토큰 {tokens_input:,} in / {tokens_output:,} out Β· " f"μ•½ β‚©{cost:,}_", ] return "\n".join(lines) diff --git a/stock-lab/tests/test_ai_news_telegram.py b/stock-lab/tests/test_ai_news_telegram.py index 480d33f..eb71223 100644 --- a/stock-lab/tests/test_ai_news_telegram.py +++ b/stock-lab/tests/test_ai_news_telegram.py @@ -53,3 +53,27 @@ def test_build_message_empty_lists(): # 빈 λ¦¬μŠ€νŠΈλΌλ„ ν—€λ”λŠ” μžˆμ–΄μ•Ό 함 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