86 lines
4.7 KiB
Python
86 lines
4.7 KiB
Python
from langchain_core.messages import AIMessage
|
|
import time
|
|
import json
|
|
|
|
|
|
def create_bear_researcher(llm, memory):
|
|
def bear_node(state) -> dict:
|
|
investment_debate_state = state["investment_debate_state"]
|
|
history = investment_debate_state.get("history", "")
|
|
bear_history = investment_debate_state.get("bear_history", "")
|
|
|
|
current_response = investment_debate_state.get("current_response", "")
|
|
market_research_report = state["market_report"]
|
|
sentiment_report = state["sentiment_report"]
|
|
news_report = state["news_report"]
|
|
fundamentals_report = state["fundamentals_report"]
|
|
|
|
curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
|
|
past_memories = memory.get_memories(curr_situation, n_matches=2)
|
|
|
|
past_memory_str = ""
|
|
for i, rec in enumerate(past_memories, 1):
|
|
past_memory_str += rec["recommendation"] + "\n\n"
|
|
|
|
# 根据配置选择语言
|
|
config = getattr(memory, 'config', {})
|
|
if config.get("output_language", "english") == "chinese":
|
|
prompt = f"""你是一个看跌分析师,提出反对投资该股票的案例。你的目标是提出一个理由充分的论点,强调风险、挑战和负面指标。利用提供的研究和数据来突出潜在的下行风险并有效反驳看涨论点。
|
|
|
|
重点关注的要点:
|
|
|
|
- 风险和挑战:突出可能阻碍股票表现的因素,如市场饱和、财务不稳定或宏观经济威胁。
|
|
- 竞争劣势:强调弱点,如较弱的市场地位、创新下降或来自竞争对手的威胁。
|
|
- 负面指标:使用来自财务数据、市场趋势或最近不利新闻的证据来支持你的立场。
|
|
- 看涨反驳:用具体数据和合理推理批判性地分析看涨论点,暴露弱点或过于乐观的假设。
|
|
- 参与度:以对话风格呈现你的论点,直接与看涨分析师的观点互动并有效辩论,而不是简单地列出事实。
|
|
|
|
可用资源:
|
|
|
|
市场研究报告:{market_research_report}
|
|
社交媒体情绪报告:{sentiment_report}
|
|
最新世界事务新闻:{news_report}
|
|
公司基本面报告:{fundamentals_report}
|
|
辩论对话历史:{history}
|
|
最后的看涨论点:{current_response}
|
|
类似情况的反思和经验教训:{past_memory_str}
|
|
|
|
使用这些信息提供令人信服的看跌论点,反驳看涨声明,并参与展示投资该股票风险和弱点的动态辩论。你还必须解决反思并从过去犯的错误和经验教训中学习。"""
|
|
else:
|
|
prompt = f"""You are a Bear Analyst making the case against investing in the stock. Your goal is to present a well-reasoned argument emphasizing risks, challenges, and negative indicators. Leverage the provided research and data to highlight potential downsides and counter bullish arguments effectively.
|
|
|
|
Key points to focus on:
|
|
|
|
- Risks and Challenges: Highlight factors like market saturation, financial instability, or macroeconomic threats that could hinder the stock's performance.
|
|
- Competitive Weaknesses: Emphasize vulnerabilities such as weaker market positioning, declining innovation, or threats from competitors.
|
|
- Negative Indicators: Use evidence from financial data, market trends, or recent adverse news to support your position.
|
|
- Bull Counterpoints: Critically analyze the bull argument with specific data and sound reasoning, exposing weaknesses or over-optimistic assumptions.
|
|
- Engagement: Present your argument in a conversational style, directly engaging with the bull analyst's points and debating effectively rather than simply listing facts.
|
|
|
|
Resources available:
|
|
|
|
Market research report: {market_research_report}
|
|
Social media sentiment report: {sentiment_report}
|
|
Latest world affairs news: {news_report}
|
|
Company fundamentals report: {fundamentals_report}
|
|
Conversation history of the debate: {history}
|
|
Last bull argument: {current_response}
|
|
Reflections from similar situations and lessons learned: {past_memory_str}
|
|
Use this information to deliver a compelling bear argument, refute the bull's claims, and engage in a dynamic debate that demonstrates the risks and weaknesses of investing in the stock. You must also address reflections and learn from lessons and mistakes you made in the past."""
|
|
|
|
response = llm.invoke(prompt)
|
|
|
|
argument = f"Bear Analyst: {response.content}"
|
|
|
|
new_investment_debate_state = {
|
|
"history": history + "\n" + argument,
|
|
"bear_history": bear_history + "\n" + argument,
|
|
"bull_history": investment_debate_state.get("bull_history", ""),
|
|
"current_response": argument,
|
|
"count": investment_debate_state["count"] + 1,
|
|
}
|
|
|
|
return {"investment_debate_state": new_investment_debate_state}
|
|
|
|
return bear_node
|