1+ # finder/run_finder.py
2+ import csv
13import sys
24import os
3-
4- from libs .utils import news_processing
5- from finder import ticker_selector
5+ import time
6+ import requests
67import pandas as pd
7- from langchain_community .llms import Ollama
8-
98
9+ # ---- 경로 세팅 ----
1010project_root = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
1111sys .path .append (project_root )
1212
13+ from libs .utils import news_processing
14+ from finder import ticker_selector
15+ from libs .llm_clients .ollama_client import get_ollama_client # ← 분리된 유틸 임포트
1316
1417def run_finder ():
15- '''
18+ """
1619 전체 프로세스를 조율하여 최종 Top 3 투자 종목 반환
17- '''
20+ """
1821 # --- 1단계: 의존성 객체 및 데이터 준비 ---
19- llm = Ollama (model = "llama3.2" )
20-
2122 try :
22- stability_df = pd .read_csv ('data/stability_score_2025.csv' )
23+ llm = get_ollama_client () # ✅ 헬스체크 및 모델 확인 포함
24+ except Exception as e :
25+ print (str (e ))
26+ return []
27+
28+ csv_path = os .path .join (project_root , "data" , "stability_score_2025.csv" )
29+
30+ try :
31+ stability_df = pd .read_csv (csv_path )
2332 except FileNotFoundError :
24- print ("오류: 'data/stability_score_2025.csv' 파일을 찾을 수 없습니다." )
33+ print (f "오류: { csv_path } 파일을 찾을 수 없습니다." )
2534 return []
2635
2736 # --- 2단계: 주간 뉴스 데이터 수집 및 요약 ---
28- weekly_news_df = news_processing .get_weekly_news_summary (days = 5 , llm_client = llm )
37+ try :
38+ weekly_news_df = news_processing .get_weekly_news_summary (days = 5 , llm_client = llm )
39+ except requests .exceptions .ConnectionError as e :
40+ print (f"[LLM 연결 오류] 뉴스 요약 단계에서 LLM 서버 연결 실패: { e } " )
41+ return []
42+ except requests .exceptions .Timeout as e :
43+ print (f"[LLM 타임아웃] 뉴스 요약 단계에서 응답 지연: { e } " )
44+ return []
45+ except Exception as e :
46+ print (f"[예기치 못한 오류] 뉴스 요약 단계: { e } " )
47+ return []
2948
30- if weekly_news_df . empty :
49+ if weekly_news_df is None or getattr ( weekly_news_df , " empty" , False ) :
3150 print ("분석할 뉴스 데이터가 없어 프로세스를 종료합니다." )
3251 return []
3352
3453 # --- 3단계: 뉴스 데이터와 재무 데이터를 기반으로 Top 3 종목 선정 ---
35- top_3_tickers = ticker_selector .select_top_stocks (
36- news_summary_df = weekly_news_df ,
37- stability_df = stability_df ,
38- llm_client = llm
39- )
54+ try :
55+ top_3_tickers = ticker_selector .select_top_stocks (
56+ news_summary_df = weekly_news_df ,
57+ stability_df = stability_df ,
58+ llm_client = llm
59+ )
60+ except requests .exceptions .ConnectionError as e :
61+ print (f"[LLM 연결 오류] 종목 선정 단계에서 LLM 서버 연결 실패: { e } " )
62+ return []
63+ except requests .exceptions .Timeout as e :
64+ print (f"[LLM 타임아웃] 종목 선정 단계에서 응답 지연: { e } " )
65+ return []
66+ except Exception as e :
67+ print (f"[예기치 못한 오류] 종목 선정 단계: { e } " )
68+ return []
4069
4170 print ("\n 🎉 [Finder 모듈 최종 결과] 투자 추천 Top 3 종목 🎉" )
4271 print (top_3_tickers )
43-
4472 return top_3_tickers
4573
4674if __name__ == '__main__' :
47- run_finder ()
75+ run_finder ()
0 commit comments