pbesa 4.0.2__tar.gz → 4.0.3__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.2 → pbesa-4.0.3}/PKG-INFO +1 -1
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/cognitive.py +129 -88
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/dispatcher_team.py +15 -39
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/selected_dispatcher_team.py +13 -10
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/worker.py +39 -10
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa.egg-info/PKG-INFO +1 -1
- {pbesa-4.0.2 → pbesa-4.0.3}/setup.py +1 -1
- {pbesa-4.0.2 → pbesa-4.0.3}/.gitignore +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/LICENSE +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/LICENSE.txt +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/MANIFEST +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/README.md +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/db.sqlite3 +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/settings.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/wsgi.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/asgi.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/pbesa.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/settings.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/urls.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/wsgi.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/manage.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/views.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/admin.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/apps.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translatecontroller.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translatedelegate.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translateresponse.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/translatetask.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/workeragent.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/migrations/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/migrations/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/models.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/tests.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/urls.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/views.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/countercontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/counterdelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/counterresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/countercontroller.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/counterdelegate.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/controller/counterresponse.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/counteragent.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/countertask.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/remote_a.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/remote_b.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/remote_c.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/adapter.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/agent.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/io/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/io/system_file.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/io/tcp_server.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/res/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-37.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-38.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-39.pyc +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/res/conf.json +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/util.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/kernel/world.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/mas.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/models.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/remote/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/remote/adm_listener.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/remote/adm_listener_handler.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/remote/exceptions.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/remote/remote_adm.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/remote/remote_adm_handler.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/__init__.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/collaborative_team.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/delegator.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/delegator_team.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/dialog.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/prompts.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa/social/templates.py +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa.egg-info/SOURCES.txt +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa.egg-info/dependency_links.txt +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa.egg-info/requires.txt +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/pbesa.egg-info/top_level.txt +0 -0
- {pbesa-4.0.2 → pbesa-4.0.3}/setup.cfg +0 -0
@@ -13,7 +13,8 @@
|
|
13
13
|
# Define resources
|
14
14
|
# --------------------------------------------------------
|
15
15
|
|
16
|
-
import
|
16
|
+
import json
|
17
|
+
import logging
|
17
18
|
import traceback
|
18
19
|
from pydantic import BaseModel
|
19
20
|
from typing import List, Optional
|
@@ -263,7 +264,7 @@ class AugmentedGeneration(ABC):
|
|
263
264
|
""" Reset method """
|
264
265
|
self.__work_memory = []
|
265
266
|
# Set up model
|
266
|
-
self.
|
267
|
+
self.setup_world()
|
267
268
|
|
268
269
|
def derive(self, query) -> str:
|
269
270
|
""" Generate method
|
@@ -275,7 +276,7 @@ class AugmentedGeneration(ABC):
|
|
275
276
|
instantane_memory = self.__work_memory.copy()
|
276
277
|
instantane_memory.append({"role": "user", "content": prompt})
|
277
278
|
text = self.__ai_service.generate(instantane_memory)
|
278
|
-
|
279
|
+
logging.info(f"Thought: {text}")
|
279
280
|
if self.__def_tool_dict:
|
280
281
|
tool = self.__def_tool_dict.get(self.__role.tool)
|
281
282
|
if tool:
|
@@ -285,6 +286,10 @@ class AugmentedGeneration(ABC):
|
|
285
286
|
return text
|
286
287
|
except Exception as e:
|
287
288
|
traceback.print_exc()
|
289
|
+
|
290
|
+
logging.info(f"------------RESET---------------")
|
291
|
+
self.reset()
|
292
|
+
|
288
293
|
return "Lo lamento, no puedo responder en este momento"
|
289
294
|
|
290
295
|
def get_role(self) -> Role:
|
@@ -465,9 +470,14 @@ class Dialog(ABC):
|
|
465
470
|
def setup_world(self):
|
466
471
|
""" Set up model method """
|
467
472
|
# Define role
|
468
|
-
self.
|
469
|
-
|
470
|
-
|
473
|
+
instrucciones = f"Instrucciones:\n{self.__role.description}\n Tu tarea: {self.__role.objective}\n"
|
474
|
+
requisitos = f"Requisitos:\n{self.__role.arquetype}\n"
|
475
|
+
ejemplo = f"Ejemplo:\n{self.__role.example}\n"
|
476
|
+
continuar = "Ahora, evalúa el siguiente caso:\n"
|
477
|
+
self.__work_memory.append({"role": "user", "content": instrucciones})
|
478
|
+
self.__work_memory.append({"role": "user", "content": requisitos})
|
479
|
+
self.__work_memory.append({"role": "user", "content": ejemplo})
|
480
|
+
self.__work_memory.append({"role": "user", "content": continuar})
|
471
481
|
|
472
482
|
def get_model(self) -> any:
|
473
483
|
""" Get model method
|
@@ -502,29 +512,29 @@ class Dialog(ABC):
|
|
502
512
|
self.setup_world()
|
503
513
|
interations = agent_metadata.role.interactions
|
504
514
|
grafo = recorrer_interacciones(interations)
|
505
|
-
|
515
|
+
logging.info("")
|
506
516
|
# Si el grafo es una lista de nodos, lo imprimimos cada uno
|
507
517
|
if isinstance(grafo, list):
|
508
518
|
for nodo in grafo:
|
509
519
|
imprimir_grafo(nodo)
|
510
520
|
else:
|
511
521
|
imprimir_grafo(grafo)
|
512
|
-
|
522
|
+
logging.info("")
|
513
523
|
# Ejemplo de uso:
|
514
524
|
self.__dfa = extraer_diccionario_nodos(grafo)
|
515
525
|
# Mostrar el diccionario
|
516
526
|
for clave, valor in self.__dfa.items():
|
517
|
-
|
518
|
-
|
527
|
+
logging.info(f"{clave}: {valor.text}")
|
528
|
+
logging.info("")
|
519
529
|
iniciadores = []
|
520
530
|
for item in interations:
|
521
531
|
for clave, valor in self.__dfa.items():
|
522
532
|
if valor.text == item['texto']:
|
523
533
|
iniciadores.append(valor)
|
524
|
-
|
534
|
+
logging.info("Iniciadores:")
|
525
535
|
for iniciador in iniciadores:
|
526
|
-
|
527
|
-
|
536
|
+
logging.info(iniciador.text)
|
537
|
+
logging.info("")
|
528
538
|
# Set dialog state
|
529
539
|
self.__dfa['start'] = iniciadores
|
530
540
|
|
@@ -544,7 +554,7 @@ class Dialog(ABC):
|
|
544
554
|
""" Reset method """
|
545
555
|
self.__work_memory = []
|
546
556
|
# Set up model
|
547
|
-
self.
|
557
|
+
self.setup_world()
|
548
558
|
|
549
559
|
def team_inquiry(self, team, data, operation, session_flag) -> str:
|
550
560
|
canales = self.state['canales']
|
@@ -559,15 +569,11 @@ class Dialog(ABC):
|
|
559
569
|
}
|
560
570
|
else:
|
561
571
|
if session_flag:
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
# 'text': data,
|
568
|
-
# 'session_id': session_id
|
569
|
-
# },
|
570
|
-
#}
|
572
|
+
logging.info(f"Session flag: {session_flag}")
|
573
|
+
logging.info(f"------------RESET--------------- {data}")
|
574
|
+
self.reset()
|
575
|
+
return data
|
576
|
+
|
571
577
|
else:
|
572
578
|
dto = {
|
573
579
|
"data": {
|
@@ -577,63 +583,75 @@ class Dialog(ABC):
|
|
577
583
|
response = canal.post(team.lower(), dto)
|
578
584
|
if response['status']:
|
579
585
|
return response['message']['response']
|
586
|
+
|
587
|
+
logging.info(f"------------RESET---------------")
|
588
|
+
self.reset()
|
580
589
|
return "Lo lamento, no puedo responder en este momento"
|
581
590
|
|
582
|
-
def get_text(self,
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
messages.append({
|
588
|
-
"Assistant": speaker.capitalize(),
|
589
|
-
"User": text.strip()
|
590
|
-
})
|
591
|
-
if len(messages) > 0:
|
592
|
-
return messages[-1]["Assistant"]
|
593
|
-
else:
|
594
|
-
return messages[-1]["User"]
|
595
|
-
return inputs
|
591
|
+
def get_text(self, mensaje) -> str:
|
592
|
+
mensaje_limpio = mensaje.replace("<|im_start|>user<|im_sep|>", "").replace("<|im_start|>system<|im_sep|>", "")
|
593
|
+
mensaje_limpio = mensaje_limpio.replace("<|im_start|>", "").replace("<|im_sep|>", "").replace("<|im_end|>", "")
|
594
|
+
mensaje_limpio = mensaje_limpio.replace("[Usuario]: ", "").replace("[Sistema]: ", "")
|
595
|
+
return mensaje_limpio.strip()
|
596
596
|
|
597
597
|
def transition(self, owner, dialog_state, query, team_source=False) -> str:
|
598
|
+
logging.info(f"Transition: {owner} -> {dialog_state}, Team: {team_source}, Query: {query}")
|
598
599
|
text = ""
|
600
|
+
|
601
|
+
# Verifica que exista la performativa
|
602
|
+
if not dialog_state in self.__dfa:
|
603
|
+
logging.warning(f"------------Performativa no existe---------------")
|
604
|
+
self.reset()
|
605
|
+
return "Web", DialogState.START, "Lo lamento, no puedo responder en este momento", "Web"
|
606
|
+
|
599
607
|
node = self.__dfa[dialog_state]
|
600
608
|
if not isinstance(node, list):
|
601
609
|
node = node.children
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
610
|
+
|
611
|
+
# Flujo de selección
|
612
|
+
if node and len(node)> 1:
|
613
|
+
logging.info(f"--> Más de una opción.")
|
614
|
+
options = ""
|
615
|
+
cont = 1
|
616
|
+
for item in node:
|
617
|
+
options += f"{cont}) {item.text}\n"
|
618
|
+
cont += 1
|
619
|
+
prompt = CLASSIFICATION_PROMPT % (query, options)
|
620
|
+
logging.info(f"Query: {query},\n Options:\n{options}")
|
621
|
+
self.__meta_work_memory.append({"role": "user", "content": prompt})
|
622
|
+
text = self.__ai_service.generate(self.__meta_work_memory)
|
623
|
+
logging.info(f"Thought: {text}")
|
624
|
+
self.__meta_work_memory = []
|
625
|
+
text = self.get_text(text)
|
626
|
+
select_node = None
|
627
|
+
for option in range(1, cont):
|
628
|
+
if str(option) in text:
|
629
|
+
select_node = node[option-1]
|
630
|
+
logging.info(f"Select node: {select_node.text}")
|
631
|
+
break
|
632
|
+
if not select_node:
|
633
|
+
logging.info("=> No se seleccionó ninguna opción")
|
634
|
+
logging.info(f"=> Node: {node}")
|
635
|
+
logging.info(f"=> len node: {len(node)}")
|
624
636
|
select_node = node[0]
|
625
|
-
|
626
|
-
|
627
|
-
|
637
|
+
logging.info(f"=> Selecciona el primer nodo: {select_node.text}")
|
638
|
+
elif node and len(node) == 1:
|
639
|
+
logging.info(f"--> Una opción.")
|
640
|
+
select_node = node[0]
|
641
|
+
else:
|
642
|
+
logging.info(f"------------RESET---------------")
|
643
|
+
self.reset()
|
644
|
+
logging.info(f"???> text: {text} es terminal")
|
628
645
|
text = self.get_text(text)
|
629
646
|
return owner, DialogState.START, text, owner
|
630
|
-
|
647
|
+
|
648
|
+
# Flujo normal
|
649
|
+
logging.info(f"Flujo normal: {select_node.text}")
|
631
650
|
if team_source:
|
632
651
|
self.__work_memory.append({"role": "user", "content": select_node.text})
|
633
652
|
else:
|
634
653
|
self.__work_memory.append({"role": "user", "content": query})
|
635
654
|
self.__work_memory.append({"role": "user", "content": select_node.text})
|
636
|
-
|
637
655
|
new_owner, new_dialog_state, text, team = self.do_transition(owner, select_node.children[0], query)
|
638
656
|
text = self.get_text(text)
|
639
657
|
return new_owner, new_dialog_state, text, team
|
@@ -643,7 +661,7 @@ class Dialog(ABC):
|
|
643
661
|
:return: str
|
644
662
|
"""
|
645
663
|
if isinstance(node, DeclarativeNode):
|
646
|
-
|
664
|
+
logging.info(f"D -> node: {node.text}")
|
647
665
|
self.__work_memory.append({"role": "user", "content": node.text})
|
648
666
|
elif isinstance(node, ActionNode):
|
649
667
|
|
@@ -651,76 +669,99 @@ class Dialog(ABC):
|
|
651
669
|
# Accion
|
652
670
|
#------------------------------
|
653
671
|
|
654
|
-
|
672
|
+
logging.info(f"-> node action: {node.action}")
|
655
673
|
if node.tool and not node.tool == "Ninguno":
|
656
|
-
|
657
|
-
self.__work_memory.append({"role": "user", "content": node.text})
|
674
|
+
logging.info(f"-> node tool: {node.tool}")
|
675
|
+
self.__work_memory.append({"role": "user", "content": node.text})
|
676
|
+
logging.info("-----")
|
677
|
+
logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
|
678
|
+
logging.info("-----")
|
658
679
|
res = self.__ai_service.generate(self.__work_memory)
|
659
|
-
|
680
|
+
logging.info(f"-> node tool: {res}")
|
681
|
+
res = self.get_text(res)
|
660
682
|
# Check if res is empty
|
661
683
|
if not res or res == "":
|
684
|
+
logging.info("1 -> res vacio")
|
662
685
|
res = "Lo lamento, no puedo responder en este momento"
|
663
|
-
return owner, DialogState.START, res, owner
|
664
686
|
|
665
|
-
|
687
|
+
logging.info(f"------------RESET---------------")
|
688
|
+
self.reset()
|
666
689
|
|
690
|
+
return owner, DialogState.START, res, owner
|
691
|
+
logging.info(f"-> node tool: envia -> {res}")
|
667
692
|
text = self.team_inquiry(node.team, res, node.tool, False)
|
668
693
|
else:
|
669
|
-
|
670
694
|
#------------------------------
|
671
695
|
# Lllamada
|
672
696
|
#------------------------------
|
673
|
-
|
674
|
-
print("-> node team:", node.team)
|
697
|
+
logging.info(f"-> node team: {node.team}")
|
675
698
|
# Verifica si el nodo es termianl ya que significa
|
676
699
|
# que el dialogo cambia de agente
|
677
700
|
if node.is_terminal:
|
678
|
-
|
701
|
+
logging.info(f"-> node team -> es terminal -> {node.text}")
|
679
702
|
self.__work_memory.append({"role": "user", "content": node.text})
|
703
|
+
logging.info("-----")
|
704
|
+
logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
|
705
|
+
logging.info("-----")
|
680
706
|
res = self.__ai_service.generate(self.__work_memory)
|
681
707
|
res = self.get_text(res)
|
682
708
|
self.__work_memory.append({"role": "system", "content": res})
|
683
|
-
|
684
709
|
# Check if res is empty
|
685
710
|
if not res or res == "":
|
711
|
+
logging.info("2 -> res vacio")
|
686
712
|
res = "Lo lamento, no puedo responder en este momento"
|
713
|
+
logging.info(f"------------RESET---------------")
|
714
|
+
self.reset()
|
687
715
|
return owner, DialogState.START, res, owner
|
688
|
-
|
689
|
-
|
690
|
-
#text = self.team_inquiry(node.team, res, None, True)
|
716
|
+
logging.info(f"-> node team -> envia: {res}")
|
717
|
+
text = self.team_inquiry(node.team, res, None, True)
|
691
718
|
return node.team, DialogState.START, res, node.team
|
692
719
|
else:
|
693
|
-
|
720
|
+
logging.info("-> node team -> continua")
|
694
721
|
self.__work_memory.append({"role": "user", "content": node.text})
|
695
|
-
|
722
|
+
logging.info(f"-> node team -> envia: {query}")
|
696
723
|
text = self.team_inquiry(node.team, query, node.tool, False)
|
697
|
-
|
724
|
+
logging.info(f"-> node team -> text: {text}")
|
698
725
|
self.__deep_count += 1
|
699
726
|
if self.__deep_count < self.__deep_limit:
|
700
727
|
return self.transition(owner, node.performative, text, True)
|
701
728
|
else:
|
702
729
|
self.__deep_count = 0
|
730
|
+
logging.info("-> node team -> deep limit")
|
731
|
+
|
732
|
+
logging.info(f"------------RESET---------------")
|
733
|
+
self.reset()
|
734
|
+
|
703
735
|
return "Web", DialogState.START, "Lo lamento me he perdido, ¿podrías repetir la pregunta?"
|
704
736
|
else:
|
705
|
-
|
737
|
+
logging.info(f"!!!!!!!!!!!!!!!!!!!!!!!> Otro tipo de nodo: {node.text}")
|
706
738
|
|
739
|
+
logging.info(f"=> !!!!: {query}")
|
740
|
+
logging.info("-----")
|
741
|
+
logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
|
742
|
+
logging.info("-----")
|
707
743
|
res = self.__ai_service.generate(self.__work_memory)
|
744
|
+
logging.info(f"=> res: {res}")
|
708
745
|
res = self.get_text(res)
|
709
746
|
self.__work_memory.append({"role": "system", "content": res})
|
710
|
-
|
711
747
|
# Check if res is empty
|
712
748
|
if not res or res == "":
|
749
|
+
logging.info("3 -> res vacio")
|
750
|
+
|
751
|
+
logging.info(f"------------RESET---------------")
|
752
|
+
self.reset()
|
753
|
+
|
713
754
|
res = "Lo lamento, no puedo responder en este momento"
|
714
755
|
return owner, DialogState.START, res, owner
|
715
756
|
|
716
|
-
|
757
|
+
logging.info(f"=> Thought DEEP: {res}")
|
717
758
|
|
718
759
|
new_dialog_state = node.performative
|
719
760
|
if not node.is_terminal:
|
720
|
-
|
761
|
+
logging.info(f"=> new_owner: {owner} new_dialog_state: {new_dialog_state}")
|
721
762
|
return owner, new_dialog_state, res, owner
|
722
763
|
|
723
|
-
|
764
|
+
logging.info(f"Tipe node: {type(node)}")
|
724
765
|
|
725
|
-
|
766
|
+
logging.info(f"$$$> new_owner: {owner} new_dialog_state: {new_dialog_state}")
|
726
767
|
return owner, new_dialog_state, res, owner
|
@@ -33,8 +33,8 @@ operate in an agile and effective manner.
|
|
33
33
|
# Define resources
|
34
34
|
# --------------------------------------------------------
|
35
35
|
|
36
|
+
import logging
|
36
37
|
from abc import abstractmethod
|
37
|
-
|
38
38
|
from .worker import Task, Worker
|
39
39
|
from ..kernel.agent import Queue
|
40
40
|
from ..kernel.agent import Agent
|
@@ -56,54 +56,28 @@ class DispatcherException(Exception):
|
|
56
56
|
class Delegate(Action):
|
57
57
|
""" An action is a response to the occurrence of an event """
|
58
58
|
|
59
|
-
def
|
60
|
-
"""
|
61
|
-
|
62
|
-
@param data Event data
|
59
|
+
def active_timeout(self, ag, time: int) -> None:
|
60
|
+
""" Active timeout
|
61
|
+
@param time: Time
|
63
62
|
"""
|
64
|
-
|
65
|
-
self.
|
66
|
-
'gateway': data['gateway'],
|
67
|
-
'dtoList': []
|
68
|
-
}
|
69
|
-
self.adm.send_event(ag, 'task', data['dto'])
|
70
|
-
|
71
|
-
# --------------------------------------------------------
|
72
|
-
# Define DelegateAction
|
73
|
-
# --------------------------------------------------------
|
74
|
-
|
75
|
-
class DelegateAction(Action):
|
76
|
-
""" An action is a response to the occurrence of an event """
|
63
|
+
logging.info(f"[Delegate] Send event timeout {time}")
|
64
|
+
self.adm.send_event(ag, 'timeout', {'time': time, 'command': 'start'})
|
77
65
|
|
78
66
|
def execute(self, data: any) -> None:
|
79
67
|
"""
|
80
68
|
Response.
|
81
69
|
@param data Event data
|
82
70
|
"""
|
83
|
-
self.delegate(data)
|
84
|
-
|
85
|
-
def active_timeout(self, time: int) -> None:
|
86
|
-
""" Active timeout
|
87
|
-
@param time: Time
|
88
|
-
"""
|
89
|
-
self.adm.send_event(self.agent.id, 'timeout', {'time': time, 'dto': None})
|
90
|
-
|
91
|
-
def to_assign(self, data: any) -> None:
|
92
|
-
""" Assign
|
93
|
-
@param data: Data
|
94
|
-
"""
|
95
71
|
ag = self.agent.get_free_queue().get()
|
96
72
|
self.agent.get_request_dict()[ag] = {
|
73
|
+
'gateway': data['gateway'],
|
97
74
|
'dtoList': []
|
98
75
|
}
|
99
|
-
self.adm.send_event(ag, 'task', data)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
@param data: Data
|
105
|
-
"""
|
106
|
-
pass
|
76
|
+
self.adm.send_event(ag, 'task', data['dto'])
|
77
|
+
if 'timeout' in self.agent.state:
|
78
|
+
self.active_timeout(ag, self.agent.state['timeout'])
|
79
|
+
else:
|
80
|
+
raise DispatcherException('[Delegate]: Timeout not defined in the state as "timeout" key')
|
107
81
|
|
108
82
|
# --------------------------------------------------------
|
109
83
|
# Define Action
|
@@ -141,11 +115,13 @@ class ResponseAction(Action):
|
|
141
115
|
"""
|
142
116
|
request = self.agent.get_request_dict()[data['source']]
|
143
117
|
if 'timeout' in data:
|
144
|
-
self.
|
118
|
+
logging.info(f"[ResponseAction][{self.agent.id}]: Timeout ******************")
|
119
|
+
request['gateway'].put("TIMEOUT")
|
145
120
|
else:
|
146
121
|
request['dtoList'].append(data['result'])
|
147
122
|
if len(request['dtoList']) >= self.agent.get_buffer_size():
|
148
123
|
self.send_response(request)
|
124
|
+
self.adm.send_event(data['source'], 'timeout', {'command': 'stop'})
|
149
125
|
|
150
126
|
# --------------------------------------------------------
|
151
127
|
# Define component
|
@@ -34,16 +34,14 @@ operate in an agile and effective manner.
|
|
34
34
|
# Define resources
|
35
35
|
# --------------------------------------------------------
|
36
36
|
|
37
|
+
import logging
|
37
38
|
from abc import abstractmethod
|
38
|
-
|
39
|
-
from pbesa.cognitive import AugmentedGeneration, Dialog
|
40
|
-
from pbesa.mas import Directory
|
41
|
-
|
42
39
|
from .worker import Task, Worker
|
43
40
|
from ..kernel.agent import Queue
|
44
41
|
from ..kernel.agent import Agent
|
45
42
|
from ..kernel.agent import Action
|
46
43
|
from ..kernel.util import generate_short_uuid
|
44
|
+
from pbesa.cognitive import AugmentedGeneration, Dialog
|
47
45
|
|
48
46
|
# ----------------------------------------------------------
|
49
47
|
# Defines system component exceptions
|
@@ -82,19 +80,22 @@ class DelegateAction(Action):
|
|
82
80
|
""" Assign
|
83
81
|
@param data: Data
|
84
82
|
"""
|
85
|
-
|
83
|
+
logging.info('Assign to agent...')
|
86
84
|
ag = self.agent.get_free_queue().get()
|
87
85
|
agent_obj = self.adm.get_agent(ag)
|
88
|
-
agent_count = len(self.agent.get_agent_list())
|
86
|
+
agent_count = len(self.agent.get_agent_list())
|
87
|
+
logging.info('List of agents: ' + str(self.agent.get_agent_list()))
|
89
88
|
if operation:
|
90
|
-
|
89
|
+
logging.info(f'With operation {operation}')
|
91
90
|
exit = False
|
92
91
|
while not exit:
|
93
92
|
# Chec if the agent is instance of AugmentedGeneration
|
94
93
|
if isinstance(agent_obj, AugmentedGeneration) or isinstance(agent_obj, Dialog):
|
95
94
|
# Get the role
|
96
95
|
role = agent_obj.get_role()
|
96
|
+
logging.info(f"Comparing {role.tool} with {operation}")
|
97
97
|
if role.tool == operation:
|
98
|
+
logging.info('The agent is operational')
|
98
99
|
self.agent.get_request_dict()[ag] = {
|
99
100
|
'gateway': data['gateway'],
|
100
101
|
'dtoList': []
|
@@ -103,25 +104,27 @@ class DelegateAction(Action):
|
|
103
104
|
self.__rewier[ag] = 0
|
104
105
|
exit = True
|
105
106
|
else:
|
106
|
-
|
107
|
+
logging.info('The agent is not available')
|
107
108
|
self.adm.send_event(agent_obj.get_controller(), 'notify', ag)
|
108
109
|
if ag in self.__rewier:
|
109
110
|
self.__rewier[ag] = self.__rewier[ag] + 1
|
110
111
|
else:
|
111
112
|
self.__rewier[ag] = 0
|
112
113
|
if self.__rewier[ag] >= agent_count * 3:
|
114
|
+
data['gateway'].put('ERROR')
|
113
115
|
raise SelectedDispatcherException('[Error, toAssign]: The agent is not available')
|
114
116
|
else:
|
115
|
-
|
117
|
+
logging.info('The agent is operational')
|
116
118
|
self.adm.send_event(agent_obj.get_controller(), 'notify', ag)
|
117
119
|
if ag in self.__rewier:
|
118
120
|
self.__rewier[ag] = self.__rewier[ag] + 1
|
119
121
|
else:
|
120
122
|
self.__rewier[ag] = 0
|
121
123
|
if self.__rewier[ag] >= agent_count * 3:
|
124
|
+
data['gateway'].put('ERROR')
|
122
125
|
raise SelectedDispatcherException('[Error, toAssign]: The agent is not available')
|
123
126
|
else:
|
124
|
-
|
127
|
+
logging.info('Without operation')
|
125
128
|
self.agent.get_request_dict()[ag] = {
|
126
129
|
'gateway': data['gateway'],
|
127
130
|
'dtoList': []
|
@@ -13,6 +13,7 @@
|
|
13
13
|
# Define resources
|
14
14
|
# --------------------------------------------------------
|
15
15
|
|
16
|
+
import logging
|
16
17
|
from threading import Timer
|
17
18
|
from abc import abstractmethod
|
18
19
|
from ..kernel.agent import Agent
|
@@ -35,24 +36,39 @@ class WorkerException(Exception):
|
|
35
36
|
# ----------------------------------------------------------
|
36
37
|
|
37
38
|
class TimeoutAction(Action):
|
38
|
-
"""
|
39
|
-
|
40
|
-
|
39
|
+
""" Represents the action that manages the timeout """
|
40
|
+
|
41
|
+
def __init__(self) -> None:
|
42
|
+
""" Constructor """
|
43
|
+
self.__timer = None
|
44
|
+
super().__init__()
|
41
45
|
|
42
46
|
def handler(self) -> None:
|
43
47
|
""" Timeout handler """
|
44
48
|
if self.agent.is_timeout():
|
45
49
|
self.agent.set_timeout(False)
|
46
|
-
|
50
|
+
response = {
|
51
|
+
'timeout': True,
|
52
|
+
'source': self.agent.id
|
53
|
+
}
|
54
|
+
self.adm.send_event(self.agent.get_controller(), 'response', response)
|
47
55
|
|
48
56
|
def execute(self, data:any) -> None:
|
49
|
-
""" Execute
|
50
|
-
@param data:
|
57
|
+
""" Execute the action
|
58
|
+
@param data: Event data
|
51
59
|
"""
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
logging.info(f"[TimeoutAction][{self.agent.id}]: Execute {data}")
|
61
|
+
if data['command'] == 'start':
|
62
|
+
if not self.agent.is_timeout():
|
63
|
+
self.agent.set_timeout(True)
|
64
|
+
self.__timer = Timer(data['time'], self.handler)
|
65
|
+
self.__timer.start()
|
66
|
+
logging.info(f"[TimeoutAction][{self.agent.id}]: Timer started")
|
67
|
+
else:
|
68
|
+
if self.__timer:
|
69
|
+
self.__timer.cancel()
|
70
|
+
self.__timer = None
|
71
|
+
logging.info(f"[TimeoutAction][{self.agent.id}]: Timer stopped")
|
56
72
|
|
57
73
|
# --------------------------------------------------------
|
58
74
|
# Define Task Action
|
@@ -126,6 +142,7 @@ class Worker(Agent):
|
|
126
142
|
@param agent_id: Agent ID
|
127
143
|
"""
|
128
144
|
self.__task_list = []
|
145
|
+
self.__timeout = False
|
129
146
|
self.__controller = None
|
130
147
|
self.__controller_type = None
|
131
148
|
super().__init__(agent_id)
|
@@ -158,6 +175,18 @@ class Worker(Agent):
|
|
158
175
|
action.set_is_pool(False)
|
159
176
|
action.set_enable_response(True)
|
160
177
|
|
178
|
+
def is_timeout(self) -> bool:
|
179
|
+
""" Check if the controller has a timeout
|
180
|
+
@return: True if the controller has a timeout, False otherwise
|
181
|
+
"""
|
182
|
+
return self.__timeout
|
183
|
+
|
184
|
+
def set_timeout(self, timeout:bool) -> None:
|
185
|
+
""" Set timeout
|
186
|
+
@param timeout: Timeout
|
187
|
+
"""
|
188
|
+
self.__timeout = timeout
|
189
|
+
|
161
190
|
@abstractmethod
|
162
191
|
def build(self) -> None:
|
163
192
|
""" Build """
|
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.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc
RENAMED
File without changes
|
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/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
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/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
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translatedelegate.py
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translateresponse.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/translatetask.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
|
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.2 → pbesa-4.0.3}/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
|