iatoolkit 0.3.8__py3-none-any.whl → 0.3.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of iatoolkit might be problematic. Click here for more details.
- iatoolkit/__init__.py +2 -0
- iatoolkit/base_company.py +6 -0
- iatoolkit/cli_commands.py +77 -0
- iatoolkit/iatoolkit.py +21 -68
- {iatoolkit-0.3.8.dist-info → iatoolkit-0.3.9.dist-info}/METADATA +1 -1
- {iatoolkit-0.3.8.dist-info → iatoolkit-0.3.9.dist-info}/RECORD +9 -8
- services/dispatcher_service.py +4 -0
- {iatoolkit-0.3.8.dist-info → iatoolkit-0.3.9.dist-info}/WHEEL +0 -0
- {iatoolkit-0.3.8.dist-info → iatoolkit-0.3.9.dist-info}/top_level.txt +0 -0
iatoolkit/__init__.py
CHANGED
|
@@ -21,6 +21,7 @@ from services.excel_service import ExcelService
|
|
|
21
21
|
from services.dispatcher_service import Dispatcher
|
|
22
22
|
from services.document_service import DocumentService
|
|
23
23
|
from services.search_service import SearchService
|
|
24
|
+
from services.query_service import QueryService
|
|
24
25
|
from repositories.profile_repo import ProfileRepo
|
|
25
26
|
from repositories.llm_query_repo import LLMQueryRepo
|
|
26
27
|
from repositories.database_manager import DatabaseManager
|
|
@@ -39,6 +40,7 @@ __all__ = [
|
|
|
39
40
|
'ExcelService',
|
|
40
41
|
'Dispatcher',
|
|
41
42
|
'DocumentService',
|
|
43
|
+
'QueryService',
|
|
42
44
|
'SearchService',
|
|
43
45
|
'ProfileRepo',
|
|
44
46
|
'LLMQueryRepo',
|
iatoolkit/base_company.py
CHANGED
|
@@ -43,5 +43,11 @@ class BaseCompany(ABC):
|
|
|
43
43
|
def get_metadata_from_filename(self, filename: str) -> dict:
|
|
44
44
|
raise NotImplementedError("La subclase debe implementar el método get_query_context()")
|
|
45
45
|
|
|
46
|
+
def register_cli_commands(self, app):
|
|
47
|
+
"""
|
|
48
|
+
optional method for a company definition of it's cli commands
|
|
49
|
+
"""
|
|
50
|
+
pass
|
|
51
|
+
|
|
46
52
|
def unsupported_operation(self, tag):
|
|
47
53
|
raise NotImplementedError(f"La operación '{tag}' no está soportada por esta empresa.")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import logging
|
|
3
|
+
from iatoolkit import IAToolkit
|
|
4
|
+
from services.dispatcher_service import Dispatcher
|
|
5
|
+
from services.profile_service import ProfileService
|
|
6
|
+
|
|
7
|
+
def register_core_commands(app):
|
|
8
|
+
"""Registra los comandos CLI del núcleo de IAToolkit."""
|
|
9
|
+
|
|
10
|
+
@app.cli.command("setup-all-companies")
|
|
11
|
+
def setup_all_companies():
|
|
12
|
+
"""🗄️ Inicializa todas las compañías registradas en la base de datos."""
|
|
13
|
+
try:
|
|
14
|
+
dispatcher = IAToolkit.get_instance().get_injector().get(Dispatcher)
|
|
15
|
+
click.echo("🚀 Inicializando base de datos y compañías...")
|
|
16
|
+
dispatcher.setup_all_companies()
|
|
17
|
+
click.echo("✅ Base de datos y compañías inicializadas correctamente.")
|
|
18
|
+
except Exception as e:
|
|
19
|
+
logging.exception(e)
|
|
20
|
+
click.echo(f"❌ Error: {e}")
|
|
21
|
+
|
|
22
|
+
@app.cli.command("setup-company")
|
|
23
|
+
@click.argument("company_short_name")
|
|
24
|
+
def setup_company(company_short_name: str):
|
|
25
|
+
"""⚙️ Genera una nueva API key para una compañía ya registrada."""
|
|
26
|
+
try:
|
|
27
|
+
profile_service = IAToolkit.get_instance().get_injector().get(ProfileService)
|
|
28
|
+
click.echo(f"🔑 Generando API key para '{company_short_name}'...")
|
|
29
|
+
result = profile_service.new_api_key(company_short_name)
|
|
30
|
+
|
|
31
|
+
if 'error' in result:
|
|
32
|
+
click.echo(f"❌ Error: {result['error']}")
|
|
33
|
+
click.echo("👉 Asegúrate de que el nombre de la compañía es correcto y está registrada.")
|
|
34
|
+
else:
|
|
35
|
+
click.echo("✅ ¡Configuración lista! Agrega esta variable a tu entorno:")
|
|
36
|
+
click.echo(f"IATOOLKIT_API_KEY={result['api-key']}")
|
|
37
|
+
except Exception as e:
|
|
38
|
+
logging.exception(e)
|
|
39
|
+
click.echo(f"❌ Ocurrió un error inesperado durante la configuración: {e}")
|
|
40
|
+
|
|
41
|
+
@app.cli.command("encrypt-key")
|
|
42
|
+
@click.argument("key")
|
|
43
|
+
def api_key(key: str):
|
|
44
|
+
from common.util import Utility
|
|
45
|
+
|
|
46
|
+
util = IAToolkit.get_instance().get_injector().get(Utility)
|
|
47
|
+
try:
|
|
48
|
+
encrypt_key = util.encrypt_key(key)
|
|
49
|
+
click.echo(f'la clave encriptada es: {encrypt_key} \n')
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logging.exception(e)
|
|
52
|
+
click.echo(f"Error: {str(e)}")
|
|
53
|
+
|
|
54
|
+
@app.cli.command("exec-tasks")
|
|
55
|
+
@click.argument("company_short_name")
|
|
56
|
+
def exec_pending_tasks(company_short_name: str):
|
|
57
|
+
from services.tasks_service import TaskService
|
|
58
|
+
task_service = IAToolkit.get_instance().get_injector().get(TaskService)
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
result = task_service.trigger_pending_tasks(company_short_name)
|
|
62
|
+
click.echo(result['message'])
|
|
63
|
+
except Exception as e:
|
|
64
|
+
logging.exception(e)
|
|
65
|
+
click.echo(f"Error: {str(e)}")
|
|
66
|
+
|
|
67
|
+
@app.cli.command("load")
|
|
68
|
+
def load_documents():
|
|
69
|
+
from services.load_documents_service import LoadDocumentsService
|
|
70
|
+
|
|
71
|
+
load_documents_service = IAToolkit.get_instance().get_injector().get(LoadDocumentsService)
|
|
72
|
+
try:
|
|
73
|
+
result = load_documents_service.load()
|
|
74
|
+
click.echo(result['message'])
|
|
75
|
+
except Exception as e:
|
|
76
|
+
logging.exception(e)
|
|
77
|
+
click.echo(f"Error: {str(e)}")
|
iatoolkit/iatoolkit.py
CHANGED
|
@@ -15,7 +15,6 @@ from urllib.parse import urlparse
|
|
|
15
15
|
import redis
|
|
16
16
|
import logging
|
|
17
17
|
import os
|
|
18
|
-
import click
|
|
19
18
|
from typing import Optional, Dict, Any
|
|
20
19
|
from repositories.database_manager import DatabaseManager
|
|
21
20
|
from injector import Binder, singleton, Injector
|
|
@@ -319,75 +318,29 @@ class IAToolkit:
|
|
|
319
318
|
Bcrypt(self.app)
|
|
320
319
|
|
|
321
320
|
def _setup_cli_commands(self):
|
|
322
|
-
|
|
321
|
+
from iatoolkit.cli_commands import register_core_commands
|
|
323
322
|
from services.dispatcher_service import Dispatcher
|
|
324
|
-
from
|
|
323
|
+
from iatoolkit.company_registry import get_company_registry
|
|
324
|
+
|
|
325
|
+
# 1. Register core commands
|
|
326
|
+
register_core_commands(self.app)
|
|
327
|
+
logging.info("✅ Comandos CLI del núcleo registrados.")
|
|
328
|
+
|
|
329
|
+
# 2. Register company-specific commands
|
|
330
|
+
try:
|
|
331
|
+
# Get the dispatcher, which holds the company instances
|
|
332
|
+
dispatcher = self.get_injector().get(Dispatcher)
|
|
333
|
+
registry = get_company_registry()
|
|
334
|
+
|
|
335
|
+
# Iterate through the registered company names
|
|
336
|
+
for company_name in registry.get_registered_companies():
|
|
337
|
+
company_instance = dispatcher.get_company_instance(company_name)
|
|
338
|
+
if company_instance:
|
|
339
|
+
company_instance.register_cli_commands(self.app)
|
|
340
|
+
logging.info(f"✅ Comandos CLI para la compañía '{company_name}' registrados.")
|
|
325
341
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
"""🗄️ Inicializa la base de datos del sistema"""
|
|
329
|
-
try:
|
|
330
|
-
dispatcher = self.get_injector().get(Dispatcher)
|
|
331
|
-
|
|
332
|
-
click.echo("🚀 Inicializando base de datos...")
|
|
333
|
-
dispatcher.setup_all_companies()
|
|
334
|
-
click.echo("✅ Base de datos inicializada correctamente")
|
|
335
|
-
|
|
336
|
-
except Exception as e:
|
|
337
|
-
logging.exception(e)
|
|
338
|
-
click.echo(f"❌ Error: {e}")
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
@self.app.cli.command("setup-company")
|
|
342
|
-
@click.argument("company_short_name")
|
|
343
|
-
def setup_company(company_short_name: str):
|
|
344
|
-
"""⚙️ Ejecuta el proceso de configuración para una nueva empresa."""
|
|
345
|
-
try:
|
|
346
|
-
# step 1: init the database
|
|
347
|
-
dispatcher = self.get_injector().get(Dispatcher)
|
|
348
|
-
click.echo("🚀 step 1 of 2: init companies in the database...")
|
|
349
|
-
dispatcher.setup_all_companies()
|
|
350
|
-
click.echo("✅ database is ready.")
|
|
351
|
-
|
|
352
|
-
# step 2: generate the api key
|
|
353
|
-
profile_service = self.get_injector().get(ProfileService)
|
|
354
|
-
click.echo(f"🔑 step 2 of 2: generating api-key for use in '{company_short_name}'...")
|
|
355
|
-
result = profile_service.new_api_key(company_short_name)
|
|
356
|
-
|
|
357
|
-
if 'error' in result:
|
|
358
|
-
click.echo(f"❌ Error in step 2: {result['error']}")
|
|
359
|
-
click.echo("👉 Make sure company name is correct and it's initialized in your app.")
|
|
360
|
-
else:
|
|
361
|
-
click.echo("Configuration es ready, add this variable to your environment")
|
|
362
|
-
click.echo(f"IATOOLKIT_API_KEY={result['api-key']}")
|
|
363
|
-
|
|
364
|
-
except Exception as e:
|
|
365
|
-
logging.exception(e)
|
|
366
|
-
click.echo(f"❌ Ocurrió un error inesperado durante la configuración: {e}")
|
|
367
|
-
|
|
368
|
-
@self.app.cli.command("populate-sample-db")
|
|
369
|
-
def populate_sample_db():
|
|
370
|
-
from companies.sample_company.sample_company import SampleCompany
|
|
371
|
-
"""📦 Crea y puebla la base de datos de sample_company con datos de prueba."""
|
|
372
|
-
try:
|
|
373
|
-
company_instance = self.get_injector().get(SampleCompany)
|
|
374
|
-
click.echo("🚀 Obteniendo instancia de 'sample_company'...")
|
|
375
|
-
|
|
376
|
-
if not company_instance or not hasattr(company_instance, 'sample_database') or not company_instance.sample_database:
|
|
377
|
-
click.echo("❌ Error: No se pudo obtener la instancia de 'sample_company' o su base de datos no está configurada.")
|
|
378
|
-
click.echo("👉 Asegúrate de que 'sample_company' esté registrada y que la variable de entorno 'SAMPLE_DATABASE_URI' esté definida.")
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
click.echo("⚙️ Creando y poblando la base de datos. Esto puede tardar unos momentos...")
|
|
382
|
-
|
|
383
|
-
company_instance.sample_database.create_database()
|
|
384
|
-
company_instance.sample_database.populate_database()
|
|
385
|
-
|
|
386
|
-
click.echo("✅ Base de datos de 'sample_company' poblada exitosamente.")
|
|
387
|
-
|
|
388
|
-
except Exception as e:
|
|
389
|
-
logging.exception(e)
|
|
390
|
-
click.echo(f"❌ Ocurrió un error inesperado: {e}")
|
|
342
|
+
except Exception as e:
|
|
343
|
+
logging.error(f"❌ Error durante el registro de comandos de compañías: {e}")
|
|
391
344
|
|
|
392
345
|
def _setup_context_processors(self):
|
|
393
346
|
# Configura context processors para templates
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
iatoolkit/__init__.py,sha256=
|
|
2
|
-
iatoolkit/base_company.py,sha256=
|
|
1
|
+
iatoolkit/__init__.py,sha256=dKjc0IsztMClwbalF5hbtz418TRtu0xE2pdb8J3iQQw,1512
|
|
2
|
+
iatoolkit/base_company.py,sha256=FlB-HFYH8FoTl4nbtsYgfKjkdZtizJbKwXqaosxmRqc,2009
|
|
3
|
+
iatoolkit/cli_commands.py,sha256=oWd5kwDYd0W1Lcpuk3N2cEnusPAVefaCrYveMQ1zDvY,3223
|
|
3
4
|
iatoolkit/company_registry.py,sha256=cRaez-VBo1icnUNKmkQqo_Xlr8UKWFoYEMZ70XP6Jgk,2702
|
|
4
|
-
iatoolkit/iatoolkit.py,sha256=
|
|
5
|
+
iatoolkit/iatoolkit.py,sha256=OwlGujwtNLBYtfZuCpcX_yzrgB8BVo9Jfh72owM8FFc,15651
|
|
5
6
|
iatoolkit/system_prompts/arquitectura.prompt,sha256=2W-7NWy6P6y1Gh5_-zD1iK-BWq1Siu8TuvGCouP67bQ,1267
|
|
6
7
|
iatoolkit/system_prompts/format_styles.prompt,sha256=MSMe1qvR3cF_0IbFshn8R0z6Wx6VCHQq1p37rpu5wwk,3576
|
|
7
8
|
iatoolkit/system_prompts/query_main.prompt,sha256=Eu5VOQzUygJ45Ct1WKYGbi0JMltgI6FQIZWlGmN1bdk,3214
|
|
@@ -9,7 +10,7 @@ iatoolkit/system_prompts/sql_rules.prompt,sha256=y4nURVnb9AyFwt-lrbMNBHHtZlhk6kC
|
|
|
9
10
|
services/__init__.py,sha256=fSvSfIcPW1dHwTBY1hQ5dBEhaoorzk_GzR4G46gD8tY,173
|
|
10
11
|
services/api_service.py,sha256=InIKTc64BWcp4U4tYKHz28x4ErPxIfvR9x3ZlxJZlXs,2911
|
|
11
12
|
services/benchmark_service.py,sha256=g9JVrmAqIe_iI0D1DwdQ6DJ2_FJRCTndarESNSVfhbw,5907
|
|
12
|
-
services/dispatcher_service.py,sha256=
|
|
13
|
+
services/dispatcher_service.py,sha256=vZbz-XCP0Aa-oE4nh5ZKeUKWlJ78VPSRYkpzMHlVFM0,14952
|
|
13
14
|
services/document_service.py,sha256=sm5QtbrKs2dF9hpLuSLMB-IMWYNBD7yWHv3rd80aD0o,5960
|
|
14
15
|
services/excel_service.py,sha256=wE9Udbyb96kGRSnZZ6KM2mbE484rKjTEhta9GKKpy-8,3630
|
|
15
16
|
services/file_processor_service.py,sha256=82UArWtwpr94CAMkkoRP0_nPtoqItymdKSIABS0Xkxw,2943
|
|
@@ -25,7 +26,7 @@ services/sql_service.py,sha256=H7CIPpXTcxLXLojD2fBFr_mIAD0PW1vEJhKHLfJi4Hk,1418
|
|
|
25
26
|
services/tasks_service.py,sha256=hHJDlcsSOPtEleD6_Vv3pocfxWNmthIhmZSdnoWFpEM,6861
|
|
26
27
|
services/user_feedback_service.py,sha256=YtCndRBekDEWYEbac431Ksn2gMO5iBrI3WqKK0xtShE,2513
|
|
27
28
|
services/user_session_context_service.py,sha256=5qn7fqpuiU8KgMpU4M5-iRUsETumz1raBw-EeZLuE1A,3868
|
|
28
|
-
iatoolkit-0.3.
|
|
29
|
-
iatoolkit-0.3.
|
|
30
|
-
iatoolkit-0.3.
|
|
31
|
-
iatoolkit-0.3.
|
|
29
|
+
iatoolkit-0.3.9.dist-info/METADATA,sha256=wLPKZh6G6AXabwamba8ywnayHiCCwHYiNWVfqH7JK9I,8801
|
|
30
|
+
iatoolkit-0.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
31
|
+
iatoolkit-0.3.9.dist-info/top_level.txt,sha256=dqlBbmgo9okD9d_WMR9uYzdup7Rxgj26yFF85jRGeu4,19
|
|
32
|
+
iatoolkit-0.3.9.dist-info/RECORD,,
|
services/dispatcher_service.py
CHANGED
|
@@ -238,6 +238,10 @@ class Dispatcher:
|
|
|
238
238
|
raise IAToolkitException(IAToolkitException.ErrorType.EXTERNAL_SOURCE_ERROR,
|
|
239
239
|
f"Error en get_metadata_from_filename de {company_name}: {str(e)}") from e
|
|
240
240
|
|
|
241
|
+
def get_company_instance(self, company_name: str):
|
|
242
|
+
"""Returns the instance for a given company name."""
|
|
243
|
+
return self.company_classes.get(company_name)
|
|
244
|
+
|
|
241
245
|
def get_registered_companies(self) -> dict:
|
|
242
246
|
"""Obtiene todas las empresas registradas (para debugging/admin)"""
|
|
243
247
|
return {
|
|
File without changes
|
|
File without changes
|