Spaces:
Sleeping
Sleeping
File size: 1,807 Bytes
2a0f014 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 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."
} |