Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| class VertexSemanticAgent: | |
| def __init__(self, ticker): | |
| self.ticker = ticker.upper() | |
| self.api_key = os.getenv("FMP_API_KEY") | |
| self.base_url = "https://financialmodelingprep.com/api/v4/sec_filing_segment" | |
| def get_sec_risk_factors(self): | |
| """ | |
| Extrae la sección 'Item 1A' (Risk Factors) del reporte más reciente. | |
| """ | |
| params = { | |
| "symbol": self.ticker, | |
| "type": "10-K", | |
| "segment": "item1a", | |
| "apikey": self.api_key | |
| } | |
| try: | |
| response = requests.get(self.base_url, params=params) | |
| data = response.json() | |
| if data and isinstance(data, list): | |
| # Retornamos el texto del primer (más reciente) reporte encontrado | |
| return data[0].get("content", "No se encontró contenido en el Item 1A.") | |
| return "No se hallaron filings 10-K para este ticker." | |
| except Exception as e: | |
| return f"Error conectando con FMP: {str(e)}" | |
| def judge_risks(self, text): | |
| """ | |
| Aquí es donde entraría el LLM. Por ahora, hacemos un análisis de | |
| fuerza bruta buscando palabras clave de alta peligrosidad. | |
| """ | |
| red_flags = ["litigation", "breach", "cybersecurity", "bankruptcy", "insolvency", "investigation"] | |
| found = [word for word in red_flags if word in text.lower()] | |
| score = len(found) | |
| return { | |
| "semantic_score": score, # A más alto, más riesgo | |
| "detected_keywords": found, | |
| "summary": f"Se detectaron {score} factores de riesgo críticos en el texto." | |
| } |