pbesa 4.0.18__tar.gz → 4.0.19__tar.gz
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.
- {pbesa-4.0.18 → pbesa-4.0.19}/.gitignore +2 -1
- {pbesa-4.0.18 → pbesa-4.0.19}/PKG-INFO +1 -1
- pbesa-4.0.19/pbesa/celulas/celula_simulador_ciudadano.py +115 -0
- pbesa-4.0.19/pbesa/celulas/data_extraction_cel.py +148 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/cognitive.py +55 -8
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa.egg-info/PKG-INFO +1 -1
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa.egg-info/SOURCES.txt +2 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/setup.py +1 -1
- {pbesa-4.0.18 → pbesa-4.0.19}/LICENSE +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/LICENSE.txt +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/MANIFEST +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/README.md +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/db.sqlite3 +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/settings.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/wsgi.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/asgi.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/pbesa.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/settings.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/urls.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/wsgi.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/manage.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/views.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/admin.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/apps.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/controller/translatecontroller.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/controller/translatedelegate.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/controller/translateresponse.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/worker/translatetask.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/worker/workeragent.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/migrations/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/migrations/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/models.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/tests.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/urls.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/views.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/__pycache__/countercontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/__pycache__/counterdelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/__pycache__/counterresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/countercontroller.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/counterdelegate.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/controller/counterresponse.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/counteragent.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/countertask.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/remote_a.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/remote_b.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/remote_c.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_casos.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_consultas.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_datos_identificables.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_expertos.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_generar_documento.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_preguntas.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/celula_saludos.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/celulas/web.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/adapter.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/agent.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/io/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/io/system_file.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/io/tcp_server.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/res/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/res/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/res/__pycache__/__init__.cpython-37.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/res/__pycache__/__init__.cpython-38.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/res/__pycache__/__init__.cpython-39.pyc +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/res/conf.json +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/util.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/kernel/world.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/mas.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/models.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/remote/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/remote/adm_listener.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/remote/adm_listener_handler.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/remote/exceptions.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/remote/remote_adm.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/remote/remote_adm_handler.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/__init__.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/collaborative_team.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/delegator.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/delegator_team.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/dialog.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/dispatcher_team.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/prompts.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/selected_dispatcher_team.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/templates.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa/social/worker.py +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa.egg-info/dependency_links.txt +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa.egg-info/requires.txt +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/pbesa.egg-info/top_level.txt +0 -0
- {pbesa-4.0.18 → pbesa-4.0.19}/setup.cfg +0 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
SYSTEM_PROMPT = """
|
4
|
+
Eres un **simulador de demandantes ante entes de control**.
|
5
|
+
Tu tarea es leer la **solicitud de demanda** que se te entregue y luego **responder cualquier pregunta** actuando como la persona que radicó dicha demanda.
|
6
|
+
|
7
|
+
Responde siempre en **primera persona**, manteniendo un tono respetuoso y claro.
|
8
|
+
Menciona o alude a los entes de control involucrados cuando sea pertinente (SIC – Superintendencia de Industria y Comercio, ICA – Instituto Colombiano Agropecuario, DIMAR – Dirección General Marítima, SFC – Superintendencia Financiera de Colombia, SNS – Superintendencia Nacional de Salud, entre otros).
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
### Criterios que debe cumplir la respuesta
|
13
|
+
|
14
|
+
1. **Perspectiva**: primera persona singular (“yo”, “mi”).
|
15
|
+
2. **Coherencia**: debe basarse exclusivamente en la información provista en la demanda.
|
16
|
+
3. **Pertinencia**: enfócate en la pregunta; no agregues información externa ni resoluciones legales.
|
17
|
+
4. **Claridad**: utiliza lenguaje sencillo y directo, evitando tecnicismos innecesarios.
|
18
|
+
5. **Respeto**: mantén un tono formal y cortés frente a la autoridad.
|
19
|
+
|
20
|
+
**Importante**:
|
21
|
+
- Solo responde a la pregunta. No agregues información adicional que no esté relacionada con la demanda.
|
22
|
+
- Solo responde a la pregunta. No agregres explicaciones o justificaciones.
|
23
|
+
- Si te preguntan datos personales, responde con datos inventados.
|
24
|
+
- Si te preguntan datos de contacto, responde con datos inventados.
|
25
|
+
- Si te preguntan de persona jurídica, responde con datos inventados.
|
26
|
+
- Si te preguntan si deseas que te asista en la radicación de la demanda, responde que sí.
|
27
|
+
|
28
|
+
---
|
29
|
+
|
30
|
+
### Ejemplos
|
31
|
+
|
32
|
+
**Demanda de ejemplo**
|
33
|
+
> “Como ciudadano preocupado por la seguridad fluvial, pongo en conocimiento que una barcaza de la Empresa de Transporte Fluvial del Magdalena se encuentra navegando sin certificado de navegabilidad vigente, lo cual representa un riesgo para la vida humana y la operación segura en el río.”
|
34
|
+
|
35
|
+
| Pregunta | Respuesta esperada |
|
36
|
+
|----------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
37
|
+
| “¿Cuál es el principal riesgo que identificó?” | “Considero que el principal riesgo es la posible pérdida de vidas humanas ante un accidente, pues la embarcación no ha demostrado cumplir con los requisitos técnicos exigidos por DIMAR.” |
|
38
|
+
| “¿Por qué decidió acudir ante la DIMAR y no a otra entidad?” | “Acudí a DIMAR porque es la autoridad marítima competente para verificar los certificados de navegabilidad y sancionar irregularidades en operaciones fluviales.” |
|
39
|
+
| “¿Ha presentado pruebas?” | “Sí, anexé fotografías donde se observa la matrícula de la barcaza y la fecha de expiración del certificado.” |
|
40
|
+
|
41
|
+
---
|
42
|
+
"""
|
43
|
+
|
44
|
+
USER_PROMPT = """
|
45
|
+
### Plantilla de uso
|
46
|
+
|
47
|
+
Demanda:
|
48
|
+
%s
|
49
|
+
"""
|
50
|
+
class UserSimulator(object):
|
51
|
+
"""
|
52
|
+
Clase que simula un usuario demandante ante entes de control.
|
53
|
+
"""
|
54
|
+
|
55
|
+
class __UserSimulator:
|
56
|
+
|
57
|
+
def __init__(self, service):
|
58
|
+
self.iteracion = 1
|
59
|
+
self.work_memory = []
|
60
|
+
self.service = service
|
61
|
+
|
62
|
+
# Efectua la inferencia del modelo.
|
63
|
+
def evaluate(self, text, max_tkns=2000, reset=False) -> any:
|
64
|
+
try:
|
65
|
+
if reset:
|
66
|
+
self.iteracion = 1
|
67
|
+
self.work_memory = []
|
68
|
+
logging.info("\n")
|
69
|
+
logging.info(f"Procesando: {text} - Iteración: {self.iteracion}")
|
70
|
+
if self.iteracion == 1:
|
71
|
+
prompt = SYSTEM_PROMPT
|
72
|
+
self.work_memory.append({"role": "system", "content": SYSTEM_PROMPT})
|
73
|
+
prompt = USER_PROMPT % text
|
74
|
+
self.work_memory.append({"role": "user", "content": prompt})
|
75
|
+
else:
|
76
|
+
self.work_memory.append({"role": "user", "content": text})
|
77
|
+
res = self.service.generate(self.work_memory, max_tkns)
|
78
|
+
self.work_memory.append({"role": "assistant", "content": res})
|
79
|
+
self.iteracion += 1
|
80
|
+
logging.info(f"Respuesta: {res}")
|
81
|
+
logging.info("\n")
|
82
|
+
if not res or res == "":
|
83
|
+
res = text
|
84
|
+
logging.warning(f"No obtener una respuesta.")
|
85
|
+
return res
|
86
|
+
except Exception as e:
|
87
|
+
logging.error(f"Error al procesar: {text}")
|
88
|
+
logging.error(e)
|
89
|
+
return None
|
90
|
+
|
91
|
+
# Singleton instance
|
92
|
+
instance = None
|
93
|
+
|
94
|
+
def __new__(cls, service) -> object:
|
95
|
+
""" Create new instance """
|
96
|
+
if not UserSimulator.instance:
|
97
|
+
UserSimulator.instance = UserSimulator.__UserSimulator(service)
|
98
|
+
return UserSimulator.instance
|
99
|
+
|
100
|
+
def __getattr__(self, name: str) -> object:
|
101
|
+
""" Get attribute
|
102
|
+
@param name Attribute name
|
103
|
+
@return object Attribute
|
104
|
+
"""
|
105
|
+
return getattr(self.instance, name)
|
106
|
+
|
107
|
+
def __setattr__(self, name:str) -> object:
|
108
|
+
""" Set attribute
|
109
|
+
@param name Attribute name
|
110
|
+
@return object Attribute
|
111
|
+
"""
|
112
|
+
return setattr(self.instance, name)
|
113
|
+
|
114
|
+
def derive(service, text, max_tkns=2000, reset=False) -> any:
|
115
|
+
return UserSimulator(service).evaluate(text, max_tkns=max_tkns, reset=reset)
|
@@ -0,0 +1,148 @@
|
|
1
|
+
import re
|
2
|
+
import json
|
3
|
+
import logging
|
4
|
+
|
5
|
+
SYSTEM_PROMPT = """
|
6
|
+
Eres un generador de JSON. Tu tarea es extraer la información proporcionada por el usuario, basándose en la descripción de los campos requeridos, y formatearla como un objeto JSON.
|
7
|
+
|
8
|
+
**Descripción de los campos requeridos:**
|
9
|
+
%s
|
10
|
+
|
11
|
+
**Instrucciones para la extracción y formato JSON:**
|
12
|
+
1. Identifica cada valor proporcionado por el usuario y asócialo con su campo correspondiente de la descripción.
|
13
|
+
2. Los nombres de los campos en el JSON deben ser exactamente los de la "Descripción de los campos requeridos", sin las llaves ni guiones.
|
14
|
+
3. Si un campo no tiene un valor claro en la respuesta del usuario, omítelo del JSON.
|
15
|
+
4. Asegúrate de que el JSON sea válido.
|
16
|
+
|
17
|
+
**Ejemplo de cómo el usuario podría responder y cómo debe ser el JSON resultante (basado en la descripción de campos "datos del Demandante: - Correo electrónico - Primer Nombre - Segundo Nombre - Primer Apellido - Segundo Apellido - Tipo de documento - Identificación - País donde se hace la solicitud - Departamento / Estado / Provincia donde se hace la solicitud - Municipio / Ciudad donde se hace la solicitud - Dirección notificación judicial"):**
|
18
|
+
|
19
|
+
**Respuesta del usuario:** "micorreo@correo.com, Fabian, Jose, Roldan, Piñeros, CC, 123456789, Colombia, Cundinamarca, Bogotá, Calle 100 #10-20"
|
20
|
+
**JSON resultante:**
|
21
|
+
```json
|
22
|
+
{
|
23
|
+
"Correo electrónico": "micorreo@correo.com",
|
24
|
+
"Primer Nombre": "Fabian",
|
25
|
+
"Segundo Nombre": "Jose",
|
26
|
+
"Primer Apellido": "Roldan",
|
27
|
+
"Segundo Apellido": "Piñeros",
|
28
|
+
"Tipo de documento": "CC",
|
29
|
+
"Identificación": "123456789",
|
30
|
+
"País donde se hace la solicitud": "Colombia",
|
31
|
+
"Departamento / Estado / Provincia donde se hace la solicitud": "Cundinamarca",
|
32
|
+
"Municipio / Ciudad donde se hace la solicitud": "Bogotá",
|
33
|
+
"Dirección notificación judicial": "Calle 100 #10-20"
|
34
|
+
}
|
35
|
+
"""
|
36
|
+
|
37
|
+
USER_PROMPT = """
|
38
|
+
|
39
|
+
Texto: "%s"
|
40
|
+
|
41
|
+
Clasificación:
|
42
|
+
"""
|
43
|
+
|
44
|
+
def extract_field_constraints(text):
|
45
|
+
field_constraints = {}
|
46
|
+
start_index = text.find(':')
|
47
|
+
if start_index != -1:
|
48
|
+
text = text[start_index+1:].strip()
|
49
|
+
lines = text.strip().split('\n')
|
50
|
+
for line in lines:
|
51
|
+
line = line.strip()
|
52
|
+
if not line:
|
53
|
+
continue
|
54
|
+
clean_line = line.lstrip('- ').strip()
|
55
|
+
is_obligatorio = True
|
56
|
+
if '(obligatorio)' in clean_line:
|
57
|
+
is_obligatorio = True
|
58
|
+
field_name = clean_line.replace('(obligatorio)', '').strip()
|
59
|
+
elif '(no obligatorio)' in clean_line:
|
60
|
+
is_obligatorio = False
|
61
|
+
field_name = clean_line.replace('(no obligatorio)', '').strip()
|
62
|
+
else:
|
63
|
+
field_name = clean_line.strip()
|
64
|
+
field_constraints[field_name] = is_obligatorio
|
65
|
+
return field_constraints
|
66
|
+
|
67
|
+
def validar_campo(validaciones_campos, nombre_campo, valor):
|
68
|
+
if nombre_campo in validaciones_campos:
|
69
|
+
config = validaciones_campos[nombre_campo]
|
70
|
+
regex = config["validacion"]
|
71
|
+
mensaje = config["mensaje_error"]
|
72
|
+
if re.fullmatch(regex, valor):
|
73
|
+
return True, None
|
74
|
+
else:
|
75
|
+
return False, mensaje
|
76
|
+
else:
|
77
|
+
return False, f"No se encontró configuración de validación para el campo: {nombre_campo}"
|
78
|
+
|
79
|
+
def procesar_datos(validaciones_campos, description, datos):
|
80
|
+
""" Procesa los datos extraídos y valida cada campo """
|
81
|
+
# Obtiene los campos
|
82
|
+
field_constraints = extract_field_constraints(description)
|
83
|
+
logging.info("Campos extraídos:")
|
84
|
+
logging.info(json.dumps(field_constraints, indent=4))
|
85
|
+
for field, is_required in field_constraints.items():
|
86
|
+
if is_required and field not in datos:
|
87
|
+
logging.error(f"Falta el campo obligatorio: {field}")
|
88
|
+
return None
|
89
|
+
if field not in datos:
|
90
|
+
datos[field] = None
|
91
|
+
logging.info("Los campos estan completos.")
|
92
|
+
# Validar los campos extraídos
|
93
|
+
errores = []
|
94
|
+
resultado = {}
|
95
|
+
for campo, valor in datos.items():
|
96
|
+
valido, mensaje_error = validar_campo(validaciones_campos, campo, str(valor))
|
97
|
+
if not valido:
|
98
|
+
errores.append(f"Error en '{campo}': {mensaje_error}")
|
99
|
+
else:
|
100
|
+
resultado[campo] = valor
|
101
|
+
if errores:
|
102
|
+
logging.error("Errores de validación encontrados:")
|
103
|
+
for error in errores:
|
104
|
+
logging.error(error)
|
105
|
+
return None, error
|
106
|
+
else:
|
107
|
+
logging.info("Todos los campos validados correctamente.")
|
108
|
+
return resultado, None
|
109
|
+
|
110
|
+
def get_struct(text):
|
111
|
+
json_start = text.find('{')
|
112
|
+
json_end = text.rfind('}') + 1
|
113
|
+
json_string = text[json_start:json_end]
|
114
|
+
return json.loads(json_string)
|
115
|
+
|
116
|
+
# Efectua la inferencia del modelo.
|
117
|
+
def call_engine(service, description, text) -> any:
|
118
|
+
try:
|
119
|
+
tmp_work_memory = []
|
120
|
+
system_prompt = SYSTEM_PROMPT % description
|
121
|
+
tmp_work_memory.append({"role": "system", "content": system_prompt})
|
122
|
+
user_prompt = USER_PROMPT % text
|
123
|
+
tmp_work_memory.append({"role": "user", "content": user_prompt})
|
124
|
+
logging.info(f"Enviando solicitud al modelo...")
|
125
|
+
res = service.generate(tmp_work_memory)
|
126
|
+
result = get_struct(res)
|
127
|
+
logging.info(f"El model ha respondido con éxito.")
|
128
|
+
return result
|
129
|
+
except Exception as e:
|
130
|
+
logging.error(f"El modelo ha fallado al procesar la solicitud.")
|
131
|
+
logging.error(f"Error al procesar: {text}")
|
132
|
+
logging.error(e)
|
133
|
+
return None
|
134
|
+
|
135
|
+
def derive(description, text) -> any:
|
136
|
+
result = derive(description, text)
|
137
|
+
if result:
|
138
|
+
logging.info("\n" *3)
|
139
|
+
logging.info(f"Descripción: {description}")
|
140
|
+
logging.info(f"Texto: {text}")
|
141
|
+
logging.info(f"Resultado:")
|
142
|
+
logging.info(json.dumps(result, indent=4))
|
143
|
+
logging.info(f"Esperado:")
|
144
|
+
expected = json.loads(expected)
|
145
|
+
logging.info(json.dumps(expected, indent=4))
|
146
|
+
logging.info("\n" *3)
|
147
|
+
return procesar_datos(description, result)
|
148
|
+
return None, "no pude identificar los datos en el texto proporcionado."
|
@@ -15,6 +15,7 @@
|
|
15
15
|
import re
|
16
16
|
import uuid
|
17
17
|
import json
|
18
|
+
import pickle
|
18
19
|
import logging
|
19
20
|
import traceback
|
20
21
|
from .mas import Adm
|
@@ -656,7 +657,10 @@ class Dialog(ABC):
|
|
656
657
|
logging.debug(iniciador.text)
|
657
658
|
logging.debug("")
|
658
659
|
# Set dialog state
|
659
|
-
self.__dfa['start'] = iniciadores
|
660
|
+
self.__dfa['start'] = iniciadores
|
661
|
+
#filename = f'{self.__role.name}_grafo.pkl'
|
662
|
+
#with open(filename, 'wb') as f:
|
663
|
+
# pickle.dump(grafo, f)
|
660
664
|
|
661
665
|
def load_model(self, provider, config, ai_service=None, substitudes = False) -> None:
|
662
666
|
self.__service_provider, service = define_service_provider(provider, ai_service, substitudes)
|
@@ -877,25 +881,57 @@ class Dialog(ABC):
|
|
877
881
|
caso = celula_casos.derive(self.__ai_service, query, max_tkns=10)
|
878
882
|
consulta = celula_consultas.derive(self.__ai_service, query, max_tkns=10)
|
879
883
|
# Verifica si es un saludo, consulta o caso
|
880
|
-
|
881
|
-
|
882
|
-
|
884
|
+
|
885
|
+
#es_saludo = ("SALUDO" in saludo) and ("NO_PREGUNTA" in consulta) and ("NO_QUEJA_DEMANDA" in caso) and not ("NO_SALUDO" in saludo)
|
886
|
+
#es_consulta = ("PREGUNTA_O_SOLICITUD" in consulta) and ("NO_QUEJA_DEMANDA" in caso) and ("NO_SALUDO" in saludo) and not ("NO_PREGUNTA" in consulta)
|
887
|
+
#es_caso = ("QUEJA_DEMANDA" in caso) and ("NO_PREGUNTA" in consulta) and ("NO_SALUDO" in saludo) and not ("NO_QUEJA_DEMANDA" in caso)
|
888
|
+
|
889
|
+
es_saludo = ("SALUDO" in saludo) and not ("NO_SALUDO" in saludo)
|
890
|
+
es_consulta = ("PREGUNTA_O_SOLICITUD" in consulta) and ("NO_PREGUNTA" in consulta)
|
891
|
+
es_caso = ("QUEJA_DEMANDA" in caso) and ("NO_SALUDO" in saludo)
|
892
|
+
|
893
|
+
|
883
894
|
logging.info("\n------------------- Clase --------------------------")
|
884
895
|
logging.info(f"[Stage-1]: Saludo({saludo}), Consulta({consulta}), Caso({caso})")
|
885
896
|
logging.info(f"[Stage-1]: Es saludo({es_saludo}), Es consulta({es_consulta}), Es caso({es_caso})")
|
886
897
|
logging.info("\n-----------------------------------------------------")
|
898
|
+
|
899
|
+
eva = 0
|
900
|
+
ambiguedad = False
|
901
|
+
eva = 1 if es_saludo else 0
|
902
|
+
eva += 1 if es_consulta else 0
|
903
|
+
eva += 1 if es_caso else 0
|
904
|
+
|
887
905
|
# Verifica los casos
|
888
|
-
if
|
906
|
+
if eva > 0 and eva < 3:
|
889
907
|
logging.info("[Stage-1]: Discriminador encontrado")
|
890
|
-
|
908
|
+
|
909
|
+
# Casos identificables
|
910
|
+
if es_saludo and not es_consulta and not es_caso:
|
891
911
|
dicriminador = "saluda"
|
892
|
-
elif es_consulta:
|
912
|
+
elif es_consulta and not es_saludo and not es_caso:
|
893
913
|
dicriminador = "consulta"
|
894
|
-
|
914
|
+
elif es_caso and not es_saludo and not es_consulta:
|
895
915
|
dicriminador = "caso"
|
916
|
+
|
917
|
+
# Casos ambiguos con saludo
|
918
|
+
elif es_saludo and es_consulta and not es_caso:
|
919
|
+
dicriminador = "consulta"
|
920
|
+
elif es_saludo and es_caso and not es_consulta:
|
921
|
+
dicriminador = "caso"
|
922
|
+
|
923
|
+
# Casos ambiguos con consulta y caso
|
924
|
+
elif es_consulta and es_caso and not es_saludo:
|
925
|
+
res = "Lo lamento, ¿Desea que le ayude con una Consulta o una Demanda?"
|
926
|
+
else:
|
927
|
+
ambiguedad = True
|
928
|
+
|
896
929
|
self.notify(session_id, f"primera fase se identifica: {dicriminador}.")
|
897
930
|
res = query
|
898
931
|
else:
|
932
|
+
ambiguedad = True
|
933
|
+
|
934
|
+
if ambiguedad:
|
899
935
|
logging.info("[Stage-1]: Respuesta con ambiguedad")
|
900
936
|
self.notify(session_id, "identificando ambiguedad...")
|
901
937
|
logging.info("\n\n\n--------------ANALIZER------------------")
|
@@ -909,6 +945,17 @@ class Dialog(ABC):
|
|
909
945
|
|
910
946
|
return dicriminador, res
|
911
947
|
|
948
|
+
def get_node(self, performative):
|
949
|
+
""" Get node method
|
950
|
+
:param performative: performative
|
951
|
+
:return: Node
|
952
|
+
"""
|
953
|
+
if performative in self.__dfa:
|
954
|
+
return self.__dfa[performative]
|
955
|
+
else:
|
956
|
+
logging.error(f"Performativa {performative} no encontrada en el DFA")
|
957
|
+
return None
|
958
|
+
|
912
959
|
def transition(self, session, owner, dialog_state, query, team_source=False) -> str:
|
913
960
|
try:
|
914
961
|
res = ""
|
@@ -78,6 +78,8 @@ pbesa/celulas/celula_expertos.py
|
|
78
78
|
pbesa/celulas/celula_generar_documento.py
|
79
79
|
pbesa/celulas/celula_preguntas.py
|
80
80
|
pbesa/celulas/celula_saludos.py
|
81
|
+
pbesa/celulas/celula_simulador_ciudadano.py
|
82
|
+
pbesa/celulas/data_extraction_cel.py
|
81
83
|
pbesa/celulas/web.py
|
82
84
|
pbesa/kernel/__init__.py
|
83
85
|
pbesa/kernel/adapter.py
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc
RENAMED
File without changes
|
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/helloworld/__pycache__/wsgi.cpython-36.pyc
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/__pycache__/views.cpython-36.pyc
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/worker/translatetask.py
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/django/helloworld/translate/mas/worker/workeragent.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.18 → pbesa-4.0.19}/examples/remote/mas/worker/__pycache__/workeragent.cpython-36.pyc
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|