57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
import time
|
|
import json
|
|
from tradingagents.i18n import get_prompts
|
|
|
|
def create_fundamentals_analyst(llm, toolkit):
|
|
def fundamentals_analyst_node(state):
|
|
current_date = state["trade_date"]
|
|
ticker = state["company_of_interest"]
|
|
company_name = state["company_of_interest"]
|
|
|
|
if toolkit.config["online_tools"]:
|
|
tools = [toolkit.get_fundamentals_openai]
|
|
else:
|
|
tools = [
|
|
toolkit.get_finnhub_company_insider_sentiment,
|
|
toolkit.get_finnhub_company_insider_transactions,
|
|
toolkit.get_simfin_balance_sheet,
|
|
toolkit.get_simfin_cashflow,
|
|
toolkit.get_simfin_income_stmt,
|
|
]
|
|
|
|
system_message = (
|
|
get_prompts("analysts", "fundamentals_analyst", "system_message")
|
|
)
|
|
|
|
prompt = ChatPromptTemplate.from_messages(
|
|
[
|
|
(
|
|
"system",
|
|
get_prompts("analysts", "template")
|
|
),
|
|
MessagesPlaceholder(variable_name="messages"),
|
|
]
|
|
)
|
|
|
|
prompt = prompt.partial(system_message=system_message)
|
|
prompt = prompt.partial(tool_names=", ".join([tool.name for tool in tools]))
|
|
prompt = prompt.partial(current_date=current_date)
|
|
prompt = prompt.partial(ticker=ticker)
|
|
|
|
chain = prompt | llm.bind_tools(tools)
|
|
|
|
result = chain.invoke(state["messages"])
|
|
|
|
report = ""
|
|
|
|
if len(result.tool_calls) == 0:
|
|
report = result.content
|
|
|
|
return {
|
|
"messages": [result],
|
|
"fundamentals_report": report,
|
|
}
|
|
|
|
return fundamentals_analyst_node
|