iatoolkit 0.59.1__py3-none-any.whl → 0.67.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 -0
- iatoolkit/base_company.py +2 -19
- iatoolkit/common/routes.py +28 -25
- iatoolkit/common/session_manager.py +2 -0
- iatoolkit/common/util.py +17 -6
- iatoolkit/company_registry.py +1 -2
- iatoolkit/iatoolkit.py +54 -20
- iatoolkit/locales/en.yaml +167 -0
- iatoolkit/locales/es.yaml +163 -0
- iatoolkit/repositories/database_manager.py +3 -3
- iatoolkit/repositories/document_repo.py +1 -1
- iatoolkit/repositories/models.py +3 -4
- iatoolkit/repositories/profile_repo.py +0 -4
- iatoolkit/services/auth_service.py +44 -32
- iatoolkit/services/branding_service.py +35 -27
- iatoolkit/services/configuration_service.py +140 -0
- iatoolkit/services/dispatcher_service.py +20 -18
- iatoolkit/services/document_service.py +5 -2
- iatoolkit/services/excel_service.py +15 -11
- iatoolkit/services/file_processor_service.py +4 -12
- iatoolkit/services/history_service.py +8 -7
- iatoolkit/services/i18n_service.py +104 -0
- iatoolkit/services/jwt_service.py +7 -9
- iatoolkit/services/language_service.py +79 -0
- iatoolkit/services/load_documents_service.py +4 -4
- iatoolkit/services/mail_service.py +9 -4
- iatoolkit/services/onboarding_service.py +10 -4
- iatoolkit/services/profile_service.py +59 -38
- iatoolkit/services/prompt_manager_service.py +20 -16
- iatoolkit/services/query_service.py +15 -14
- iatoolkit/services/sql_service.py +6 -2
- iatoolkit/services/user_feedback_service.py +70 -29
- iatoolkit/static/js/chat_feedback_button.js +80 -0
- iatoolkit/static/js/chat_help_content.js +124 -0
- iatoolkit/static/js/chat_history_button.js +110 -0
- iatoolkit/static/js/chat_logout_button.js +36 -0
- iatoolkit/static/js/chat_main.js +32 -184
- iatoolkit/static/js/{chat_onboarding.js → chat_onboarding_button.js} +0 -1
- iatoolkit/static/js/chat_prompt_manager.js +94 -0
- iatoolkit/static/js/chat_reload_button.js +35 -0
- iatoolkit/static/styles/chat_iatoolkit.css +251 -205
- iatoolkit/static/styles/chat_modal.css +63 -95
- iatoolkit/static/styles/chat_public.css +107 -0
- iatoolkit/static/styles/landing_page.css +121 -167
- iatoolkit/templates/_company_header.html +20 -0
- iatoolkit/templates/_login_widget.html +10 -10
- iatoolkit/templates/base.html +36 -19
- iatoolkit/templates/change_password.html +24 -22
- iatoolkit/templates/chat.html +121 -93
- iatoolkit/templates/chat_modals.html +113 -74
- iatoolkit/templates/error.html +44 -8
- iatoolkit/templates/forgot_password.html +17 -15
- iatoolkit/templates/index.html +66 -81
- iatoolkit/templates/login_simulation.html +16 -5
- iatoolkit/templates/onboarding_shell.html +1 -2
- iatoolkit/templates/signup.html +22 -20
- iatoolkit/views/base_login_view.py +12 -1
- iatoolkit/views/change_password_view.py +50 -33
- iatoolkit/views/external_login_view.py +5 -11
- iatoolkit/views/file_store_api_view.py +7 -9
- iatoolkit/views/forgot_password_view.py +21 -19
- iatoolkit/views/help_content_api_view.py +54 -0
- iatoolkit/views/history_api_view.py +16 -12
- iatoolkit/views/home_view.py +61 -0
- iatoolkit/views/index_view.py +5 -34
- iatoolkit/views/init_context_api_view.py +16 -13
- iatoolkit/views/llmquery_api_view.py +38 -28
- iatoolkit/views/login_simulation_view.py +14 -2
- iatoolkit/views/login_view.py +48 -33
- iatoolkit/views/logout_api_view.py +49 -0
- iatoolkit/views/profile_api_view.py +46 -0
- iatoolkit/views/prompt_api_view.py +8 -8
- iatoolkit/views/signup_view.py +27 -25
- iatoolkit/views/{tasks_view.py → tasks_api_view.py} +10 -36
- iatoolkit/views/tasks_review_api_view.py +55 -0
- iatoolkit/views/user_feedback_api_view.py +21 -32
- iatoolkit/views/verify_user_view.py +33 -26
- {iatoolkit-0.59.1.dist-info → iatoolkit-0.67.0.dist-info}/METADATA +40 -22
- iatoolkit-0.67.0.dist-info/RECORD +120 -0
- iatoolkit-0.67.0.dist-info/licenses/LICENSE +21 -0
- iatoolkit/static/js/chat_context_reload.js +0 -54
- iatoolkit/static/js/chat_feedback.js +0 -115
- iatoolkit/static/js/chat_history.js +0 -127
- iatoolkit/static/styles/chat_info.css +0 -53
- iatoolkit/templates/_branding_styles.html +0 -53
- iatoolkit/templates/_navbar.html +0 -9
- iatoolkit/templates/header.html +0 -31
- iatoolkit/templates/test.html +0 -9
- iatoolkit/views/chat_token_request_view.py +0 -98
- iatoolkit/views/tasks_review_view.py +0 -83
- iatoolkit-0.59.1.dist-info/RECORD +0 -111
- {iatoolkit-0.59.1.dist-info → iatoolkit-0.67.0.dist-info}/WHEEL +0 -0
- {iatoolkit-0.59.1.dist-info → iatoolkit-0.67.0.dist-info}/top_level.txt +0 -0
iatoolkit/__init__.py
CHANGED
|
@@ -13,6 +13,7 @@ from .base_company import BaseCompany
|
|
|
13
13
|
from iatoolkit.repositories.database_manager import DatabaseManager
|
|
14
14
|
|
|
15
15
|
# --- Services ---
|
|
16
|
+
from iatoolkit.services.configuration_service import ConfigurationService
|
|
16
17
|
from iatoolkit.services.query_service import QueryService
|
|
17
18
|
from iatoolkit.services.sql_service import SqlService
|
|
18
19
|
from iatoolkit.services.document_service import DocumentService
|
|
@@ -29,6 +30,7 @@ __all__ = [
|
|
|
29
30
|
'BaseCompany',
|
|
30
31
|
'DatabaseManager',
|
|
31
32
|
'QueryService',
|
|
33
|
+
'ConfigurationService',
|
|
32
34
|
'SqlService',
|
|
33
35
|
'ExcelService',
|
|
34
36
|
'DocumentService',
|
iatoolkit/base_company.py
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
from abc import ABC, abstractmethod
|
|
8
8
|
from iatoolkit.repositories.profile_repo import ProfileRepo
|
|
9
9
|
from iatoolkit.repositories.llm_query_repo import LLMQueryRepo
|
|
10
|
-
|
|
11
10
|
from iatoolkit.services.prompt_manager_service import PromptService
|
|
12
11
|
from iatoolkit.repositories.models import Company, Function, PromptCategory
|
|
13
12
|
from iatoolkit import IAToolkit
|
|
@@ -22,20 +21,14 @@ class BaseCompany(ABC):
|
|
|
22
21
|
self.prompt_service: PromptService = injector.get(PromptService)
|
|
23
22
|
self.company: Company | None = None
|
|
24
23
|
|
|
25
|
-
def _load_company_by_short_name(self, short_name: str) -> Company:
|
|
26
|
-
self.company = self.profile_repo.get_company_by_short_name(short_name)
|
|
27
|
-
return self.company
|
|
28
|
-
|
|
29
24
|
def _create_company(self,
|
|
30
25
|
short_name: str,
|
|
31
26
|
name: str,
|
|
32
|
-
|
|
33
|
-
onboarding_cards: dict | None = None
|
|
27
|
+
parameters: dict | None = None,
|
|
34
28
|
) -> Company:
|
|
35
29
|
company_obj = Company(short_name=short_name,
|
|
36
30
|
name=name,
|
|
37
|
-
|
|
38
|
-
onboarding_cards=onboarding_cards)
|
|
31
|
+
parameters=parameters)
|
|
39
32
|
self.company = self.profile_repo.create_company(company_obj)
|
|
40
33
|
return self.company
|
|
41
34
|
|
|
@@ -76,11 +69,6 @@ class BaseCompany(ABC):
|
|
|
76
69
|
)
|
|
77
70
|
|
|
78
71
|
|
|
79
|
-
@abstractmethod
|
|
80
|
-
# initialize all the database tables needed
|
|
81
|
-
def register_company(self):
|
|
82
|
-
raise NotImplementedError("La subclase debe implementar el método create_company()")
|
|
83
|
-
|
|
84
72
|
@abstractmethod
|
|
85
73
|
# get context specific for this company
|
|
86
74
|
def get_company_context(self, **kwargs) -> str:
|
|
@@ -96,11 +84,6 @@ class BaseCompany(ABC):
|
|
|
96
84
|
def handle_request(self, tag: str, params: dict) -> dict:
|
|
97
85
|
raise NotImplementedError("La subclase debe implementar el método handle_request()")
|
|
98
86
|
|
|
99
|
-
@abstractmethod
|
|
100
|
-
# get context specific for the query
|
|
101
|
-
def start_execution(self):
|
|
102
|
-
raise NotImplementedError("La subclase debe implementar el método start_execution()")
|
|
103
|
-
|
|
104
87
|
@abstractmethod
|
|
105
88
|
# get context specific for the query
|
|
106
89
|
def get_metadata_from_filename(self, filename: str) -> dict:
|
iatoolkit/common/routes.py
CHANGED
|
@@ -3,17 +3,8 @@
|
|
|
3
3
|
#
|
|
4
4
|
# IAToolkit is open source software.
|
|
5
5
|
|
|
6
|
-
from flask import render_template, redirect,
|
|
7
|
-
from iatoolkit.common.session_manager import SessionManager
|
|
6
|
+
from flask import render_template, redirect, url_for,send_from_directory, current_app, abort
|
|
8
7
|
from flask import jsonify
|
|
9
|
-
from iatoolkit.views.history_api_view import HistoryApiView
|
|
10
|
-
import os
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def logout(company_short_name: str):
|
|
14
|
-
SessionManager.clear()
|
|
15
|
-
flash("Has cerrado sesión correctamente", "info")
|
|
16
|
-
return redirect(url_for('index', company_short_name=company_short_name))
|
|
17
8
|
|
|
18
9
|
|
|
19
10
|
# this function register all the views
|
|
@@ -22,8 +13,8 @@ def register_views(injector, app):
|
|
|
22
13
|
from iatoolkit.views.index_view import IndexView
|
|
23
14
|
from iatoolkit.views.init_context_api_view import InitContextApiView
|
|
24
15
|
from iatoolkit.views.llmquery_api_view import LLMQueryApiView
|
|
25
|
-
from iatoolkit.views.
|
|
26
|
-
from iatoolkit.views.
|
|
16
|
+
from iatoolkit.views.tasks_api_view import TaskApiView
|
|
17
|
+
from iatoolkit.views.tasks_review_api_view import TaskReviewApiView
|
|
27
18
|
from iatoolkit.views.login_simulation_view import LoginSimulationView
|
|
28
19
|
from iatoolkit.views.signup_view import SignupView
|
|
29
20
|
from iatoolkit.views.verify_user_view import VerifyAccountView
|
|
@@ -32,12 +23,20 @@ def register_views(injector, app):
|
|
|
32
23
|
from iatoolkit.views.file_store_api_view import FileStoreApiView
|
|
33
24
|
from iatoolkit.views.user_feedback_api_view import UserFeedbackApiView
|
|
34
25
|
from iatoolkit.views.prompt_api_view import PromptApiView
|
|
35
|
-
from iatoolkit.views.
|
|
26
|
+
from iatoolkit.views.history_api_view import HistoryApiView
|
|
27
|
+
from iatoolkit.views.help_content_api_view import HelpContentApiView
|
|
28
|
+
from iatoolkit.views.profile_api_view import UserLanguageApiView # <-- Importa la nueva vista
|
|
29
|
+
|
|
36
30
|
from iatoolkit.views.login_view import LoginView, FinalizeContextView
|
|
37
31
|
from iatoolkit.views.external_login_view import ExternalLoginView, RedeemTokenApiView
|
|
32
|
+
from iatoolkit.views.logout_api_view import LogoutApiView
|
|
33
|
+
from iatoolkit.views.home_view import HomeView
|
|
38
34
|
|
|
39
35
|
# iatoolkit home page
|
|
40
|
-
app.add_url_rule('
|
|
36
|
+
app.add_url_rule('/', view_func=IndexView.as_view('index'))
|
|
37
|
+
|
|
38
|
+
# company home view
|
|
39
|
+
app.add_url_rule('/<company_short_name>/home', view_func=HomeView.as_view('home'))
|
|
41
40
|
|
|
42
41
|
# login for the iatoolkit integrated frontend
|
|
43
42
|
app.add_url_rule('/<company_short_name>/login', view_func=LoginView.as_view('login'))
|
|
@@ -57,23 +56,26 @@ def register_views(injector, app):
|
|
|
57
56
|
view_func=FinalizeContextView.as_view('finalize_with_token')
|
|
58
57
|
)
|
|
59
58
|
|
|
59
|
+
app.add_url_rule(
|
|
60
|
+
'/api/profile/language',
|
|
61
|
+
view_func=UserLanguageApiView.as_view('user_language_api')
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# logout
|
|
65
|
+
app.add_url_rule('/<company_short_name>/api/logout',
|
|
66
|
+
view_func=LogoutApiView.as_view('logout'))
|
|
67
|
+
|
|
60
68
|
# this endpoint is called by the JS for changing the token for a session
|
|
61
69
|
app.add_url_rule('/<string:company_short_name>/api/redeem_token',
|
|
62
70
|
view_func = RedeemTokenApiView.as_view('redeem_token'))
|
|
63
71
|
|
|
64
|
-
#
|
|
65
|
-
app.add_url_rule('/auth/chat_token',
|
|
66
|
-
view_func=ChatTokenRequestView.as_view('chat-token'))
|
|
67
|
-
|
|
68
|
-
# init (reset) the company context (with api-key)
|
|
72
|
+
# init (reset) the company context
|
|
69
73
|
app.add_url_rule('/<company_short_name>/api/init-context',
|
|
70
74
|
view_func=InitContextApiView.as_view('init-context'),
|
|
71
75
|
methods=['POST', 'OPTIONS'])
|
|
72
76
|
|
|
73
77
|
# register new user, account verification and forgot password
|
|
74
78
|
app.add_url_rule('/<company_short_name>/signup',view_func=SignupView.as_view('signup'))
|
|
75
|
-
app.add_url_rule('/<company_short_name>/logout', 'logout', logout)
|
|
76
|
-
app.add_url_rule('/logout', 'logout', logout)
|
|
77
79
|
app.add_url_rule('/<company_short_name>/verify/<token>', view_func=VerifyAccountView.as_view('verify_account'))
|
|
78
80
|
app.add_url_rule('/<company_short_name>/forgot-password', view_func=ForgotPasswordView.as_view('forgot_password'))
|
|
79
81
|
app.add_url_rule('/<company_short_name>/change-password/<token>', view_func=ChangePasswordView.as_view('change_password'))
|
|
@@ -85,13 +87,14 @@ def register_views(injector, app):
|
|
|
85
87
|
# open the promt directory
|
|
86
88
|
app.add_url_rule('/<company_short_name>/api/prompts', view_func=PromptApiView.as_view('prompt'))
|
|
87
89
|
|
|
88
|
-
#
|
|
90
|
+
# toolbar buttons
|
|
89
91
|
app.add_url_rule('/<company_short_name>/api/feedback', view_func=UserFeedbackApiView.as_view('feedback'))
|
|
90
92
|
app.add_url_rule('/<company_short_name>/api/history', view_func=HistoryApiView.as_view('history'))
|
|
93
|
+
app.add_url_rule('/<company_short_name>/api/help-content', view_func=HelpContentApiView.as_view('help-content'))
|
|
91
94
|
|
|
92
95
|
# tasks management endpoints: create task, and review answer
|
|
93
|
-
app.add_url_rule('/tasks', view_func=
|
|
94
|
-
app.add_url_rule('/tasks/review/<int:task_id>', view_func=
|
|
96
|
+
app.add_url_rule('/tasks', view_func=TaskApiView.as_view('tasks'))
|
|
97
|
+
app.add_url_rule('/tasks/review/<int:task_id>', view_func=TaskReviewApiView.as_view('tasks-review'))
|
|
95
98
|
|
|
96
99
|
# this endpoint is for upload documents into the vector store (api-key)
|
|
97
100
|
app.add_url_rule('/api/load', view_func=FileStoreApiView.as_view('load_api'))
|
|
@@ -133,6 +136,6 @@ def register_views(injector, app):
|
|
|
133
136
|
# hacer que la raíz '/' vaya al home de iatoolkit
|
|
134
137
|
@app.route('/')
|
|
135
138
|
def root_redirect():
|
|
136
|
-
return redirect(url_for('index'
|
|
139
|
+
return redirect(url_for('index'))
|
|
137
140
|
|
|
138
141
|
|
iatoolkit/common/util.py
CHANGED
|
@@ -21,10 +21,8 @@ class Utility:
|
|
|
21
21
|
def __init__(self):
|
|
22
22
|
self.encryption_key = os.getenv('FERNET_KEY')
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
def render_prompt_from_template(self,
|
|
26
25
|
template_pathname: str,
|
|
27
|
-
query: str = None,
|
|
28
26
|
client_data: dict = {},
|
|
29
27
|
**kwargs) -> str:
|
|
30
28
|
|
|
@@ -37,8 +35,6 @@ class Utility:
|
|
|
37
35
|
env = Environment(loader=FileSystemLoader(template_dir))
|
|
38
36
|
template = env.get_template(template_file)
|
|
39
37
|
|
|
40
|
-
kwargs["query"] = query
|
|
41
|
-
|
|
42
38
|
# add all the keys in client_data to kwargs
|
|
43
39
|
kwargs.update(client_data)
|
|
44
40
|
|
|
@@ -53,7 +49,6 @@ class Utility:
|
|
|
53
49
|
def render_prompt_from_string(self,
|
|
54
50
|
template_string: str,
|
|
55
51
|
searchpath: str | list[str] = None,
|
|
56
|
-
query: str = None,
|
|
57
52
|
client_data: dict = {},
|
|
58
53
|
**kwargs) -> str:
|
|
59
54
|
"""
|
|
@@ -76,7 +71,6 @@ class Utility:
|
|
|
76
71
|
env = Environment(loader=loader)
|
|
77
72
|
template = env.from_string(template_string)
|
|
78
73
|
|
|
79
|
-
kwargs["query"] = query
|
|
80
74
|
kwargs.update(client_data)
|
|
81
75
|
|
|
82
76
|
prompt = template.render(**kwargs)
|
|
@@ -87,6 +81,23 @@ class Utility:
|
|
|
87
81
|
f'No se pudo renderizar el template desde el string, error: {str(e)}') from e
|
|
88
82
|
|
|
89
83
|
|
|
84
|
+
def get_company_template(self, company_short_name: str, template_name: str) -> str:
|
|
85
|
+
# 1. get the path to the company specific template
|
|
86
|
+
template_path = os.path.join(os.getcwd(), f'companies/{company_short_name}/templates/{template_name}')
|
|
87
|
+
if not os.path.exists(template_path):
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
# 2. read the file
|
|
91
|
+
try:
|
|
92
|
+
with open(template_path, 'r') as f:
|
|
93
|
+
template_string = f.read()
|
|
94
|
+
|
|
95
|
+
return template_string
|
|
96
|
+
except Exception as e:
|
|
97
|
+
logging.exception(e)
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
|
|
90
101
|
def serialize(self, obj):
|
|
91
102
|
if isinstance(obj, datetime) or isinstance(obj, date):
|
|
92
103
|
return obj.isoformat()
|
iatoolkit/company_registry.py
CHANGED
|
@@ -31,10 +31,9 @@ class CompanyRegistry:
|
|
|
31
31
|
|
|
32
32
|
# save the created instance in the registry
|
|
33
33
|
self._company_instances[company_key] = company_instance
|
|
34
|
-
logging.info(f"company '{company_key}' instantiated")
|
|
35
34
|
|
|
36
35
|
except Exception as e:
|
|
37
|
-
logging.error(f"Error
|
|
36
|
+
logging.error(f"Error while creating company instance for {company_key}: {e}")
|
|
38
37
|
logging.exception(e)
|
|
39
38
|
raise
|
|
40
39
|
|
iatoolkit/iatoolkit.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#
|
|
4
4
|
# IAToolkit is open source software.
|
|
5
5
|
|
|
6
|
-
from flask import Flask, url_for
|
|
6
|
+
from flask import Flask, url_for, get_flashed_messages
|
|
7
7
|
from flask_session import Session
|
|
8
8
|
from flask_injector import FlaskInjector
|
|
9
9
|
from flask_bcrypt import Bcrypt
|
|
@@ -16,10 +16,10 @@ import os
|
|
|
16
16
|
from typing import Optional, Dict, Any
|
|
17
17
|
from iatoolkit.repositories.database_manager import DatabaseManager
|
|
18
18
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
19
|
-
from injector import Binder,
|
|
19
|
+
from injector import Binder, Injector, singleton
|
|
20
20
|
from importlib.metadata import version as _pkg_version, PackageNotFoundError
|
|
21
21
|
|
|
22
|
-
IATOOLKIT_VERSION = "0.
|
|
22
|
+
IATOOLKIT_VERSION = "0.67.0"
|
|
23
23
|
|
|
24
24
|
# global variable for the unique instance of IAToolkit
|
|
25
25
|
_iatoolkit_instance: Optional['IAToolkit'] = None
|
|
@@ -52,7 +52,7 @@ class IAToolkit:
|
|
|
52
52
|
self.app = None
|
|
53
53
|
self.db_manager = None
|
|
54
54
|
self._injector = None
|
|
55
|
-
self.version = IATOOLKIT_VERSION
|
|
55
|
+
self.version = IATOOLKIT_VERSION # default version
|
|
56
56
|
|
|
57
57
|
@classmethod
|
|
58
58
|
def get_instance(cls) -> 'IAToolkit':
|
|
@@ -88,7 +88,7 @@ class IAToolkit:
|
|
|
88
88
|
# and other integrations, as views are handled manually.
|
|
89
89
|
FlaskInjector(app=self.app, injector=self._injector)
|
|
90
90
|
|
|
91
|
-
# Step 6: initialize dispatcher and registered
|
|
91
|
+
# Step 6: initialize dispatcher and registered companies
|
|
92
92
|
self._init_dispatcher_and_company_instances()
|
|
93
93
|
|
|
94
94
|
# Step 7: Finalize setup within the application context
|
|
@@ -96,13 +96,12 @@ class IAToolkit:
|
|
|
96
96
|
self._setup_cors()
|
|
97
97
|
self._setup_additional_services()
|
|
98
98
|
self._setup_cli_commands()
|
|
99
|
+
self._setup_request_globals()
|
|
99
100
|
self._setup_context_processors()
|
|
100
101
|
|
|
101
102
|
# Step 8: define the download_dir for excel's
|
|
102
103
|
self._setup_download_dir()
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
105
|
logging.info(f"🎉 IAToolkit v{self.version} inicializado correctamente")
|
|
107
106
|
self._initialized = True
|
|
108
107
|
return self.app
|
|
@@ -111,6 +110,22 @@ class IAToolkit:
|
|
|
111
110
|
# get a value from the config dict or the environment variable
|
|
112
111
|
return self.config.get(key, os.getenv(key, default))
|
|
113
112
|
|
|
113
|
+
def _setup_request_globals(self):
|
|
114
|
+
"""
|
|
115
|
+
Configures functions to run before each request to set up
|
|
116
|
+
request-global variables, such as language.
|
|
117
|
+
"""
|
|
118
|
+
injector = self._injector
|
|
119
|
+
|
|
120
|
+
@self.app.before_request
|
|
121
|
+
def set_request_language():
|
|
122
|
+
"""
|
|
123
|
+
Determines and caches the language for the current request in g.lang.
|
|
124
|
+
"""
|
|
125
|
+
from iatoolkit.services.language_service import LanguageService
|
|
126
|
+
language_service = injector.get(LanguageService)
|
|
127
|
+
language_service.get_current_language()
|
|
128
|
+
|
|
114
129
|
def _setup_logging(self):
|
|
115
130
|
# Lee el nivel de log desde una variable de entorno, con 'INFO' como valor por defecto.
|
|
116
131
|
log_level_name = os.getenv('LOG_LEVEL', 'INFO').upper()
|
|
@@ -226,19 +241,19 @@ class IAToolkit:
|
|
|
226
241
|
|
|
227
242
|
def _setup_cors(self):
|
|
228
243
|
"""🌐 Configura CORS"""
|
|
229
|
-
|
|
244
|
+
from iatoolkit.company_registry import get_company_registry
|
|
245
|
+
|
|
246
|
+
# default CORS origin
|
|
230
247
|
default_origins = [
|
|
231
|
-
"http://localhost:5001",
|
|
232
|
-
"http://127.0.0.1:5001",
|
|
233
248
|
os.getenv('IATOOLKIT_BASE_URL')
|
|
234
249
|
]
|
|
235
250
|
|
|
236
|
-
#
|
|
251
|
+
# Iterate through the registered company names
|
|
237
252
|
extra_origins = []
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
253
|
+
all_company_instances = get_company_registry().get_all_company_instances()
|
|
254
|
+
for company_name, company_instance in all_company_instances.items():
|
|
255
|
+
cors_origin = company_instance.company.parameters.get('cors_origin', [])
|
|
256
|
+
extra_origins += cors_origin
|
|
242
257
|
|
|
243
258
|
all_origins = default_origins + extra_origins
|
|
244
259
|
|
|
@@ -253,7 +268,6 @@ class IAToolkit:
|
|
|
253
268
|
|
|
254
269
|
logging.info(f"✅ CORS configurado para: {all_origins}")
|
|
255
270
|
|
|
256
|
-
|
|
257
271
|
def _configure_core_dependencies(self, binder: Binder):
|
|
258
272
|
"""⚙️ Configures all system dependencies."""
|
|
259
273
|
try:
|
|
@@ -302,6 +316,10 @@ class IAToolkit:
|
|
|
302
316
|
from iatoolkit.services.jwt_service import JWTService
|
|
303
317
|
from iatoolkit.services.dispatcher_service import Dispatcher
|
|
304
318
|
from iatoolkit.services.branding_service import BrandingService
|
|
319
|
+
from iatoolkit.services.i18n_service import I18nService
|
|
320
|
+
from iatoolkit.services.language_service import LanguageService
|
|
321
|
+
from iatoolkit.services.onboarding_service import OnboardingService
|
|
322
|
+
from iatoolkit.services.configuration_service import ConfigurationService
|
|
305
323
|
|
|
306
324
|
binder.bind(QueryService, to=QueryService)
|
|
307
325
|
binder.bind(TaskService, to=TaskService)
|
|
@@ -315,6 +333,10 @@ class IAToolkit:
|
|
|
315
333
|
binder.bind(JWTService, to=JWTService)
|
|
316
334
|
binder.bind(Dispatcher, to=Dispatcher)
|
|
317
335
|
binder.bind(BrandingService, to=BrandingService)
|
|
336
|
+
binder.bind(OnboardingService, to=OnboardingService)
|
|
337
|
+
binder.bind(I18nService, to=I18nService)
|
|
338
|
+
binder.bind(LanguageService, to=LanguageService)
|
|
339
|
+
binder.bind(ConfigurationService, to=ConfigurationService)
|
|
318
340
|
|
|
319
341
|
def _bind_infrastructure(self, binder: Binder):
|
|
320
342
|
from iatoolkit.infra.llm_client import llmClient
|
|
@@ -324,8 +346,8 @@ class IAToolkit:
|
|
|
324
346
|
from iatoolkit.services.auth_service import AuthService
|
|
325
347
|
from iatoolkit.common.util import Utility
|
|
326
348
|
|
|
327
|
-
binder.bind(LLMProxy, to=LLMProxy
|
|
328
|
-
binder.bind(llmClient, to=llmClient
|
|
349
|
+
binder.bind(LLMProxy, to=LLMProxy)
|
|
350
|
+
binder.bind(llmClient, to=llmClient)
|
|
329
351
|
binder.bind(GoogleChatApp, to=GoogleChatApp)
|
|
330
352
|
binder.bind(MailApp, to=MailApp)
|
|
331
353
|
binder.bind(AuthService, to=AuthService)
|
|
@@ -341,9 +363,9 @@ class IAToolkit:
|
|
|
341
363
|
# instantiate all the registered companies
|
|
342
364
|
get_company_registry().instantiate_companies(self._injector)
|
|
343
365
|
|
|
344
|
-
# use the dispatcher to
|
|
366
|
+
# use the dispatcher to load the config and prepare the execution
|
|
345
367
|
dispatcher = self._injector.get(Dispatcher)
|
|
346
|
-
dispatcher.
|
|
368
|
+
dispatcher.load_company_configs()
|
|
347
369
|
|
|
348
370
|
def _setup_cli_commands(self):
|
|
349
371
|
from iatoolkit.cli_commands import register_core_commands
|
|
@@ -369,8 +391,18 @@ class IAToolkit:
|
|
|
369
391
|
def inject_globals():
|
|
370
392
|
from iatoolkit.common.session_manager import SessionManager
|
|
371
393
|
from iatoolkit.services.profile_service import ProfileService
|
|
394
|
+
from iatoolkit.services.i18n_service import I18nService
|
|
372
395
|
|
|
396
|
+
# Get services from the injector
|
|
373
397
|
profile_service = self._injector.get(ProfileService)
|
|
398
|
+
i18n_service = self._injector.get(I18nService)
|
|
399
|
+
|
|
400
|
+
# The 't' function wrapper no longer needs to determine the language itself.
|
|
401
|
+
# It will be automatically handled by the refactored I18nService.
|
|
402
|
+
def translate_for_template(key: str, **kwargs):
|
|
403
|
+
return i18n_service.t(key, **kwargs)
|
|
404
|
+
|
|
405
|
+
# Get user profile if a session exists
|
|
374
406
|
user_profile = profile_service.get_current_session_info().get('profile', {})
|
|
375
407
|
|
|
376
408
|
return {
|
|
@@ -382,6 +414,8 @@ class IAToolkit:
|
|
|
382
414
|
'user_is_local': user_profile.get('user_is_local'),
|
|
383
415
|
'user_email': user_profile.get('user_email'),
|
|
384
416
|
'iatoolkit_base_url': os.environ.get('IATOOLKIT_BASE_URL', ''),
|
|
417
|
+
'flashed_messages': get_flashed_messages(with_categories=True),
|
|
418
|
+
't': translate_for_template
|
|
385
419
|
}
|
|
386
420
|
|
|
387
421
|
def _get_default_static_folder(self) -> str:
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Language: English
|
|
2
|
+
ui:
|
|
3
|
+
login_widget:
|
|
4
|
+
title: "Sign In"
|
|
5
|
+
welcome_message: "Enter your credentials or register to access Sample Company’s AI platform."
|
|
6
|
+
email_placeholder: "Email address"
|
|
7
|
+
password_placeholder: "Password"
|
|
8
|
+
login_button: "Login"
|
|
9
|
+
forgot_password_link: "Forgot your password?"
|
|
10
|
+
no_account_prompt: "Don't have an account?"
|
|
11
|
+
signup_link: "Sign Up"
|
|
12
|
+
|
|
13
|
+
signup:
|
|
14
|
+
title: "Create an Account"
|
|
15
|
+
subtitle: "Start your journey with us today."
|
|
16
|
+
first_name_label: "First Name"
|
|
17
|
+
last_name_label: "Last Name"
|
|
18
|
+
email_label: "Email Address"
|
|
19
|
+
password_label: "Password"
|
|
20
|
+
confirm_password_label: "Confirm Password"
|
|
21
|
+
signup_button: "Create Account"
|
|
22
|
+
already_have_account: "Already have an account?"
|
|
23
|
+
login_link: "Log In"
|
|
24
|
+
disclaimer: "🔒We value your privacy. Your data will be used exclusively for the operation of the platform."
|
|
25
|
+
|
|
26
|
+
forgot_password:
|
|
27
|
+
title: "Recover Password"
|
|
28
|
+
subtitle: "Enter your email address and we will send you a link to reset your password."
|
|
29
|
+
submit_button: "Send Recovery Link"
|
|
30
|
+
back_to_login: "Back to Login"
|
|
31
|
+
|
|
32
|
+
change_password:
|
|
33
|
+
title: "Create New Password"
|
|
34
|
+
subtitle: "You are changing the password for <strong>{email}</strong>."
|
|
35
|
+
temp_code_label: "Temporary Code"
|
|
36
|
+
temp_code_placeholder: "Check your email"
|
|
37
|
+
new_password_label: "New Password"
|
|
38
|
+
password_instructions: "Must contain at least 8 characters, an uppercase letter, a lowercase letter, a number, and a special character."
|
|
39
|
+
confirm_password_label: "Confirm New Password"
|
|
40
|
+
save_button: "Save Password"
|
|
41
|
+
back_to_home: "Back to home"
|
|
42
|
+
|
|
43
|
+
chat:
|
|
44
|
+
welcome_message: "Hello! How can I help you today?"
|
|
45
|
+
input_placeholder: "Type your query here..."
|
|
46
|
+
prompts_available: "Available prompts"
|
|
47
|
+
|
|
48
|
+
tooltips:
|
|
49
|
+
history: "History of my queries"
|
|
50
|
+
reload_context: "Force Context Reload"
|
|
51
|
+
feedback: "Your feedback is very important"
|
|
52
|
+
usage_guide: "Usage Guide"
|
|
53
|
+
onboarding: "How to ask better questions"
|
|
54
|
+
logout: "Log out"
|
|
55
|
+
use_prompt_assistant: "Use Prompt Assistant"
|
|
56
|
+
attach_files: "Attach files"
|
|
57
|
+
view_attached_files: "View attached files"
|
|
58
|
+
send: "Send"
|
|
59
|
+
stop: "Stop"
|
|
60
|
+
|
|
61
|
+
modals:
|
|
62
|
+
files_title: "Uploaded Files"
|
|
63
|
+
feedback_title: "Your Opinion is Important"
|
|
64
|
+
feedback_prompt: "How useful was the assistant's response?"
|
|
65
|
+
feedback_comment_label: "Your feedback helps us improve:"
|
|
66
|
+
feedback_comment_placeholder: "Write your opinion, suggestions, or comments here..."
|
|
67
|
+
history_title: "Query History"
|
|
68
|
+
history_table_date: "Date"
|
|
69
|
+
history_table_query: "Query"
|
|
70
|
+
loading_history: "Loading history..."
|
|
71
|
+
no_history_found: "No query history found."
|
|
72
|
+
help_title: "AI Assistant User Guide"
|
|
73
|
+
|
|
74
|
+
buttons:
|
|
75
|
+
cancel: "Close"
|
|
76
|
+
send: "Send"
|
|
77
|
+
stop: "Stop"
|
|
78
|
+
|
|
79
|
+
errors:
|
|
80
|
+
company_not_found: "The company {company_short_name} does not exist."
|
|
81
|
+
timeout: "timeout expired."
|
|
82
|
+
auth:
|
|
83
|
+
invalid_password: "The provided password is incorrect."
|
|
84
|
+
user_not_found: "A user with that email address was not found."
|
|
85
|
+
invalid_or_expired_token: "Invalid or expired token."
|
|
86
|
+
session_creation_failed: "Could not create user session."
|
|
87
|
+
authentication_required: "Authentication required. No session cookie or API Key provided."
|
|
88
|
+
invalid_api_key: "Invalid or inactive API Key."
|
|
89
|
+
no_user_identifier_api: "No user_identifier provided for API call."
|
|
90
|
+
templates:
|
|
91
|
+
company_not_found: "Company not found."
|
|
92
|
+
home_template_not_found: "The home page template for the company '{company_name}' is not configured."
|
|
93
|
+
template_not_found: "Template not found: '{template_name}'."
|
|
94
|
+
|
|
95
|
+
processing_error: "An error occurred while processing the custom home page template: {error}"
|
|
96
|
+
general:
|
|
97
|
+
unexpected_error: "An unexpected error has occurred. Please contact support."
|
|
98
|
+
unsupported_language: "The selected language is not supported."
|
|
99
|
+
signup:
|
|
100
|
+
company_not_found: "The company {company_name} does not exist."
|
|
101
|
+
incorrect_password_for_existing_user: "The password for the user {email} is incorrect."
|
|
102
|
+
user_already_registered: "The user with email '{email}' already exists in this company."
|
|
103
|
+
password_mismatch: "The passwords do not match. Please try again."
|
|
104
|
+
change_password:
|
|
105
|
+
token_expired: "The password change link has expired. Please request a new one."
|
|
106
|
+
password_mismatch: "The passwords do not match. Please try again."
|
|
107
|
+
invalid_temp_code: "The temporary code is not valid. Please check it or request a new one."
|
|
108
|
+
forgot_password:
|
|
109
|
+
user_not_registered: "The user with email {email} is not registered."
|
|
110
|
+
verification:
|
|
111
|
+
token_expired: "The verification link has expired. Please contact support if you need a new one."
|
|
112
|
+
user_not_found: "The user you are trying to verify does not exist."
|
|
113
|
+
validation:
|
|
114
|
+
password_too_short: "Password must be at least 8 characters long."
|
|
115
|
+
password_no_uppercase: "Password must contain at least one uppercase letter."
|
|
116
|
+
password_no_lowercase: "Password must contain at least one lowercase letter."
|
|
117
|
+
password_no_digit: "Password must contain at least one number."
|
|
118
|
+
password_no_special_char: "Password must contain at least one special character."
|
|
119
|
+
|
|
120
|
+
services:
|
|
121
|
+
no_text_file: "The file is not text or the encoding is not UTF-8"
|
|
122
|
+
no_output_file: "Missing output file name"
|
|
123
|
+
no_data_for_excel: "Missing data or it is not a list of dictionaries"
|
|
124
|
+
no_download_directory: "Temporary directory for saving Excel files is not configured"
|
|
125
|
+
cannot_create_excel: "Could not create the Excel file"
|
|
126
|
+
invalid_filename: "Invalid filename"
|
|
127
|
+
file_not_exist: "File not found"
|
|
128
|
+
path_is_not_a_file: "The path does not correspond to a file"
|
|
129
|
+
file_validation_error: "Error validating file"
|
|
130
|
+
user_not_authorized: "user is not authorized for this company"
|
|
131
|
+
account_not_verified: "Your account has not been verified. Please check your email."
|
|
132
|
+
missing_response_id: "Can not found 'previous_response_id' for '{company_short_name}/{user_identifier}'. Reinit context"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
api_responses:
|
|
136
|
+
context_reloaded_success: "The context has been successfully reloaded."
|
|
137
|
+
|
|
138
|
+
services:
|
|
139
|
+
mail_sent: "Email sent successfully."
|
|
140
|
+
start_query: "Hello, what can I help you with today?"
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
flash_messages:
|
|
144
|
+
password_changed_success: "Your password has been successfully reset. You can now log in."
|
|
145
|
+
login_required: "Please log in to continue."
|
|
146
|
+
signup_success: "Registration successful. Please check your email to verify your account."
|
|
147
|
+
user_associated_success: "Existing user successfully associated with the new company."
|
|
148
|
+
account_verified_success: "Your account has been successfully verified. Welcome!"
|
|
149
|
+
forgot_password_success: "If your email is registered, you will receive a link to reset your password."
|
|
150
|
+
|
|
151
|
+
# Keys specifically for JavaScript
|
|
152
|
+
js_messages:
|
|
153
|
+
feedback_sent_success_title: "Feedback Sent"
|
|
154
|
+
feedback_sent_success_body: "Thank you for your feedback!"
|
|
155
|
+
feedback_sent_error: "Could not send feedback, please try again."
|
|
156
|
+
feedback_rating_error: "Please rate the assistant using the stars."
|
|
157
|
+
feedback_comment_error: "Please write your comment before sending."
|
|
158
|
+
context_reloaded: "Context has been reloaded."
|
|
159
|
+
error_loading_history: "An error occurred while loading the history."
|
|
160
|
+
request_aborted: "The response generation has been stopped."
|
|
161
|
+
processing_error: "An error occurred while processing the request."
|
|
162
|
+
server_comm_error: "Server communication error ({status}). Please try again later."
|
|
163
|
+
network_error: "A network error occurred. Please try again in a few moments."
|
|
164
|
+
unknown_server_error: "Unknown server error."
|
|
165
|
+
loading: "Loading..."
|
|
166
|
+
reload_init: "init reloading context in background..."
|
|
167
|
+
no_history_found: "No query history found."
|