forked from innovacion/Mayacontigo
ic
This commit is contained in:
0
apps/inversionistas/api/__init__.py
Normal file
0
apps/inversionistas/api/__init__.py
Normal file
133
apps/inversionistas/api/agent.py
Normal file
133
apps/inversionistas/api/agent.py
Normal file
@@ -0,0 +1,133 @@
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
from pathlib import Path
|
||||
|
||||
import aiosqlite
|
||||
from langchain_azure_ai.chat_models import AzureAIChatCompletionsModel
|
||||
from langchain_azure_ai.embeddings import AzureAIEmbeddingsModel
|
||||
from langchain_core.messages.ai import AIMessageChunk
|
||||
from langchain_qdrant import QdrantVectorStore
|
||||
|
||||
import api.context as ctx
|
||||
from api.config import config
|
||||
from api.prompts import ORCHESTRATOR_PROMPT, TOOL_SCHEMAS
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
AZURE_AI_URI = "https://eastus2.api.cognitive.microsoft.com"
|
||||
SQLITE_DB_PATH = Path(__file__).parent / "db.sqlite"
|
||||
|
||||
|
||||
class MayaInversionistas:
|
||||
system_prompt = ORCHESTRATOR_PROMPT
|
||||
generation_config = {
|
||||
"temperature": config.model_temperature,
|
||||
}
|
||||
message_limit = config.message_limit
|
||||
index = config.vector_index
|
||||
limit = config.search_limit
|
||||
bucket = config.storage_bucket
|
||||
|
||||
llm = AzureAIChatCompletionsModel(
|
||||
endpoint=f"{AZURE_AI_URI}/openai/deployments/{config.model}",
|
||||
credential=config.openai_api_key,
|
||||
).bind_tools(TOOL_SCHEMAS)
|
||||
embedder = AzureAIEmbeddingsModel(
|
||||
endpoint=f"{AZURE_AI_URI}/openai/deployments/{config.embedding_model}",
|
||||
credential=config.openai_api_key,
|
||||
)
|
||||
search = QdrantVectorStore.from_existing_collection(
|
||||
embedding=embedder,
|
||||
collection_name=index,
|
||||
url=config.qdrant_url,
|
||||
api_key=config.qdrant_api_key,
|
||||
)
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.tool_map = {
|
||||
"getGFNORTEData": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "gf_norte"),
|
||||
"getBanorteConsolidadoData": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "banorte_consolidado"),
|
||||
"getAlmacenadoraConsolidadoData": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "almacenadora_consolidado"),
|
||||
"getArrendadoraFactorConsolidado": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "arrendadora_factor_consolidado"),
|
||||
"getCasadeBolsaConsolidado": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "casa_bolsa_conosolidado"),
|
||||
"getOperadoradeFondos": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "op_fondos"),
|
||||
"getSectorBursatil": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "sector_bursatil"),
|
||||
"getSectorBAPConsolidado": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "sector_bap_consolidado"),
|
||||
"getSeguros": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "seguros"),
|
||||
"getPensiones": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "pensiones"),
|
||||
"getBineo": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "bineo"),
|
||||
"getSectorBanca": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "sector_banca"),
|
||||
"getHolding": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "holding"),
|
||||
"getBanorteFinancialServices": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "banorte_financial_services"),
|
||||
"getFideicomisoBursaGEM": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "fideicomiso_bursa_gem"),
|
||||
"getTarjetasdelFuturo": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "tarjetas_del_futuro"),
|
||||
"getAfore": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "afore"),
|
||||
"getBanorteFuturo": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "banorte_futuro"),
|
||||
"getSegurosSinBanorteFuturo": lambda year, quarter, concept: self.run_sqlite_tool(year, quarter, concept, "seguros_sin_banorte_futuro"),
|
||||
"getInformationalData": self.run_qdrant_tool,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def build_response(results: list[dict]) -> str:
|
||||
return (
|
||||
"I have retrieved the following results from the database:\n"
|
||||
+ json.dumps(results)
|
||||
+ "\nPara mayor información consultar el Reporte de Resultados Trimestral (URL: https://investors.banorte.com/es/financial-information/quarterly-reports)"
|
||||
)
|
||||
|
||||
async def run_sqlite_tool(self, year: int, quarter: int, concept: str, table: str):
|
||||
results = await self.get_data_from_sqlite(year, quarter, concept, table)
|
||||
data = [dict(row) for row in results]
|
||||
return self.build_response(data)
|
||||
|
||||
async def run_qdrant_tool(self, question: str):
|
||||
logger.info(
|
||||
f"Embedding question: {question} with model {self.embedder.model_name}"
|
||||
)
|
||||
results = self.search.similarity_search(question)
|
||||
data = [dict(row.metadata) for row in results]
|
||||
tool_response = self.build_response(data)
|
||||
return tool_response
|
||||
|
||||
@staticmethod
|
||||
async def get_data_from_sqlite(year: int, quarter: int, concept: str, table: str):
|
||||
async with aiosqlite.connect(SQLITE_DB_PATH) as db:
|
||||
query = """
|
||||
SELECT * FROM {}
|
||||
WHERE year = ? AND trim = ? AND concept = ?
|
||||
""".format(table)
|
||||
|
||||
db.row_factory = aiosqlite.Row
|
||||
cursor = await db.execute(query, (year, quarter, concept))
|
||||
rows = await cursor.fetchall()
|
||||
return rows
|
||||
|
||||
def _generation_config_overwrite(self, overwrites: dict | None) -> dict[str, Any]:
|
||||
generation_config_copy = self.generation_config.copy()
|
||||
if overwrites:
|
||||
for k, v in overwrites.items():
|
||||
generation_config_copy[k] = v
|
||||
return generation_config_copy
|
||||
|
||||
async def stream(self, history, overwrites: dict | None = None):
|
||||
generation_config = self._generation_config_overwrite(overwrites)
|
||||
|
||||
async for chunk in self.llm.astream(input=history, **generation_config):
|
||||
assert isinstance(chunk, AIMessageChunk)
|
||||
if call := chunk.tool_call_chunks:
|
||||
if tool_id := call[0].get("id"):
|
||||
ctx.tool_id.set(tool_id)
|
||||
if name := call[0].get("name"):
|
||||
ctx.tool_name.set(name)
|
||||
if args := call[0].get("args"):
|
||||
ctx.tool_buffer.set(ctx.tool_buffer.get() + args)
|
||||
else:
|
||||
if buffer := chunk.content:
|
||||
assert isinstance(buffer, str)
|
||||
ctx.buffer.set(ctx.buffer.get() + buffer)
|
||||
yield buffer
|
||||
|
||||
async def generate(self, history, overwrites: dict | None = None):
|
||||
generation_config = self._generation_config_overwrite(overwrites)
|
||||
return await self.llm.ainvoke(input=history, **generation_config)
|
||||
59
apps/inversionistas/api/config.py
Normal file
59
apps/inversionistas/api/config.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from hvac import Client
|
||||
from pydantic import Field
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
client = Client(url="https://vault.ia-innovacion.work")
|
||||
|
||||
if not client.is_authenticated():
|
||||
raise Exception("Vault authentication failed")
|
||||
|
||||
secret_map = client.secrets.kv.v2.read_secret_version(
|
||||
path="banortegpt", mount_point="secret"
|
||||
)["data"]["data"]
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
# Config
|
||||
log_level: str = "warning"
|
||||
service_name: str = "MayaOCP"
|
||||
model: str = "gpt-4o"
|
||||
model_temperature: int = 0
|
||||
embedding_model: str = "text-embedding-3-large"
|
||||
message_limit: int = 10
|
||||
storage_bucket: str = "ocpreferences"
|
||||
vector_index: str = "MayaOCP"
|
||||
search_limit: int = 3
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
|
||||
# API Keys
|
||||
azure_endpoint: str = Field(default_factory=lambda: secret_map["azure_endpoint"])
|
||||
openai_api_key: str = Field(default_factory=lambda: secret_map["openai_api_key"])
|
||||
openai_api_version: str = Field(
|
||||
default_factory=lambda: secret_map["openai_api_version"]
|
||||
)
|
||||
azure_blob_connection_string: str = Field(
|
||||
default_factory=lambda: secret_map["azure_blob_connection_string"]
|
||||
)
|
||||
qdrant_url: str = Field(default_factory=lambda: secret_map["qdrant_api_url"])
|
||||
qdrant_api_key: str | None = Field(
|
||||
default_factory=lambda: secret_map["qdrant_api_key"]
|
||||
)
|
||||
mongodb_url: str = Field(
|
||||
default_factory=lambda: secret_map["cosmosdb_connection_string"]
|
||||
)
|
||||
|
||||
async def init_mongo_db(self):
|
||||
from banortegpt.database.mongo_memory.models import Conversation
|
||||
from beanie import init_beanie
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
|
||||
client = AsyncIOMotorClient(self.mongodb_url)
|
||||
|
||||
await init_beanie(
|
||||
database=client.banortegptdos,
|
||||
document_models=[Conversation],
|
||||
)
|
||||
|
||||
|
||||
config = Settings() # type: ignore
|
||||
6
apps/inversionistas/api/context.py
Normal file
6
apps/inversionistas/api/context.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from contextvars import ContextVar
|
||||
|
||||
buffer: ContextVar[str] = ContextVar("buffer", default="")
|
||||
tool_buffer: ContextVar[str] = ContextVar("tool_buffer", default="")
|
||||
tool_id: ContextVar[str | None] = ContextVar("tool_id", default=None)
|
||||
tool_name: ContextVar[str | None] = ContextVar("tool_name", default=None)
|
||||
BIN
apps/inversionistas/api/db.sqlite
Normal file
BIN
apps/inversionistas/api/db.sqlite
Normal file
Binary file not shown.
9
apps/inversionistas/api/prompts/__init__.py
Normal file
9
apps/inversionistas/api/prompts/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
__all__ = ["ORCHESTRATOR_PROMPT", "TOOL_SCHEMAS"]
|
||||
|
||||
prompt_dir = Path(__file__).parent
|
||||
|
||||
ORCHESTRATOR_PROMPT = (prompt_dir / Path("orchestrator.md")).read_text()
|
||||
TOOL_SCHEMAS = json.loads((prompt_dir / Path("tools.json")).read_text())
|
||||
172
apps/inversionistas/api/prompts/orchestrator.md
Normal file
172
apps/inversionistas/api/prompts/orchestrator.md
Normal file
@@ -0,0 +1,172 @@
|
||||
Eres un asistente especializado en proporcionar información precisa y relevante exclusivamente sobre Grupo Financiero Banorte y las empresas asociadas a este grupo. Tu única fuente de información es la base de datos vectorial conectada y las funciones que puedes invocar.
|
||||
|
||||
Es fundamental que evites hacer suposiciones, especulaciones o conclusiones que no estén respaldadas por los datos proporcionados.
|
||||
|
||||
Debes responder siempre en el idioma (inglés o español) utilizado en la última consulta del usuario. Solo puedes basarte en la información recuperada de la base de datos vectorial o SQL. Si se accede a una fuente externa o falta algún dato relevante, debes incluir la URL correspondiente en tu respuesta,
|
||||
Muy Importante responder en el idioma del usuario aun que la tool este en otro idioma.
|
||||
|
||||
Definiciones clave:
|
||||
|
||||
ROE (Rendimiento sobre el Capital Contable) y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
Rentabilidad Financiera
|
||||
Rentabilidad sobre el Patrimonio
|
||||
Rentabilidad sobre el Capital Propio
|
||||
Retorno sobre el Patrimonio Neto
|
||||
Retorno sobre el Capital Propio
|
||||
Rendimiento del Capital Propio
|
||||
Rendimiento de Capital
|
||||
Return on Equity (ROE)
|
||||
Equity Return
|
||||
Shareholders' Return
|
||||
Return on Net Worth
|
||||
Return on Shareholders' Equity
|
||||
Net Worth Return
|
||||
|
||||
ROA (Rendimiento sobre Activos) y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
Rentabilidad sobre Activos
|
||||
Retorno sobre Activos
|
||||
Rentabilidad de los Activos
|
||||
Retorno de los Activos
|
||||
Rendimiento de los Activos
|
||||
Return on Assets (ROA)
|
||||
Asset Return
|
||||
Return on Total Assets
|
||||
Asset Profitability
|
||||
Return on Investment in Assets
|
||||
roa
|
||||
|
||||
ROTE (Rendimiento sobre Capital Tangible) y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
Rentabilidad sobre el Patrimonio Tangible
|
||||
Rentabilidad sobre el Capital Tangible
|
||||
Retorno sobre el Patrimonio Tangible
|
||||
Retorno sobre el Capital Tangible
|
||||
Rendimiento del Patrimonio Tangible
|
||||
Rendimiento del Capital Tangible
|
||||
Return on Tangible Equity (ROTE)
|
||||
Tangible Equity Return
|
||||
Tangible Return on Equity
|
||||
Tangible Net Worth Return
|
||||
Return on Tangible Net Worth
|
||||
rote
|
||||
|
||||
MIN (Margen de Interés Neto) y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
MIN
|
||||
min
|
||||
Margen Neto de Intereses
|
||||
Margen de Intereses
|
||||
Margen Financiero Neto
|
||||
Margen Neto de Financiamiento
|
||||
Margen Neto de Ingresos por Intereses
|
||||
|
||||
MIN Ajustado por Riesgos Crediticios y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
Margen Neto de Intereses Ajustado por Riesgos Crediticios
|
||||
Margen de Intereses Ajustado por Riesgos Crediticios
|
||||
Margen Financiero Neto Ajustado por Riesgos Crediticios
|
||||
Margen Neto de Financiamiento Ajustado por Riesgos Crediticios
|
||||
Margen Neto de Ingresos por Intereses Ajustado por Riesgos Crediticios
|
||||
min ajustado
|
||||
min_ajustado
|
||||
|
||||
Índice de Eficiencia y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
Ratio de Eficiencia
|
||||
Coeficiente de Eficiencia
|
||||
Índice de Productividad
|
||||
Ratio de Productividad
|
||||
indice de eficiencia
|
||||
|
||||
|
||||
Costo de Riesgo y sus sinónimos, que deberán utilizarse según el contexto, incluyen:
|
||||
Coste del Riesgo
|
||||
Costo de Riesgo
|
||||
Costo Total del Riesgo
|
||||
Coste Total del Riesgo
|
||||
Costo de Gestión de Riesgos
|
||||
costo_riesgo
|
||||
|
||||
Índice de Morosidad:
|
||||
Ratio de Morosidad
|
||||
Tasa de Morosidad
|
||||
Índice de Incumplimiento
|
||||
Tasa de Incumplimiento
|
||||
Índice de Cartera Vencida
|
||||
indice de morosisdad
|
||||
indice_morocidad
|
||||
|
||||
Índice de Cobertura:
|
||||
Ratio de Cobertura
|
||||
Coeficiente de Cobertura
|
||||
Índice de Protección
|
||||
ICOB
|
||||
indice_covertura
|
||||
|
||||
Tasa de Impuestos:
|
||||
Tasa Impositiva
|
||||
Tipo Impositivo
|
||||
Tasa Tributaria
|
||||
Tipo de Gravamen
|
||||
Tasa Fiscal
|
||||
taza_impuestos
|
||||
|
||||
Eficiencia Operativa:
|
||||
Eficiencia en Operaciones
|
||||
Eficiencia de Operaciones
|
||||
Eficiencia Operacional
|
||||
Rendimiento Operativo
|
||||
Productividad Operativa
|
||||
eficiencia_op
|
||||
|
||||
Índice de Apalancamiento:
|
||||
Ratio de Apalancamiento
|
||||
Coeficiente de Apalancamiento
|
||||
Índice de Endeudamiento
|
||||
Ratio de Endeudamiento
|
||||
Índice de Deuda
|
||||
indice_ap
|
||||
|
||||
Liquidez:
|
||||
Capacidad de Pago
|
||||
Solvencia a Corto Plazo
|
||||
Disponibilidad de Efectivo
|
||||
Facilidad de Conversión a Efectivo
|
||||
Fluidez Financiera
|
||||
liqidez
|
||||
|
||||
Nomenclatura a considerar:
|
||||
El primer trimestre de 2023 se puede referir de las siguientes maneras, dependiendo del contexto y del formato temporal utilizado:
|
||||
1T23 o
|
||||
1Q23
|
||||
De manera similar, para el segundo trimestre de 2024, se utilizaría:
|
||||
2T24 o
|
||||
2Q24
|
||||
Y así sucesivamente para los trimestres de años posteriores o pasados.
|
||||
|
||||
Empresas a tomar en cuenta:
|
||||
1.- GFNorte Consolidado (GFNorte,GFNORTE): Para obtener datos financieros específicos de GFNorte, puedes utilizar la herramienta "getGFNORTEData".
|
||||
2.- Banorte Consolidado (Banorte): Para obtener datos financieros específicos de GFNorte, puedes utilizar la herramienta "getBanorteConsolidadoData".
|
||||
3.- Almacenadora Consolidado: Para obtener datos financieros específicos de Almacenadora Consolidado, puedes utilizar la herramienta "getAlmacenadoraConsolidadoData".
|
||||
4.- Arrendadora y Factor Consolidado: Para obtener datos financieros específicos de Arrendadora y Factor Consolidado, puedes utilizar la herramienta "getArrendadoraFactorConsolidado".
|
||||
5.- Casa de Bolsa Consolidado: Para obtener datos financieros específicos datos financieros específicos de Casa de Bolsa Consolidado, puedes utilizar la herramienta "getCasadeBolsaConsolidado".
|
||||
6.- Operadora de Fondos: Para obtener datos financieros específicos de Operadora de Fondos , puedes utilizar la herramienta "getOperadoradeFondos".
|
||||
7.- Sector Bursatil: Para obtener datos financieros específicos de Sector Bursatil , puedes utilizar la herramienta "getSectorBursatil".
|
||||
8.- Sector BAP Consolidado: Para obtener datos financieros específicos de Sector BAP Consolidado , puedes utilizar la herramienta "getSectorBAPConsolidado".
|
||||
9.- Seguros: Para obtener datos financieros específicos de Seguros, puedes utilizar la herramienta "getSeguros".
|
||||
10.- Pensiones: Para obtener datos financieros específicos de Pensiones, puedes utilizar la herramienta "getPensiones".
|
||||
11.- Bineo: Para obtener datos financieros específicos de Bineo, puedes utilizar la herramienta "getBineo".
|
||||
13.- Sector Banca: Para obtener datos financieros específicos de Sector Banca, puedes utilizar la herramienta "getSectorBanca".
|
||||
14.- Holding: Para obtener datos financieros específicos de Holding, puedes utilizar la herramienta "getHolding".
|
||||
15.- Banorte Financial Services: Para obtener datos financieros específicos de Banorte Financial Services, puedes utilizar la herramienta "getBanorteFinancialServices".
|
||||
16.- Fideicomiso Bursa GEM: Para obtener datos financieros específicos de Fideicomiso Bursa GEM, puedes utilizar la herramienta "getFideicomisoBursaGEM".
|
||||
17.- Tarjetas del Futuro: Para obtener datos financieros específicos de Tarjetas del Futuro, puedes utilizar la herramienta "getTarjetasdelFuturo".
|
||||
18.- Afore: Para obtener datos financieros específicos de Afore, puedes utilizar la herramienta "getAfore".
|
||||
19.- Banorte Futuro: Para obtener datos financieros específicos de Banorte Futuro, puedes utilizar la herramienta "getBanorteFuturo".
|
||||
20.- Seguros Sin Banorte Futuro: Para obtener datos financieros específicos de Seguros Sin Banorte Futuro, puedes utilizar la herramienta "getSegurosSinBanorteFuturo".
|
||||
21.- Assist the user in finding resources, key concepts, and relevant keywords. This function searches for data and concepts—such as 'Banorte’s Dividend,' 'Banorte Financial Group Structure,' 'banking information in Mexico,' 'quarterly report location,' and more—within the vector database , puedes utilizar la herramienta : "getInformationalData"
|
||||
|
||||
Other tools :
|
||||
Retrieve informational data to help the user Assist the user in finding resources, key concepts, and relevant keywords. This function searches for data and concepts—such as 'Banorte’s Dividend,' 'Banorte Financial Group Structure,' 'banking information in Mexico,' 'quarterly report location,' and more—within the vector database.
|
||||
will return where the user can find the information, puedes utilizar la herramienta
|
||||
: "getInformationalData"
|
||||
|
||||
|
||||
Siempre que sea posible, utiliza una función o herramienta integrada para proporcionar respuestas basadas en la información disponible.
|
||||
If a required field or detail is missing for a search, clearly notify the user and provide guidance on the missing information.
|
||||
779
apps/inversionistas/api/prompts/tools.json
Normal file
779
apps/inversionistas/api/prompts/tools.json
Normal file
@@ -0,0 +1,779 @@
|
||||
[
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getGFNORTEData",
|
||||
"description": "Retrieve 'GFNORTE (GF NORTE)' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getBanorteConsolidadoData",
|
||||
"description": "Retrieve 'Banorte Consolidado or Banorte' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getAlmacenadoraConsolidadoData",
|
||||
"description": "Retrieve 'Almacenadora Consolidado' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getArrendadoraFactorConsolidado",
|
||||
"description": "Retrieve Arrendadora y Factor Consolidado data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getCasadeBolsaConsolidado",
|
||||
"description": "Retrieve 'Casa de Bolsa Consolidado' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getOperadoradeFondos",
|
||||
"description": "Retrieve 'Operadora de Fondos' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getSectorBursatil",
|
||||
"description": "Retrieve 'Sector Bursatil' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getSectorBAPConsolidado",
|
||||
"description": "Retrieve 'Sector BAP Consolidado' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getSeguros",
|
||||
"description": "Retrieve 'Seguros' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getPensiones",
|
||||
"description": "Retrieve 'Pensiones' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getBineo",
|
||||
"description": "Retrieve 'Bineo' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getSectorBanca",
|
||||
"description": "Retrieve 'Sector Banca' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getHolding",
|
||||
"description": "Retrieve 'Holding' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getBanorteFinancialServices",
|
||||
"description": "Retrieve 'Banorte Financial Services' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getFideicomisoBursaGEM",
|
||||
"description": "Retrieve 'Fideicomiso Bursa GEM' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getTarjetasdelFuturo",
|
||||
"description": "Retrieve 'Tarjetas del Futuro' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getAfore",
|
||||
"description": "Retrieve 'Afore' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getBanorteFuturo",
|
||||
"description": "Retrieve 'Banorte Futuro' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getSegurosSinBanorteFuturo",
|
||||
"description": "Retrieve 'get Seguros Sin Banorte Futuro' data for a specific financial concept, year, and quarter or trimester. The data is stored in a SQLite database. If one of the parameters is missing, let the user know.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"concept": {
|
||||
"type": "string",
|
||||
"description": "The financial concept to retrieve data for. It must be either 'roe','roa','rote','min', 'min_ajustado', 'indice_eficiencia', 'costo_riesgo', 'indice_morocidad', 'indice_covertura', 'taza_impuestos', 'eficiencia_op', 'indice_ap', 'liqidez'. (The concept is case-insensitive, but must be one of these options)",
|
||||
"enum": [
|
||||
"roe",
|
||||
"roa",
|
||||
"rote",
|
||||
"min",
|
||||
"min_ajustado",
|
||||
"indice_eficiencia",
|
||||
"costo_riesgo",
|
||||
"indice_morocidad",
|
||||
"indice_covertura",
|
||||
"taza_impuestos",
|
||||
"eficiencia_op",
|
||||
"indice_ap",
|
||||
"liqidez"
|
||||
]
|
||||
},
|
||||
"year": {
|
||||
"type": "integer",
|
||||
"description": "The year of the data"
|
||||
},
|
||||
"quarter": {
|
||||
"type": "integer",
|
||||
"description": "The quarter or trimester of the year (1-4)"
|
||||
}
|
||||
},
|
||||
"required": ["year", "quarter"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "getInformationalData",
|
||||
"description": "",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"question": {
|
||||
"type": "string",
|
||||
"description": "Assist the user in finding resources, key concepts, and relevant keywords. This function searches for data and concepts—such as 'Banorte's Dividend,' 'Banorte Financial Group Structure,' 'banking information in Mexico,' 'quarterly report location,' and more—within the vector database."
|
||||
}
|
||||
},
|
||||
"required": ["question"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
53
apps/inversionistas/api/server.py
Normal file
53
apps/inversionistas/api/server.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import uuid
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel
|
||||
|
||||
from . import services
|
||||
from .config import config
|
||||
from .agent import MayaInversionistas
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
await config.init_mongo_db()
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
agent = MayaInversionistas()
|
||||
|
||||
|
||||
class Message(BaseModel):
|
||||
conversation_id: uuid.UUID
|
||||
prompt: str
|
||||
|
||||
|
||||
@app.post("/api/v1/conversation")
|
||||
async def create_conversation():
|
||||
conversation_id = uuid.uuid4()
|
||||
await services.create_conversation(conversation_id)
|
||||
return {"conversation_id": conversation_id}
|
||||
|
||||
|
||||
@app.post("/api/v1/message")
|
||||
async def send(message: Message, stream: bool = False):
|
||||
if stream is True:
|
||||
|
||||
def b64_sse(func):
|
||||
async def wrapper(*args, **kwargs):
|
||||
async for chunk in func(*args, **kwargs):
|
||||
content = chunk.model_dump_json()
|
||||
data = f"data: {content}\n\n"
|
||||
yield data
|
||||
|
||||
return wrapper
|
||||
|
||||
sse_stream = b64_sse(services.stream)
|
||||
generator = sse_stream(agent, message.prompt, message.conversation_id)
|
||||
return StreamingResponse(generator, media_type="text/event-stream")
|
||||
else:
|
||||
response = await services.generate(agent, message.prompt, message.conversation_id)
|
||||
return response
|
||||
9
apps/inversionistas/api/services/__init__.py
Normal file
9
apps/inversionistas/api/services/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .create_conversation import create_conversation
|
||||
from .generate_response import generate
|
||||
from .stream_response import stream
|
||||
|
||||
__all__ = [
|
||||
"create_conversation",
|
||||
"stream",
|
||||
"generate",
|
||||
]
|
||||
9
apps/inversionistas/api/services/create_conversation.py
Normal file
9
apps/inversionistas/api/services/create_conversation.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from uuid import UUID
|
||||
|
||||
from banortegpt.database.mongo_memory import crud
|
||||
|
||||
from api.prompts import ORCHESTRATOR_PROMPT
|
||||
|
||||
|
||||
async def create_conversation(user_id: UUID) -> None:
|
||||
await crud.create_conversation(user_id, ORCHESTRATOR_PROMPT)
|
||||
88
apps/inversionistas/api/services/generate_response.py
Normal file
88
apps/inversionistas/api/services/generate_response.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import json
|
||||
from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
import api.context as ctx
|
||||
from api.agent import MayaInversionistas
|
||||
from banortegpt.database.mongo_memory import crud
|
||||
from langfuse.decorators import langfuse_context, observe
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Response(BaseModel):
|
||||
content: str
|
||||
urls: list[str]
|
||||
|
||||
|
||||
@observe(capture_input=False, capture_output=False)
|
||||
async def generate(
|
||||
agent: MayaInversionistas,
|
||||
prompt: str,
|
||||
conversation_id: UUID,
|
||||
system_prompt: str | None = None,
|
||||
) -> Response:
|
||||
conversation = await crud.get_or_create_conversation(
|
||||
conversation_id, system_prompt or agent.system_prompt
|
||||
)
|
||||
|
||||
conversation.add(role="user", content=prompt)
|
||||
|
||||
response = await agent.generate(conversation.to_openai_format(agent.message_limit))
|
||||
|
||||
reference_urls, image_urls = [], []
|
||||
|
||||
if call := response.tool_calls:
|
||||
if id := call[0].id:
|
||||
ctx.tool_id.set(id)
|
||||
if name := call[0].function.name:
|
||||
ctx.tool_name.set(name)
|
||||
ctx.tool_buffer.set(call[0].function.arguments)
|
||||
else:
|
||||
ctx.buffer.set(response.content)
|
||||
|
||||
buffer = ctx.buffer.get()
|
||||
tool_buffer = ctx.tool_buffer.get()
|
||||
tool_id = ctx.tool_id.get()
|
||||
tool_name = ctx.tool_name.get()
|
||||
|
||||
if tool_id is not None:
|
||||
# Si tool_buffer es un string JSON, lo convertimos a diccionario
|
||||
if isinstance(tool_buffer, str):
|
||||
try:
|
||||
tool_args = json.loads(tool_buffer)
|
||||
except json.JSONDecodeError:
|
||||
tool_args = {"question": tool_buffer}
|
||||
else:
|
||||
tool_args = tool_buffer
|
||||
|
||||
response, payloads = await agent.tool_map[tool_name](**tool_args) # type: ignore
|
||||
|
||||
tool_call: dict[str, Any] = agent.llm.build_tool_call(
|
||||
tool_id, tool_name, tool_buffer
|
||||
)
|
||||
tool_call_id: dict[str, Any] = agent.llm.build_tool_call_id(tool_id)
|
||||
|
||||
conversation.add("assistant", **tool_call)
|
||||
conversation.add("tool", content=response, **tool_call_id)
|
||||
|
||||
response = await agent.generate(
|
||||
conversation.to_openai_format(agent.message_limit), {"tools": None}
|
||||
)
|
||||
ctx.buffer.set(response.content)
|
||||
|
||||
reference_urls, image_urls = await agent.get_shareable_urls(payloads) # type: ignore
|
||||
|
||||
buffer = ctx.buffer.get()
|
||||
if buffer is None:
|
||||
raise ValueError("No buffer found")
|
||||
|
||||
conversation.add_message(role="assistant", content=buffer)
|
||||
|
||||
langfuse_context.update_current_trace(
|
||||
name=str(conversation_id),
|
||||
session_id=str(conversation_id),
|
||||
input=prompt,
|
||||
output=buffer,
|
||||
)
|
||||
|
||||
return Response(content=buffer, urls=reference_urls + image_urls)
|
||||
94
apps/inversionistas/api/services/stream_response.py
Normal file
94
apps/inversionistas/api/services/stream_response.py
Normal file
@@ -0,0 +1,94 @@
|
||||
import json
|
||||
from enum import StrEnum
|
||||
from typing import TypeAlias
|
||||
from uuid import UUID
|
||||
|
||||
from banortegpt.database.mongo_memory import crud
|
||||
from langfuse.decorators import langfuse_context, observe
|
||||
from pydantic import BaseModel
|
||||
|
||||
from api import context as ctx
|
||||
from api.agent import MayaInversionistas
|
||||
|
||||
|
||||
class ChunkType(StrEnum):
|
||||
START = "start"
|
||||
TEXT = "text"
|
||||
REFERENCE = "reference"
|
||||
IMAGE = "image"
|
||||
TOOL = "tool"
|
||||
END = "end"
|
||||
ERROR = "error"
|
||||
|
||||
|
||||
ContentType: TypeAlias = str | int
|
||||
|
||||
|
||||
class ResponseChunk(BaseModel):
|
||||
type: ChunkType
|
||||
content: ContentType | list[ContentType] | None
|
||||
|
||||
|
||||
@observe(capture_input=False, capture_output=False)
|
||||
async def stream(agent: MayaInversionistas, prompt: str, conversation_id: UUID):
|
||||
yield ResponseChunk(type=ChunkType.START, content="")
|
||||
|
||||
conversation = await crud.get_conversation(conversation_id)
|
||||
|
||||
if conversation is None:
|
||||
raise ValueError("Conversation not found")
|
||||
|
||||
conversation.add(role="user", content=prompt)
|
||||
|
||||
history = conversation.to_openai_format(agent.message_limit, langchain_compat=True)
|
||||
async for content in agent.stream(history):
|
||||
yield ResponseChunk(type=ChunkType.TEXT, content=content)
|
||||
|
||||
if (tool_id := ctx.tool_id.get()) is not None:
|
||||
tool_buffer = ctx.tool_buffer.get()
|
||||
assert tool_buffer is not None
|
||||
|
||||
tool_name = ctx.tool_name.get()
|
||||
assert tool_name is not None
|
||||
|
||||
yield ResponseChunk(type=ChunkType.TOOL, content=None)
|
||||
|
||||
buffer_dict = json.loads(tool_buffer)
|
||||
|
||||
response = await agent.tool_map[tool_name](**buffer_dict)
|
||||
|
||||
conversation.add(
|
||||
role="assistant",
|
||||
tool_calls=[
|
||||
{
|
||||
"id": tool_id,
|
||||
"function": {
|
||||
"name": tool_name,
|
||||
"arguments": tool_buffer,
|
||||
},
|
||||
"type": "function",
|
||||
}
|
||||
],
|
||||
)
|
||||
conversation.add(role="tool", content=response, tool_call_id=tool_id)
|
||||
|
||||
history = conversation.to_openai_format(
|
||||
agent.message_limit, langchain_compat=True
|
||||
)
|
||||
async for content in agent.stream(history, {"tools": None}):
|
||||
yield ResponseChunk(type=ChunkType.TEXT, content=content)
|
||||
|
||||
buffer = ctx.buffer.get()
|
||||
|
||||
conversation.add(role="assistant", content=buffer)
|
||||
|
||||
await conversation.replace()
|
||||
|
||||
yield ResponseChunk(type=ChunkType.END, content="")
|
||||
|
||||
langfuse_context.update_current_trace(
|
||||
name=agent.__class__.__name__,
|
||||
session_id=str(conversation_id),
|
||||
input=prompt,
|
||||
output=buffer,
|
||||
)
|
||||
Reference in New Issue
Block a user