iatoolkit 0.3.9__py3-none-any.whl → 0.4.0__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 -2
- iatoolkit/company_registry.py +4 -0
- {iatoolkit-0.3.9.dist-info → iatoolkit-0.4.0.dist-info}/METADATA +1 -1
- {iatoolkit-0.3.9.dist-info → iatoolkit-0.4.0.dist-info}/RECORD +8 -8
- services/dispatcher_service.py +37 -22
- services/prompt_manager_service.py +2 -1
- {iatoolkit-0.3.9.dist-info → iatoolkit-0.4.0.dist-info}/WHEEL +0 -0
- {iatoolkit-0.3.9.dist-info → iatoolkit-0.4.0.dist-info}/top_level.txt +0 -0
iatoolkit/__init__.py
CHANGED
|
@@ -21,9 +21,9 @@ 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
|
|
25
24
|
from repositories.profile_repo import ProfileRepo
|
|
26
25
|
from repositories.llm_query_repo import LLMQueryRepo
|
|
26
|
+
from services.query_service import QueryService
|
|
27
27
|
from repositories.database_manager import DatabaseManager
|
|
28
28
|
from infra.call_service import CallServiceClient
|
|
29
29
|
from common.util import Utility
|
|
@@ -40,8 +40,8 @@ __all__ = [
|
|
|
40
40
|
'ExcelService',
|
|
41
41
|
'Dispatcher',
|
|
42
42
|
'DocumentService',
|
|
43
|
-
'QueryService',
|
|
44
43
|
'SearchService',
|
|
44
|
+
'QueryService',
|
|
45
45
|
'ProfileRepo',
|
|
46
46
|
'LLMQueryRepo',
|
|
47
47
|
'DatabaseManager',
|
iatoolkit/company_registry.py
CHANGED
|
@@ -46,6 +46,10 @@ class CompanyRegistry:
|
|
|
46
46
|
|
|
47
47
|
return self._company_instances.copy()
|
|
48
48
|
|
|
49
|
+
def get_all_company_instances(self) -> Dict[str, BaseCompany]:
|
|
50
|
+
"""Devuelve un diccionario con todas las instancias de empresas creadas."""
|
|
51
|
+
return self._company_instances.copy()
|
|
52
|
+
|
|
49
53
|
def get_registered_companies(self) -> Dict[str, Type[BaseCompany]]:
|
|
50
54
|
return self._company_classes.copy()
|
|
51
55
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
iatoolkit/__init__.py,sha256=
|
|
1
|
+
iatoolkit/__init__.py,sha256=WImnnjDcaWy8_CoIS4UA2PwqYcMb0dDNUhg-OlkZ2X8,1512
|
|
2
2
|
iatoolkit/base_company.py,sha256=FlB-HFYH8FoTl4nbtsYgfKjkdZtizJbKwXqaosxmRqc,2009
|
|
3
3
|
iatoolkit/cli_commands.py,sha256=oWd5kwDYd0W1Lcpuk3N2cEnusPAVefaCrYveMQ1zDvY,3223
|
|
4
|
-
iatoolkit/company_registry.py,sha256=
|
|
4
|
+
iatoolkit/company_registry.py,sha256=HnDpVyCc41OAn-exVF53b_HMES7GelWZcvxR39S_nI4,2900
|
|
5
5
|
iatoolkit/iatoolkit.py,sha256=OwlGujwtNLBYtfZuCpcX_yzrgB8BVo9Jfh72owM8FFc,15651
|
|
6
6
|
iatoolkit/system_prompts/arquitectura.prompt,sha256=2W-7NWy6P6y1Gh5_-zD1iK-BWq1Siu8TuvGCouP67bQ,1267
|
|
7
7
|
iatoolkit/system_prompts/format_styles.prompt,sha256=MSMe1qvR3cF_0IbFshn8R0z6Wx6VCHQq1p37rpu5wwk,3576
|
|
@@ -10,7 +10,7 @@ iatoolkit/system_prompts/sql_rules.prompt,sha256=y4nURVnb9AyFwt-lrbMNBHHtZlhk6kC
|
|
|
10
10
|
services/__init__.py,sha256=fSvSfIcPW1dHwTBY1hQ5dBEhaoorzk_GzR4G46gD8tY,173
|
|
11
11
|
services/api_service.py,sha256=InIKTc64BWcp4U4tYKHz28x4ErPxIfvR9x3ZlxJZlXs,2911
|
|
12
12
|
services/benchmark_service.py,sha256=g9JVrmAqIe_iI0D1DwdQ6DJ2_FJRCTndarESNSVfhbw,5907
|
|
13
|
-
services/dispatcher_service.py,sha256=
|
|
13
|
+
services/dispatcher_service.py,sha256=jGixvvQ4DTQGZye8aa05q56B6U-s6NaDb6he6UTXmQc,15534
|
|
14
14
|
services/document_service.py,sha256=sm5QtbrKs2dF9hpLuSLMB-IMWYNBD7yWHv3rd80aD0o,5960
|
|
15
15
|
services/excel_service.py,sha256=wE9Udbyb96kGRSnZZ6KM2mbE484rKjTEhta9GKKpy-8,3630
|
|
16
16
|
services/file_processor_service.py,sha256=82UArWtwpr94CAMkkoRP0_nPtoqItymdKSIABS0Xkxw,2943
|
|
@@ -19,14 +19,14 @@ services/jwt_service.py,sha256=dC45Sn6FyzdzRiQJnzgkjN3Hy21V1imRxB0hTyWRvlA,3979
|
|
|
19
19
|
services/load_documents_service.py,sha256=_-OTUih8Zk0m4dHqAhkE7kAwU2mbz_QoMrOKnrq7ZWs,8821
|
|
20
20
|
services/mail_service.py,sha256=ystFit1LuYUC4ekYYebyiy1rqYQmxeL6K8h58MxEkOY,2233
|
|
21
21
|
services/profile_service.py,sha256=vZV0cregZQiPKYcNLaD7xjez2y6-3Mq97cDndC8NL8w,17922
|
|
22
|
-
services/prompt_manager_service.py,sha256=
|
|
22
|
+
services/prompt_manager_service.py,sha256=bWG4SIgt0u45PVUfm0xRLbLfKC7bk6uozVHRdkdgCmc,7761
|
|
23
23
|
services/query_service.py,sha256=zpaDzjzh2HqAG1F2Ap8WHBpfAMVtzZ_6v1JGVEguwvs,15687
|
|
24
24
|
services/search_service.py,sha256=oJD6WRXCJBD7WUVHWWKxexRkhR8nQSrFtcPV3pFO2KQ,1153
|
|
25
25
|
services/sql_service.py,sha256=H7CIPpXTcxLXLojD2fBFr_mIAD0PW1vEJhKHLfJi4Hk,1418
|
|
26
26
|
services/tasks_service.py,sha256=hHJDlcsSOPtEleD6_Vv3pocfxWNmthIhmZSdnoWFpEM,6861
|
|
27
27
|
services/user_feedback_service.py,sha256=YtCndRBekDEWYEbac431Ksn2gMO5iBrI3WqKK0xtShE,2513
|
|
28
28
|
services/user_session_context_service.py,sha256=5qn7fqpuiU8KgMpU4M5-iRUsETumz1raBw-EeZLuE1A,3868
|
|
29
|
-
iatoolkit-0.
|
|
30
|
-
iatoolkit-0.
|
|
31
|
-
iatoolkit-0.
|
|
32
|
-
iatoolkit-0.
|
|
29
|
+
iatoolkit-0.4.0.dist-info/METADATA,sha256=1muE8emXWndqmPwC3xhtpVYjrFiktvWdWdD_UckbW10,8801
|
|
30
|
+
iatoolkit-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
31
|
+
iatoolkit-0.4.0.dist-info/top_level.txt,sha256=dqlBbmgo9okD9d_WMR9uYzdup7Rxgj26yFF85jRGeu4,19
|
|
32
|
+
iatoolkit-0.4.0.dist-info/RECORD,,
|
services/dispatcher_service.py
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
# Todos los derechos reservados.
|
|
4
4
|
# En trámite de registro en el Registro de Propiedad Intelectual de Chile.
|
|
5
5
|
|
|
6
|
-
from iatoolkit import current_iatoolkit
|
|
7
6
|
from common.exceptions import IAToolkitException
|
|
8
7
|
from services.prompt_manager_service import PromptService
|
|
9
8
|
from services.api_service import ApiService
|
|
@@ -11,10 +10,10 @@ from repositories.llm_query_repo import LLMQueryRepo
|
|
|
11
10
|
from repositories.models import Company, Function
|
|
12
11
|
from services.excel_service import ExcelService
|
|
13
12
|
from services.mail_service import MailService
|
|
14
|
-
from iatoolkit.company_registry import get_company_registry
|
|
15
13
|
from common.session_manager import SessionManager
|
|
16
14
|
from common.util import Utility
|
|
17
15
|
from injector import inject
|
|
16
|
+
from typing import Dict
|
|
18
17
|
import logging
|
|
19
18
|
import os
|
|
20
19
|
|
|
@@ -37,11 +36,10 @@ class Dispatcher:
|
|
|
37
36
|
self.system_functions = _FUNCTION_LIST
|
|
38
37
|
self.system_prompts = _SYSTEM_PROMPT
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
self.
|
|
39
|
+
self._company_registry = None
|
|
40
|
+
self._company_instances = None
|
|
42
41
|
|
|
43
42
|
# load into the dispatcher the configured companies
|
|
44
|
-
self.company_classes = {}
|
|
45
43
|
self.initialize_companies()
|
|
46
44
|
|
|
47
45
|
# run the statrtup logic for all companies
|
|
@@ -53,23 +51,40 @@ class Dispatcher:
|
|
|
53
51
|
"iat_api_call": self.api_service.call_api
|
|
54
52
|
}
|
|
55
53
|
|
|
54
|
+
@property
|
|
55
|
+
def company_registry(self):
|
|
56
|
+
"""Lazy-loads and returns the CompanyRegistry instance."""
|
|
57
|
+
if self._company_registry is None:
|
|
58
|
+
from iatoolkit.company_registry import get_company_registry
|
|
59
|
+
self._company_registry = get_company_registry()
|
|
60
|
+
return self._company_registry
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def company_instances(self):
|
|
64
|
+
"""Lazy-loads and returns the instantiated company classes."""
|
|
65
|
+
if self._company_instances is None:
|
|
66
|
+
self._company_instances = self.company_registry.get_all_company_instances()
|
|
67
|
+
return self._company_instances
|
|
68
|
+
|
|
56
69
|
def initialize_companies(self):
|
|
70
|
+
from iatoolkit import current_iatoolkit
|
|
57
71
|
"""
|
|
58
72
|
Initializes and instantiates all registered company classes.
|
|
59
73
|
This method should be called *after* the main injector is fully configured
|
|
60
74
|
and the company registry is populated.
|
|
61
75
|
"""
|
|
62
|
-
if self.
|
|
76
|
+
if self.company_registry.get_all_company_instances(): # Check if already instantiated
|
|
63
77
|
return
|
|
64
78
|
|
|
65
79
|
# ✅ NOW it is safe to get the injector and instantiate companies.
|
|
66
80
|
injector = current_iatoolkit().get_injector()
|
|
67
81
|
self.company_registry.set_injector(injector)
|
|
68
|
-
self.
|
|
82
|
+
self.company_registry.instantiate_companies()
|
|
83
|
+
|
|
69
84
|
|
|
70
85
|
def start_execution(self):
|
|
71
86
|
"""Runs the startup logic for all registered companies."""
|
|
72
|
-
for company_name, company_instance in self.
|
|
87
|
+
for company_name, company_instance in self.company_instances.items():
|
|
73
88
|
logging.info(f'Starting execution for company: {company_name}')
|
|
74
89
|
company_instance.start_execution()
|
|
75
90
|
|
|
@@ -100,14 +115,14 @@ class Dispatcher:
|
|
|
100
115
|
i += 1
|
|
101
116
|
|
|
102
117
|
# register in the database every company class
|
|
103
|
-
for company in self.
|
|
118
|
+
for company in self.company_instances.values():
|
|
104
119
|
company.register_company()
|
|
105
120
|
|
|
106
121
|
def dispatch(self, company_name: str, action: str, **kwargs) -> str:
|
|
107
122
|
company_key = company_name.lower()
|
|
108
123
|
|
|
109
|
-
if company_key not in self.
|
|
110
|
-
available_companies = list(self.
|
|
124
|
+
if company_key not in self.company_instances:
|
|
125
|
+
available_companies = list(self.company_instances.keys())
|
|
111
126
|
raise IAToolkitException(
|
|
112
127
|
IAToolkitException.ErrorType.EXTERNAL_SOURCE_ERROR,
|
|
113
128
|
f"Empresa '{company_name}' no configurada. Empresas disponibles: {available_companies}"
|
|
@@ -117,7 +132,7 @@ class Dispatcher:
|
|
|
117
132
|
if action in self.tool_handlers:
|
|
118
133
|
return self.tool_handlers[action](**kwargs)
|
|
119
134
|
|
|
120
|
-
company_instance = self.
|
|
135
|
+
company_instance = self.company_instances[company_name]
|
|
121
136
|
try:
|
|
122
137
|
return company_instance.handle_request(action, **kwargs)
|
|
123
138
|
except IAToolkitException as e:
|
|
@@ -130,7 +145,7 @@ class Dispatcher:
|
|
|
130
145
|
f"Error en function call '{action}': {str(e)}") from e
|
|
131
146
|
|
|
132
147
|
def get_company_context(self, company_name: str, **kwargs) -> str:
|
|
133
|
-
if company_name not in self.
|
|
148
|
+
if company_name not in self.company_instances:
|
|
134
149
|
raise IAToolkitException(IAToolkitException.ErrorType.EXTERNAL_SOURCE_ERROR,
|
|
135
150
|
f"Empresa no configurada: {company_name}")
|
|
136
151
|
|
|
@@ -152,7 +167,7 @@ class Dispatcher:
|
|
|
152
167
|
filepath = os.path.join(schema_dir, file)
|
|
153
168
|
company_context += self.util.generate_context_for_schema(schema_name, filepath)
|
|
154
169
|
|
|
155
|
-
company_instance = self.
|
|
170
|
+
company_instance = self.company_instances[company_name]
|
|
156
171
|
try:
|
|
157
172
|
return company_context + company_instance.get_company_context(**kwargs)
|
|
158
173
|
except Exception as e:
|
|
@@ -180,7 +195,7 @@ class Dispatcher:
|
|
|
180
195
|
return tools
|
|
181
196
|
|
|
182
197
|
def get_user_info(self, company_name: str, user_identifier: str, is_local_user: bool) -> dict:
|
|
183
|
-
if company_name not in self.
|
|
198
|
+
if company_name not in self.company_instances:
|
|
184
199
|
raise IAToolkitException(IAToolkitException.ErrorType.EXTERNAL_SOURCE_ERROR,
|
|
185
200
|
f"Empresa no configurada: {company_name}")
|
|
186
201
|
|
|
@@ -190,7 +205,7 @@ class Dispatcher:
|
|
|
190
205
|
raw_user_data = SessionManager.get('user', {})
|
|
191
206
|
else:
|
|
192
207
|
# source 2: external company user
|
|
193
|
-
company_instance = self.
|
|
208
|
+
company_instance = self.company_instances[company_name]
|
|
194
209
|
try:
|
|
195
210
|
raw_user_data = company_instance.get_user_info(user_identifier)
|
|
196
211
|
except Exception as e:
|
|
@@ -226,11 +241,11 @@ class Dispatcher:
|
|
|
226
241
|
return normalized_user
|
|
227
242
|
|
|
228
243
|
def get_metadata_from_filename(self, company_name: str, filename: str) -> dict:
|
|
229
|
-
if company_name not in self.
|
|
244
|
+
if company_name not in self.company_instances:
|
|
230
245
|
raise IAToolkitException(IAToolkitException.ErrorType.EXTERNAL_SOURCE_ERROR,
|
|
231
246
|
f"Empresa no configurada: {company_name}")
|
|
232
247
|
|
|
233
|
-
company_instance = self.
|
|
248
|
+
company_instance = self.company_instances[company_name]
|
|
234
249
|
try:
|
|
235
250
|
return company_instance.get_metadata_from_filename(filename)
|
|
236
251
|
except Exception as e:
|
|
@@ -240,14 +255,14 @@ class Dispatcher:
|
|
|
240
255
|
|
|
241
256
|
def get_company_instance(self, company_name: str):
|
|
242
257
|
"""Returns the instance for a given company name."""
|
|
243
|
-
return self.
|
|
258
|
+
return self.company_instances.get(company_name)
|
|
244
259
|
|
|
245
260
|
def get_registered_companies(self) -> dict:
|
|
246
|
-
"""
|
|
261
|
+
"""Gets all registered companies (for debugging/admin purposes)"""
|
|
247
262
|
return {
|
|
248
263
|
"registered_classes": list(self.company_registry.get_registered_companies().keys()),
|
|
249
|
-
"instantiated": list(self.
|
|
250
|
-
"count": len(self.
|
|
264
|
+
"instantiated": list(self.company_instances.keys()),
|
|
265
|
+
"count": len(self.company_instances)
|
|
251
266
|
}
|
|
252
267
|
|
|
253
268
|
|
|
@@ -74,7 +74,8 @@ class PromptService:
|
|
|
74
74
|
raise IAToolkitException(IAToolkitException.ErrorType.DOCUMENT_NOT_FOUND,
|
|
75
75
|
f"No se encontró el prompt '{prompt_name}' para la empresa '{company.short_name}'")
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
prompt_file = f'companies/{company.short_name}/prompts/{user_prompt.filename}'
|
|
78
|
+
absolute_filepath = os.path.join(execution_dir, prompt_file)
|
|
78
79
|
if not os.path.exists(absolute_filepath):
|
|
79
80
|
raise IAToolkitException(IAToolkitException.ErrorType.FILE_IO_ERROR,
|
|
80
81
|
f"El archivo para el prompt '{prompt_name}' no existe: {absolute_filepath}")
|
|
File without changes
|
|
File without changes
|