Files
Source/project/STOCK_APP/backend/graph/nodes.py
T
cooney 315105cebb 랭그래프 활용한 주식 정보 도출 프로젝트
- 투자 의견 조회
ㄴ 전반적인 주식 판단 기준(ex. 채무, 리스크 등등)을 기준으로 판단하여 도출
- 투자 추천
ex)
{
  "tickers": [
    "NVDA", "GOOGL", "AAPL"
  ],
  "risk_type": "aggressive"
}
2026-06-19 18:03:05 +09:00

79 lines
2.6 KiB
Python

from backend.services.news_service import get_news
from backend.services.financial_service import get_financial_info
from backend.services.technical_service import get_technical_info
from backend.services.competitor_service import get_competitor_info
from langchain_core.prompts import ChatPromptTemplate
from backend.ai.llm import hugging_llm
from backend.prompts.all_prompt import REPORT_PROMPT
prompt = ChatPromptTemplate.from_template(REPORT_PROMPT)
report_chain = prompt | hugging_llm
async def news_node(state):
news_list = await get_news(state["company_name"])
return {"news": news_list}
async def financial_node(state):
financials = await get_financial_info(state["ticker"])
return {"financials": financials}
async def technical_node(state):
technicals = await get_technical_info(state["ticker"])
return {"technicals": technicals}
async def competitor_node(state):
competitors = await get_competitor_info(state["ticker"])
return {"competitors": competitors}
async def report_node(state):
"""
수집된 정보를 LLM 에게 넘기고 분석 요청
1. 뉴스기사
2. 재무정보(시가총액, 매출, 순이익...)
3. 기술적 지표(현재주가, 20일선, 60일선, rsi...)
4. 경쟁회사 재무 정보
"""
news_text = "\n".join([f"제목 : {n.title}\n내용 : {n.snippet}" for n in state["news"]])
financials = state['financials']
financial_text = f"""
시가총액 : {financials['market_cap']}
매출 : {financials['revenue']}
총자산 : {financials['total_assets']}
순이익 : {financials['net_income']}
PER : {financials['pe_ratio']}
PBR : {financials['pb_ratio']}
"""
technicals = state['technicals']
technical_text = f"""
현재주가 : {technicals['current_price']}
20일선 : {technicals['sma20']}
60일선 : {technicals['sma60']}
RSI : {technicals['rsi']}
MACD : {technicals['macd']}
MACD_SIGNAL : {technicals['macd_signal']}
추세 : {technicals['trend']}
"""
competitor_text = "\n".join([f"""
티커 : {c['ticker']}
회사 : {c['company_name']}
시가총액 : {c['market_cap']}
PER : {c['pe_ratio']}
매출성장률 : {c['revenue_growth']}
순이익률 : {c['profit_margin']}
""" for c in state['competitors']])
report = await report_chain.ainvoke(
{
"company_name" : state["company_name"],
"news": news_text,
"financials": financial_text,
"technicals": technical_text,
"competitors": competitor_text,
}
)
return {"report": report.content}