This commit is contained in:
MarkLo 2025-11-26 12:39:39 +08:00
parent 5de461e1df
commit ace244e7be
8 changed files with 65 additions and 66 deletions

View File

@ -46,14 +46,13 @@ def create_research_manager(llm, memory):
return text
return text[:max_chars] + "\n...(內容已截斷)"
# 為每個報告設置合理的字符限制
# 模型 gpt-5-mini 的限制是 8192 tokens
# 混合中英文估算: 1 字符 ≈ 1.5-2 tokens (取保守值)
# 目標: 總字符數 < 3500 字符 (約 5250-7000 tokens留足夠 tokens 給 completion)
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 600)
fundamentals_report = truncate_text(fundamentals_report, 600)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
# 整合當前情況
curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
@ -71,8 +70,8 @@ def create_research_manager(llm, memory):
past_memory_str += recommendation + "\n\n"
# 截斷辯論歷史 - 這是最容易超過限制的部分
# 限制辯論歷史在 1200 字符以
history = truncate_text(history, 1200)
# 增加限制以容納更長的辯論內
history = truncate_text(history, 3000)
# 建立提示 (prompt)
prompt = f"""**重要您必須使用繁體中文Traditional Chinese回覆所有內容。**

View File

@ -48,15 +48,14 @@ def create_risk_manager(llm, memory):
return text
return text[:max_chars] + "\n...(內容已截斷)"
# 為每個報告設置合理的字符限制
# 模型 gpt-5-mini 的限制是 8192 tokens
# 混合中英文估算: 1 字符 ≈ 1.5-2 tokens (取保守值)
# 目標: 總字符數 < 3500 字符 (約 5250-7000 tokens留足夠 tokens 給 completion)
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 600)
fundamentals_report = truncate_text(fundamentals_report, 600)
trader_plan = truncate_text(trader_plan, 800)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
trader_plan = truncate_text(trader_plan, 2000)
# 整合當前情況
curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
@ -74,8 +73,8 @@ def create_risk_manager(llm, memory):
past_memory_str += recommendation + "\n\n"
# 截斷辯論歷史 - 這是最容易超過限制的部分
# 限制辯論歷史在 1000 字符以風險辯論通常有3方比投資辯論更長
history = truncate_text(history, 1000)
# 增加限制以容納更長的辯論內風險辯論通常有3方比投資辯論更長
history = truncate_text(history, 3000)
# 建立提示 (prompt)

View File

@ -58,14 +58,13 @@ def create_bear_researcher(llm, memory):
return text[:last_pos + 1] + "\n\n...(為控制長度已精簡)"
return truncated + "...(為控制長度已精簡)"
# 為每個報告設置合理的字符限制
# 模型 gpt-4.1-mini 的限制是 8192 tokens
# 混合中英文估算: 1 字符 ≈ 1.5-2 tokens (取保守值)
# 目標: 總字符數 < 3000 字符 (約 4500-6000 tokens留 2000+ tokens 給 completion)
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 800) # 新聞通常較長但也需要控制
fundamentals_report = truncate_text(fundamentals_report, 600)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"

View File

@ -64,13 +64,11 @@ def create_bull_researcher(llm, memory):
return truncated + "...(為控制長度已精簡)"
# 為每個報告設置合理的字符限制
# 模型 gpt-4.1-mini 的限制是 8192 tokens
# 混合中英文估算: 1 字符 ≈ 1.5-2 tokens (取保守值)
# 目標: 總字符數 < 3000 字符 (約 4500-6000 tokens留 2000+ tokens 給 completion)
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 800) # 新聞通常較長但也需要控制
fundamentals_report = truncate_text(fundamentals_report, 600)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"

View File

@ -53,16 +53,17 @@ def create_risky_debator(llm):
return text
return text[:max_chars] + "\n...(內容已截斷)"
# 截斷各類輸入以控制 token 使用量
# 模型限制: 8192 tokens目標: < 3500 字符
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 600)
fundamentals_report = truncate_text(fundamentals_report, 600)
trader_decision = truncate_text(trader_decision, 800)
history = truncate_text(history, 400)
current_safe_response = truncate_text(current_safe_response, 300)
current_neutral_response = truncate_text(current_neutral_response, 300)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
trader_decision = truncate_text(trader_decision, 2000)
history = truncate_text(history, 1500)
current_safe_response = truncate_text(current_safe_response, 1000)
current_neutral_response = truncate_text(current_neutral_response, 1000)
# 建立提示 (prompt)
prompt = f"""**重要您必須使用繁體中文Traditional Chinese回覆所有內容。**

View File

@ -54,16 +54,17 @@ def create_safe_debator(llm):
return text
return text[:max_chars] + "\n...(內容已截斷)"
# 截斷各類輸入以控制 token 使用量
# 模型限制: 8192 tokens目標: < 3500 字符
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 600)
fundamentals_report = truncate_text(fundamentals_report, 600)
trader_decision = truncate_text(trader_decision, 800)
history = truncate_text(history, 400)
current_risky_response = truncate_text(current_risky_response, 300)
current_neutral_response = truncate_text(current_neutral_response, 300)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
trader_decision = truncate_text(trader_decision, 2000)
history = truncate_text(history, 1500)
current_risky_response = truncate_text(current_risky_response, 1000)
current_neutral_response = truncate_text(current_neutral_response, 1000)
# 建立提示 (prompt)
prompt = f"""**重要您必須使用繁體中文Traditional Chinese回覆所有內容。**

View File

@ -53,16 +53,17 @@ def create_neutral_debator(llm):
return text
return text[:max_chars] + "\n...(內容已截斷)"
# 截斷各類輸入以控制 token 使用量
# 模型限制: 8192 tokens目標: < 3500 字符
market_research_report = truncate_text(market_research_report, 500)
sentiment_report = truncate_text(sentiment_report, 500)
news_report = truncate_text(news_report, 600)
fundamentals_report = truncate_text(fundamentals_report, 600)
trader_decision = truncate_text(trader_decision, 800)
history = truncate_text(history, 400)
current_risky_response = truncate_text(current_risky_response, 300)
current_safe_response = truncate_text(current_safe_response, 300)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report = truncate_text(market_research_report, 2000)
sentiment_report = truncate_text(sentiment_report, 2000)
news_report = truncate_text(news_report, 2500)
fundamentals_report = truncate_text(fundamentals_report, 2000)
trader_decision = truncate_text(trader_decision, 2000)
history = truncate_text(history, 1500)
current_risky_response = truncate_text(current_risky_response, 1000)
current_safe_response = truncate_text(current_safe_response, 1000)
# 建立提示 (prompt)
prompt = f"""**重要您必須使用繁體中文Traditional Chinese回覆所有內容。**

View File

@ -57,13 +57,14 @@ def create_trader(llm, memory):
# 如果找不到合適的分隔符,直接在字符處截斷
return truncated + "...(為控制長度已精簡)"
# 截斷各類報告以控制 token 使用量
# 這些報告將用於記憶檢索embedding和 LLM prompt
market_research_report_truncated = truncate_text(market_research_report, 500)
sentiment_report_truncated = truncate_text(sentiment_report, 500)
news_report_truncated = truncate_text(news_report, 600)
fundamentals_report_truncated = truncate_text(fundamentals_report, 600)
investment_plan_truncated = truncate_text(investment_plan, 800)
# 增加限制以確保 800+ 字的報告不被截斷
market_research_report_truncated = truncate_text(market_research_report, 2000)
sentiment_report_truncated = truncate_text(sentiment_report, 2000)
news_report_truncated = truncate_text(news_report, 2500)
fundamentals_report_truncated = truncate_text(fundamentals_report, 2000)
investment_plan_truncated = truncate_text(investment_plan, 2000)
# 整合當前情況(用於記憶檢索)
curr_situation = f"{market_research_report_truncated}\n\n{sentiment_report_truncated}\n\n{news_report_truncated}\n\n{fundamentals_report_truncated}"