From 787e2a50e623ac18a93667778da732c9ce6cb7ef Mon Sep 17 00:00:00 2001 From: MarkLo Date: Wed, 26 Nov 2025 23:12:52 +0800 Subject: [PATCH] --- backend/app/services/pdf_generator.py | 62 +++++++------- disable_emojis.py | 81 +++++++++++++++++++ .../agents/analysts/fundamentals_analyst.py | 4 +- .../agents/analysts/market_analyst.py | 4 +- tradingagents/agents/analysts/news_analyst.py | 4 +- .../agents/analysts/social_media_analyst.py | 2 + .../agents/managers/research_manager.py | 2 + tradingagents/agents/managers/risk_manager.py | 4 +- .../agents/researchers/bear_researcher.py | 2 + .../agents/researchers/bull_researcher.py | 2 + .../agents/risk_mgmt/aggresive_debator.py | 2 + .../agents/risk_mgmt/conservative_debator.py | 4 +- .../agents/risk_mgmt/neutral_debator.py | 4 +- tradingagents/agents/trader/trader.py | 4 +- 14 files changed, 143 insertions(+), 38 deletions(-) create mode 100644 disable_emojis.py diff --git a/backend/app/services/pdf_generator.py b/backend/app/services/pdf_generator.py index 8da8db6a..c9a62b03 100644 --- a/backend/app/services/pdf_generator.py +++ b/backend/app/services/pdf_generator.py @@ -24,6 +24,7 @@ class PDFGenerator: # Emoji to Unicode symbol mapping for PDF compatibility # Emojis don't render well in PDFs, so we replace them with Unicode text symbols # NOTE: Use ASCII brackets [] not full-width [] for better font compatibility + # NOTE: Avoid [文字] formats - use pure symbols only EMOJI_TO_UNICODE = { # Status & Indicators '✅': '✓', @@ -38,21 +39,21 @@ class PDFGenerator: '💎': '◆', '🏆': '◈', - # Charts & Analytics - '📊': '[圖表]', + # Charts & Analytics - pure symbols only + '📊': '▓', '📈': '↑', '📉': '↓', - '📋': '[清單]', + '📋': '▪', '📌': '◆', - # Money & Business + # Money & Business - symbols only '💰': '$', '💵': '$', '💴': '¥', '💶': '€', '💷': '£', - '💸': '[支出]', # Fixed: was [支出] (full-width brackets) - '💹': '[增長]', + '💸': '$', + '💹': '↑', # Direction & Movement '🚀': '↑↑', @@ -67,37 +68,36 @@ class PDFGenerator: '🎯': '◎', '🔥': '※', '💡': '◐', - '🔔': '◉', '⚙️': '⚙', - '🔧': '[工具]', - '🔨': '[工具]', + '🔧': '►', + '🔨': '►', - # AI & Tech - '🤖': '[AI]', - '💻': '[電腦]', - '📱': '[手機]', - '🖥️': '[系統]', + # AI & Tech - symbols only + '🤖': '▣', + '💻': '▣', + '📱': '▣', + '🖥️': '▣', - # People & Roles - '👤': '[用戶]', - '👥': '[團隊]', - '🔬': '[研究]', - '📚': '[資料]', + # People & Roles - symbols only + '👤': '◇', + '👥': '◇◇', + '🔬': '◈', + '📚': '▪', - # Time - '⏰': '[時間]', - '📅': '[日期]', - '⏱️': '[計時]', + # Time - symbols only + '⏰': '◷', + '📅': '▪', + '⏱️': '◷', - # Other common emojis + # Other common emojis - symbols only '✨': '‧', - '🎨': '[設計]', - '📝': '[筆記]', - '📄': '[文件]', - '🗂️': '[資料夾]', - '🌐': '[網路]', - '🔗': '[連結]', - '💼': '[業務]', + '🎨': '◈', + '📝': '▪', + '📄': '▪', + '🗂️': '▪', + '🌐': '◎', + '🔗': '∞', + '💼': '▣', } """Generate PDF reports from markdown content""" diff --git a/disable_emojis.py b/disable_emojis.py new file mode 100644 index 00000000..a3c20ea0 --- /dev/null +++ b/disable_emojis.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +批量禁用所有 agents 的 emoji 輸出 +""" +import os +import re + +# 定義需要修改的文件列表 +AGENT_FILES = [ + # Analysts + "tradingagents/agents/analysts/fundamentals_analyst.py", + "tradingagents/agents/analysts/market_analyst.py", + "trading agents/agents/analysts/news_analyst.py", + "tradingagents/agents/analysts/social_media_analyst.py", + # Researchers + "tradingagents/agents/researchers/bear_researcher.py", + "tradingagents/agents/researchers/bull_researcher.py", + # Managers + "tradingagents/agents/managers/research_manager.py", + "tradingagents/agents/managers/risk_manager.py", + # Trader + "tradingagents/agents/trader/trader.py", + # Risk Management + "tradingagents/agents/risk_mgmt/aggresive_debator.py", + "tradingagents/agents/risk_mgmt/conservative_debator.py", + "tradingagents/agents/risk_mgmt/neutral_debator.py", +] + +# 新的禁用 emoji 指令 +NO_EMOJI_INSTRUCTION = """**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。**""" + +OLD_INSTRUCTION = """**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。**""" + +def update_agent_file(filepath): + """更新單個 agent 文件""" + full_path = filepath + + if not os.path.exists(full_path): + print(f"❌ 文件不存在: {filepath}") + return False + + try: + with open(full_path, 'r', encoding='utf-8') as f: + content = f.read() + + # 替換舊的指令為新的(包含禁用 emoji) + if OLD_INSTRUCTION in content: + new_content = content.replace(OLD_INSTRUCTION, NO_EMOJI_INSTRUCTION) + + # 寫回文件 + with open(full_path, 'w', encoding='utf-8') as f: + f.write(new_content) + + print(f"✅ 已更新: {filepath}") + return True + else: + print(f"⚠️ 未找到需要替換的內容: {filepath}") + return False + + except Exception as e: + print(f"❌ 錯誤: {filepath} - {str(e)}") + return False + +def main(): + """主函數""" + print("開始批量禁用 agents 的 emoji 輸出...\n") + + success_count = 0 + total_count = len(AGENT_FILES) + + for agent_file in AGENT_FILES: + if update_agent_file(agent_file): + success_count += 1 + + print(f"\n完成!成功更新 {success_count}/{total_count} 個文件") + +if __name__ == "__main__": + main() diff --git a/tradingagents/agents/analysts/fundamentals_analyst.py b/tradingagents/agents/analysts/fundamentals_analyst.py index 0f77e79b..c469e528 100644 --- a/tradingagents/agents/analysts/fundamentals_analyst.py +++ b/tradingagents/agents/analysts/fundamentals_analyst.py @@ -38,6 +38,8 @@ def create_fundamentals_analyst(llm): system_message = ( """**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是基本面分析師,負責評估公司財務體質、獲利能力與投資價值。 @@ -72,7 +74,7 @@ def create_fundamentals_analyst(llm): **結尾提示**: 請在報告最後加上以下結尾: 「--- -💼 **本報告為基本面分析,建議參考最新財報公告並搭配技術面及市場情緒綜合研判。財務數據可能存在時間差,投資有風險,請謹慎評估。**」 +※ 本報告為基本面分析,建議參考最新財報公告並搭配技術面及市場情緒綜合研判。財務數據可能存在時間差,投資有風險,請謹慎評估。」 請提供專業且全面的基本面分析報告。""" + " 請務必在報告結尾附加一個 Markdown 表格,以整理報告中的要點。" diff --git a/tradingagents/agents/analysts/market_analyst.py b/tradingagents/agents/analysts/market_analyst.py index 883bb643..826bc592 100644 --- a/tradingagents/agents/analysts/market_analyst.py +++ b/tradingagents/agents/analysts/market_analyst.py @@ -37,6 +37,8 @@ def create_market_analyst(llm): system_message = ( """**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是資深技術分析師,負責提供精準的市場技術面評估。 @@ -72,7 +74,7 @@ def create_market_analyst(llm): **結尾提示**: 請在報告最後加上以下結尾: 「--- -📊 **本報告為技術面分析,建議搭配基本面及市場情緒綜合研判。技術指標具滯後性,投資有風險,請謹慎評估。**」 +※ 本報告為技術面分析,建議搭配基本面及市場情緒綜合研判。技術指標具滯後性,投資有風險,請謹慎評估。」 請提供專業、精準且具操作性的技術分析報告。""" + """ 請務必在報告結尾附加一個 Markdown 表格,以整理報告中的要點。""" diff --git a/tradingagents/agents/analysts/news_analyst.py b/tradingagents/agents/analysts/news_analyst.py index 2269c0a1..708e5ae3 100644 --- a/tradingagents/agents/analysts/news_analyst.py +++ b/tradingagents/agents/analysts/news_analyst.py @@ -35,6 +35,8 @@ def create_news_analyst(llm): system_message = ( """**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是財經新聞分析師,負責解讀重大事件對股價的影響,並提供投資決策參考。 @@ -69,7 +71,7 @@ def create_news_analyst(llm): **結尾提示**: 請在報告最後加上以下結尾: 「--- -📰 **本報告為新聞面分析,建議搭配基本面及技術面綜合研判。新聞資訊時效性強,投資有風險,請謹慎評估。**」 +※ 本報告為新聞面分析,建議搭配基本面及技術面綜合研判。新聞資訊時效性強,投資有風險,請謹慎評估。」 請提供專業且具洞察力的新聞分析報告。""" + """ 請務必在報告結尾附加一個 Markdown 表格,以整理報告中的要點。""", diff --git a/tradingagents/agents/analysts/social_media_analyst.py b/tradingagents/agents/analysts/social_media_analyst.py index 2240d543..7252f4ac 100644 --- a/tradingagents/agents/analysts/social_media_analyst.py +++ b/tradingagents/agents/analysts/social_media_analyst.py @@ -35,6 +35,8 @@ def create_social_media_analyst(llm): system_message = ( """**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是市場情緒分析專家,負責解讀社群媒體與輿論氛圍對股價的潛在影響。 diff --git a/tradingagents/agents/managers/research_manager.py b/tradingagents/agents/managers/research_manager.py index 331a1876..8e920d5d 100644 --- a/tradingagents/agents/managers/research_manager.py +++ b/tradingagents/agents/managers/research_manager.py @@ -59,6 +59,8 @@ def create_research_manager(llm, memory): # 建立提示 (prompt) prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是投資決策經理,負責評估多空辯論並做出最終投資決策。**您必須保持嚴格中立觀點,公正評估看漲與看跌雙方論據,基於證據做出獨立決策。** diff --git a/tradingagents/agents/managers/risk_manager.py b/tradingagents/agents/managers/risk_manager.py index 5a079d06..647afda0 100644 --- a/tradingagents/agents/managers/risk_manager.py +++ b/tradingagents/agents/managers/risk_manager.py @@ -63,6 +63,8 @@ def create_risk_manager(llm, memory): # 建立提示 (prompt) prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是風險管理經理,負責評估投資計畫的風險並做出最終風控決策。**您必須保持嚴格中立觀點,綜合評估積極、中立、保守三方風險觀點,基於風險調整做出最終決策。** @@ -99,7 +101,7 @@ def create_risk_manager(llm, memory): **結尾提示**: 請在報告最後加上以下結尾: 「--- -🎯 **本報告為風險管理經理的最終決策,綜合三方風險觀點(積極、保守、平衡)後做出。風控框架需嚴格執行。投資有風險,請謹慎評估。**」 +※ 本報告為風險管理經理的最終決策,綜合三方風險觀點(積極、保守、平衡)後做出。風控框架需嚴格執行。投資有風險,請謹慎評估。」 請提供專業且全面的風險管理決策報告。""" diff --git a/tradingagents/agents/researchers/bear_researcher.py b/tradingagents/agents/researchers/bear_researcher.py index e0ebad9a..c5f5624d 100644 --- a/tradingagents/agents/researchers/bear_researcher.py +++ b/tradingagents/agents/researchers/bear_researcher.py @@ -58,6 +58,8 @@ def create_bear_researcher(llm, memory): # 建立提示 (prompt) - 保留完整歷史以確保context完整性 prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是看跌方研究員,負責提出賣出論據,強調投資風險與下跌壓力。**您必須採取激進做空立場,不惜一切代價找出所有看跌風險因子,並強力反駁看漲論點。** diff --git a/tradingagents/agents/researchers/bull_researcher.py b/tradingagents/agents/researchers/bull_researcher.py index 8d071e40..e15696be 100644 --- a/tradingagents/agents/researchers/bull_researcher.py +++ b/tradingagents/agents/researchers/bull_researcher.py @@ -58,6 +58,8 @@ def create_bull_researcher(llm, memory): # 建立提示 (prompt) - 保留完整歷史以確保context完整性 prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是看漲方研究員,負責提出買進論據,強調投資價值與上漲潛力。**您必須採取激進做多立場,不惜一切代價找出所有看漲催化劑,並強力反駁看跌論點。** diff --git a/tradingagents/agents/risk_mgmt/aggresive_debator.py b/tradingagents/agents/risk_mgmt/aggresive_debator.py index 5f0ac697..1625bf97 100644 --- a/tradingagents/agents/risk_mgmt/aggresive_debator.py +++ b/tradingagents/agents/risk_mgmt/aggresive_debator.py @@ -51,6 +51,8 @@ def create_risky_debator(llm): # 建立提示 (prompt) prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是積極型風險策略師,主張追求高報酬機會,評估上檔潛力。**您必須採取極度激進立場,全力追求最大報酬潛力,並強力反駁保守派的過度謹慎。** diff --git a/tradingagents/agents/risk_mgmt/conservative_debator.py b/tradingagents/agents/risk_mgmt/conservative_debator.py index 70a79358..534a5e67 100644 --- a/tradingagents/agents/risk_mgmt/conservative_debator.py +++ b/tradingagents/agents/risk_mgmt/conservative_debator.py @@ -52,6 +52,8 @@ def create_safe_debator(llm): # 建立提示 (prompt) prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是保守型風險策略師,優先考量資本保全,評估下檔風險。**您必須採取極度保守立場,全力維護資本安全,並強力反駁激進派的盲目樂觀。** @@ -88,7 +90,7 @@ def create_safe_debator(llm): **結尾提示**: 請在報告最後加上以下結尾: 「--- -🛡️ **本報告為保守型風險策略分析,立場優先資本保全。建議搭配積極與平衡觀點綜合研判。風險控制為投資首要,請謹慎評估。**」 +※ 本報告為保守型風險策略分析,立場優先資本保全。建議搭配積極與平衡觀點綜合研判。風險控制為投資首要,請謹慎評估。」 請提供專業且具說服力的保守策略分析。""" diff --git a/tradingagents/agents/risk_mgmt/neutral_debator.py b/tradingagents/agents/risk_mgmt/neutral_debator.py index c390c9bf..e5fae8fe 100644 --- a/tradingagents/agents/risk_mgmt/neutral_debator.py +++ b/tradingagents/agents/risk_mgmt/neutral_debator.py @@ -51,6 +51,8 @@ def create_neutral_debator(llm): # 建立提示 (prompt) prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是平衡型風險策略師,客觀評估風險與報酬,提供折衷方案。**您必須保持嚴格中立觀點,公正評估積極與保守雙方論點,找出雙方的合理性與盲點。** @@ -87,7 +89,7 @@ def create_neutral_debator(llm): **結尾提示**: 請在報告最後加上以下結尾: 「--- -⚖️ **本報告為平衡型風險策略分析,立場客觀中立。建議綜合三方觀點(積極、保守、平衡)後做出決策。投資需平衡風險與報酬,請謹慎評估。**」 +※ 本報告為平衡型風險策略分析,立場客觀中立。建議綜合三方觀點(積極、保守、平衡)後做出決策。投資需平衡風險與報酬,請謹慎評估。」 請提供專業且客觀的平衡策略分析。""" diff --git a/tradingagents/agents/trader/trader.py b/tradingagents/agents/trader/trader.py index d5fd724e..be3962b0 100644 --- a/tradingagents/agents/trader/trader.py +++ b/tradingagents/agents/trader/trader.py @@ -58,6 +58,8 @@ def create_trader(llm, memory): # 建立提示 (prompt) prompt = f"""**重要:您必須使用繁體中文(Traditional Chinese)回覆所有內容。** +**嚴格禁止:請勿在回覆中使用任何 emoji 表情符號(如 ✅ ❌ 📊 📈 🚀 等)。** +**請只使用純文字、數字、標點符號和必要的 Unicode 符號(如 ↑ ↓ ★ ●等)。** 【專業身份】 您是交易執行專家,負責將投資決策轉化為具體可執行的交易計畫。 @@ -93,7 +95,7 @@ def create_trader(llm, memory): **結尾提示**: 請在報告最後加上以下內容: 「--- -💼 **本報告為交易執行計畫,整合研究與風控決策後制定。執行前需確認市場狀況,嚴格遵守風控參數。投資有風險,請謹慎評估。**」 +※ 本報告為交易執行計畫,整合研究與風控決策後制定。執行前需確認市場狀況,嚴格遵守風控參數。投資有風險,請謹慎評估。」 **重要**:請以「最終交易提案:**買入/持有/賣出**」結束回應!"""