pbesa 4.0.1__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.
Files changed (103) hide show
  1. {pbesa-4.0.1 → pbesa-4.0.3}/PKG-INFO +1 -1
  2. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/cognitive.py +140 -78
  3. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/dialog.py +12 -11
  4. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/dispatcher_team.py +15 -39
  5. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/selected_dispatcher_team.py +13 -10
  6. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/worker.py +39 -10
  7. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa.egg-info/PKG-INFO +1 -1
  8. {pbesa-4.0.1 → pbesa-4.0.3}/setup.py +1 -1
  9. {pbesa-4.0.1 → pbesa-4.0.3}/.gitignore +0 -0
  10. {pbesa-4.0.1 → pbesa-4.0.3}/LICENSE +0 -0
  11. {pbesa-4.0.1 → pbesa-4.0.3}/LICENSE.txt +0 -0
  12. {pbesa-4.0.1 → pbesa-4.0.3}/MANIFEST +0 -0
  13. {pbesa-4.0.1 → pbesa-4.0.3}/README.md +0 -0
  14. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/db.sqlite3 +0 -0
  15. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__init__.py +0 -0
  16. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/__init__.cpython-36.pyc +0 -0
  17. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc +0 -0
  18. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/settings.cpython-36.pyc +0 -0
  19. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc +0 -0
  20. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/__pycache__/wsgi.cpython-36.pyc +0 -0
  21. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/asgi.py +0 -0
  22. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/pbesa.py +0 -0
  23. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/settings.py +0 -0
  24. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/urls.py +0 -0
  25. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/helloworld/wsgi.py +0 -0
  26. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/manage.py +0 -0
  27. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__init__.py +0 -0
  28. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc +0 -0
  29. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc +0 -0
  30. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc +0 -0
  31. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc +0 -0
  32. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc +0 -0
  33. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/__pycache__/views.cpython-36.pyc +0 -0
  34. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/admin.py +0 -0
  35. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/apps.py +0 -0
  36. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
  37. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
  38. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
  39. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translatecontroller.py +0 -0
  40. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translatedelegate.py +0 -0
  41. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/controller/translateresponse.py +0 -0
  42. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
  43. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
  44. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/translatetask.py +0 -0
  45. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/mas/worker/workeragent.py +0 -0
  46. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/migrations/__init__.py +0 -0
  47. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/migrations/__pycache__/__init__.cpython-36.pyc +0 -0
  48. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/models.py +0 -0
  49. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/tests.py +0 -0
  50. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/urls.py +0 -0
  51. {pbesa-4.0.1 → pbesa-4.0.3}/examples/django/helloworld/translate/views.py +0 -0
  52. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/countercontroller.cpython-36.pyc +0 -0
  53. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/counterdelegate.cpython-36.pyc +0 -0
  54. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/counterresponse.cpython-36.pyc +0 -0
  55. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
  56. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
  57. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
  58. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/countercontroller.py +0 -0
  59. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/counterdelegate.py +0 -0
  60. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/controller/counterresponse.py +0 -0
  61. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc +0 -0
  62. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc +0 -0
  63. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
  64. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
  65. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/worker/counteragent.py +0 -0
  66. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/mas/worker/countertask.py +0 -0
  67. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/remote_a.py +0 -0
  68. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/remote_b.py +0 -0
  69. {pbesa-4.0.1 → pbesa-4.0.3}/examples/remote/remote_c.py +0 -0
  70. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/__init__.py +0 -0
  71. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/__init__.py +0 -0
  72. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/adapter.py +0 -0
  73. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/agent.py +0 -0
  74. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/io/__init__.py +0 -0
  75. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/io/system_file.py +0 -0
  76. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/io/tcp_server.py +0 -0
  77. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/res/__init__.py +0 -0
  78. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-36.pyc +0 -0
  79. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-37.pyc +0 -0
  80. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-38.pyc +0 -0
  81. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/res/__pycache__/__init__.cpython-39.pyc +0 -0
  82. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/res/conf.json +0 -0
  83. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/util.py +0 -0
  84. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/kernel/world.py +0 -0
  85. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/mas.py +0 -0
  86. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/models.py +0 -0
  87. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/remote/__init__.py +0 -0
  88. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/remote/adm_listener.py +0 -0
  89. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/remote/adm_listener_handler.py +0 -0
  90. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/remote/exceptions.py +0 -0
  91. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/remote/remote_adm.py +0 -0
  92. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/remote/remote_adm_handler.py +0 -0
  93. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/__init__.py +0 -0
  94. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/collaborative_team.py +0 -0
  95. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/delegator.py +0 -0
  96. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/delegator_team.py +0 -0
  97. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/prompts.py +0 -0
  98. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa/social/templates.py +0 -0
  99. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa.egg-info/SOURCES.txt +0 -0
  100. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa.egg-info/dependency_links.txt +0 -0
  101. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa.egg-info/requires.txt +0 -0
  102. {pbesa-4.0.1 → pbesa-4.0.3}/pbesa.egg-info/top_level.txt +0 -0
  103. {pbesa-4.0.1 → pbesa-4.0.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pbesa
3
- Version: 4.0.1
3
+ Version: 4.0.3
4
4
  License-File: LICENSE
5
5
  License-File: LICENSE.txt
6
6
  Requires-Dist: pymongo==4.6.3
@@ -13,6 +13,8 @@
13
13
  # Define resources
14
14
  # --------------------------------------------------------
15
15
 
16
+ import json
17
+ import logging
16
18
  import traceback
17
19
  from pydantic import BaseModel
18
20
  from typing import List, Optional
@@ -262,7 +264,7 @@ class AugmentedGeneration(ABC):
262
264
  """ Reset method """
263
265
  self.__work_memory = []
264
266
  # Set up model
265
- self.set_up_model()
267
+ self.setup_world()
266
268
 
267
269
  def derive(self, query) -> str:
268
270
  """ Generate method
@@ -274,7 +276,7 @@ class AugmentedGeneration(ABC):
274
276
  instantane_memory = self.__work_memory.copy()
275
277
  instantane_memory.append({"role": "user", "content": prompt})
276
278
  text = self.__ai_service.generate(instantane_memory)
277
- print("Pensamiento:", text)
279
+ logging.info(f"Thought: {text}")
278
280
  if self.__def_tool_dict:
279
281
  tool = self.__def_tool_dict.get(self.__role.tool)
280
282
  if tool:
@@ -284,6 +286,10 @@ class AugmentedGeneration(ABC):
284
286
  return text
285
287
  except Exception as e:
286
288
  traceback.print_exc()
289
+
290
+ logging.info(f"------------RESET---------------")
291
+ self.reset()
292
+
287
293
  return "Lo lamento, no puedo responder en este momento"
288
294
 
289
295
  def get_role(self) -> Role:
@@ -464,9 +470,14 @@ class Dialog(ABC):
464
470
  def setup_world(self):
465
471
  """ Set up model method """
466
472
  # Define role
467
- self.__work_memory.append({"role": "user", "content": self.__role.objective})
468
- self.__work_memory.append({"role": "user", "content": self.__role.arquetype})
469
- self.__work_memory.append({"role": "user", "content": self.__role.example})
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})
470
481
 
471
482
  def get_model(self) -> any:
472
483
  """ Get model method
@@ -501,29 +512,29 @@ class Dialog(ABC):
501
512
  self.setup_world()
502
513
  interations = agent_metadata.role.interactions
503
514
  grafo = recorrer_interacciones(interations)
504
- print("")
515
+ logging.info("")
505
516
  # Si el grafo es una lista de nodos, lo imprimimos cada uno
506
517
  if isinstance(grafo, list):
507
518
  for nodo in grafo:
508
519
  imprimir_grafo(nodo)
509
520
  else:
510
521
  imprimir_grafo(grafo)
511
- print("")
522
+ logging.info("")
512
523
  # Ejemplo de uso:
513
524
  self.__dfa = extraer_diccionario_nodos(grafo)
514
525
  # Mostrar el diccionario
515
526
  for clave, valor in self.__dfa.items():
516
- print(f"{clave}: {valor.text}")
517
- print("")
527
+ logging.info(f"{clave}: {valor.text}")
528
+ logging.info("")
518
529
  iniciadores = []
519
530
  for item in interations:
520
531
  for clave, valor in self.__dfa.items():
521
532
  if valor.text == item['texto']:
522
533
  iniciadores.append(valor)
523
- print("Iniciadores:")
534
+ logging.info("Iniciadores:")
524
535
  for iniciador in iniciadores:
525
- print(iniciador.text)
526
- print("")
536
+ logging.info(iniciador.text)
537
+ logging.info("")
527
538
  # Set dialog state
528
539
  self.__dfa['start'] = iniciadores
529
540
 
@@ -543,7 +554,7 @@ class Dialog(ABC):
543
554
  """ Reset method """
544
555
  self.__work_memory = []
545
556
  # Set up model
546
- self.set_up_model()
557
+ self.setup_world()
547
558
 
548
559
  def team_inquiry(self, team, data, operation, session_flag) -> str:
549
560
  canales = self.state['canales']
@@ -558,15 +569,11 @@ class Dialog(ABC):
558
569
  }
559
570
  else:
560
571
  if session_flag:
561
- pass
562
- #session_id = self.state['session_id']
563
- #print("=> session_flag -> " + session_id)
564
- #dto = {
565
- # "data": {
566
- # 'text': data,
567
- # 'session_id': session_id
568
- # },
569
- #}
572
+ logging.info(f"Session flag: {session_flag}")
573
+ logging.info(f"------------RESET--------------- {data}")
574
+ self.reset()
575
+ return data
576
+
570
577
  else:
571
578
  dto = {
572
579
  "data": {
@@ -576,48 +583,77 @@ class Dialog(ABC):
576
583
  response = canal.post(team.lower(), dto)
577
584
  if response['status']:
578
585
  return response['message']['response']
586
+
587
+ logging.info(f"------------RESET---------------")
588
+ self.reset()
579
589
  return "Lo lamento, no puedo responder en este momento"
590
+
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()
580
596
 
581
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}")
582
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
+
583
607
  node = self.__dfa[dialog_state]
584
608
  if not isinstance(node, list):
585
609
  node = node.children
586
- options = ""
587
- cont = 1
588
- for item in node:
589
- options += f"{cont}) {item.text}\n"
590
- cont += 1
591
- prompt = CLASSIFICATION_PROMPT % (query, options)
592
- print("Query:", query, "\n", "Options:", options)
593
- self.__meta_work_memory.append({"role": "user", "content": prompt})
594
- text = self.__ai_service.generate(self.__meta_work_memory)
595
- self.__meta_work_memory = []
596
- print("Pensamiento:", text)
597
-
598
- select_node = None
599
- for option in range(1, cont):
600
- if str(option) in text:
601
- select_node = node[option-1]
602
- break
603
- if not select_node:
604
- print("=> No se seleccionó ninguna opción")
605
- print("=> Node:", node)
606
- print("=> len node:", len(node))
607
- if node and len(node)> 0:
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)}")
608
636
  select_node = node[0]
609
- print(select_node.text)
610
- text = "Lo lamento, no puedo responder en este momento"
611
- print("???> text:", text)
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")
645
+ text = self.get_text(text)
612
646
  return owner, DialogState.START, text, owner
613
-
647
+
648
+ # Flujo normal
649
+ logging.info(f"Flujo normal: {select_node.text}")
614
650
  if team_source:
615
- self.__work_memory.append({"role": "system", "content": select_node.text})
651
+ self.__work_memory.append({"role": "user", "content": select_node.text})
616
652
  else:
617
653
  self.__work_memory.append({"role": "user", "content": query})
618
- self.__work_memory.append({"role": "system", "content": select_node.text})
619
-
654
+ self.__work_memory.append({"role": "user", "content": select_node.text})
620
655
  new_owner, new_dialog_state, text, team = self.do_transition(owner, select_node.children[0], query)
656
+ text = self.get_text(text)
621
657
  return new_owner, new_dialog_state, text, team
622
658
 
623
659
  def do_transition(self, owner, node, query) -> str:
@@ -625,81 +661,107 @@ class Dialog(ABC):
625
661
  :return: str
626
662
  """
627
663
  if isinstance(node, DeclarativeNode):
628
- print("-> node:", node.text)
629
- self.__work_memory.append({"role": "system", "content": node.text})
664
+ logging.info(f"D -> node: {node.text}")
665
+ self.__work_memory.append({"role": "user", "content": node.text})
630
666
  elif isinstance(node, ActionNode):
631
667
 
632
668
  #------------------------------
633
669
  # Accion
634
670
  #------------------------------
635
671
 
636
- print("-> node action:", node.action)
672
+ logging.info(f"-> node action: {node.action}")
637
673
  if node.tool and not node.tool == "Ninguno":
638
- print("-> node tool:", node.tool)
639
- self.__work_memory.append({"role": "system", "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("-----")
640
679
  res = self.__ai_service.generate(self.__work_memory)
641
-
680
+ logging.info(f"-> node tool: {res}")
681
+ res = self.get_text(res)
642
682
  # Check if res is empty
643
683
  if not res or res == "":
684
+ logging.info("1 -> res vacio")
644
685
  res = "Lo lamento, no puedo responder en este momento"
645
- return owner, DialogState.START, res, owner
646
686
 
647
- print("-> node tool: envia", res)
687
+ logging.info(f"------------RESET---------------")
688
+ self.reset()
648
689
 
690
+ return owner, DialogState.START, res, owner
691
+ logging.info(f"-> node tool: envia -> {res}")
649
692
  text = self.team_inquiry(node.team, res, node.tool, False)
650
693
  else:
651
-
652
694
  #------------------------------
653
695
  # Lllamada
654
696
  #------------------------------
655
-
656
- print("-> node team:", node.team)
697
+ logging.info(f"-> node team: {node.team}")
657
698
  # Verifica si el nodo es termianl ya que significa
658
699
  # que el dialogo cambia de agente
659
700
  if node.is_terminal:
660
- print("-> node team -> es terminal -> " + node.text)
661
- self.__work_memory.append({"role": "system", "content": node.text})
701
+ logging.info(f"-> node team -> es terminal -> {node.text}")
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("-----")
662
706
  res = self.__ai_service.generate(self.__work_memory)
663
-
707
+ res = self.get_text(res)
708
+ self.__work_memory.append({"role": "system", "content": res})
664
709
  # Check if res is empty
665
710
  if not res or res == "":
711
+ logging.info("2 -> res vacio")
666
712
  res = "Lo lamento, no puedo responder en este momento"
713
+ logging.info(f"------------RESET---------------")
714
+ self.reset()
667
715
  return owner, DialogState.START, res, owner
668
-
669
- print("-> node team -> envia:", res)
670
- #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)
671
718
  return node.team, DialogState.START, res, node.team
672
719
  else:
673
- print("-> node team -> continua")
674
- self.__work_memory.append({"role": "system", "content": node.text})
675
- print("-> node team -> envia:", query)
720
+ logging.info("-> node team -> continua")
721
+ self.__work_memory.append({"role": "user", "content": node.text})
722
+ logging.info(f"-> node team -> envia: {query}")
676
723
  text = self.team_inquiry(node.team, query, node.tool, False)
677
-
724
+ logging.info(f"-> node team -> text: {text}")
678
725
  self.__deep_count += 1
679
726
  if self.__deep_count < self.__deep_limit:
680
727
  return self.transition(owner, node.performative, text, True)
681
728
  else:
682
729
  self.__deep_count = 0
730
+ logging.info("-> node team -> deep limit")
731
+
732
+ logging.info(f"------------RESET---------------")
733
+ self.reset()
734
+
683
735
  return "Web", DialogState.START, "Lo lamento me he perdido, ¿podrías repetir la pregunta?"
684
736
  else:
685
- print("!!!!!!!!!!!!!!!!!!!!!!!> Otro tipo de nodo:", node.text)
737
+ logging.info(f"!!!!!!!!!!!!!!!!!!!!!!!> Otro tipo de nodo: {node.text}")
686
738
 
739
+ logging.info(f"=> !!!!: {query}")
740
+ logging.info("-----")
741
+ logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
742
+ logging.info("-----")
687
743
  res = self.__ai_service.generate(self.__work_memory)
744
+ logging.info(f"=> res: {res}")
745
+ res = self.get_text(res)
688
746
  self.__work_memory.append({"role": "system", "content": res})
689
-
690
747
  # Check if res is empty
691
748
  if not res or res == "":
749
+ logging.info("3 -> res vacio")
750
+
751
+ logging.info(f"------------RESET---------------")
752
+ self.reset()
753
+
692
754
  res = "Lo lamento, no puedo responder en este momento"
693
755
  return owner, DialogState.START, res, owner
694
756
 
695
- print("=> Pensamiento DEEP:", res)
757
+ logging.info(f"=> Thought DEEP: {res}")
696
758
 
697
759
  new_dialog_state = node.performative
698
760
  if not node.is_terminal:
699
- print("=> new_owner:", owner, "new_dialog_state:", new_dialog_state)
761
+ logging.info(f"=> new_owner: {owner} new_dialog_state: {new_dialog_state}")
700
762
  return owner, new_dialog_state, res, owner
701
763
 
702
- print(f"Tipe node: {type(node)}")
764
+ logging.info(f"Tipe node: {type(node)}")
703
765
 
704
- print("$$$> new_owner:", owner, "new_dialog_state:", new_dialog_state)
766
+ logging.info(f"$$$> new_owner: {owner} new_dialog_state: {new_dialog_state}")
705
767
  return owner, new_dialog_state, res, owner
@@ -34,26 +34,27 @@ class DialogState:
34
34
  #------------------------------------------
35
35
 
36
36
  class Node:
37
- def __init__(self, performative, text=None, is_terminal=False):
37
+ def __init__(self, actor, performative, text=None, is_terminal=False):
38
+ self.actor = actor
38
39
  self.performative = performative # Se asigna el ID del objeto (en str)
39
40
  self.text = text
40
41
  self.is_terminal = is_terminal
41
42
  self.children = []
42
43
 
43
44
  class ActionNode(Node):
44
- def __init__(self, performative, text, action=None, team=None, tool=None, is_terminal=False):
45
- super().__init__(performative=performative, text=text, is_terminal=is_terminal)
45
+ def __init__(self, actor, performative, text, action=None, team=None, tool=None, is_terminal=False):
46
+ super().__init__(actor, performative=performative, text=text, is_terminal=is_terminal)
46
47
  self.action = action
47
48
  self.team = team
48
49
  self.tool = tool
49
50
 
50
51
  class DeclarativeNode(Node):
51
- def __init__(self, performative, text, is_terminal=False):
52
- super().__init__(performative, text, is_terminal)
52
+ def __init__(self, actor, performative, text, is_terminal=False):
53
+ super().__init__(actor, performative, text, is_terminal)
53
54
 
54
55
  class ResponseNode(Node):
55
- def __init__(self, performative, text, is_terminal=False):
56
- super().__init__(performative=performative, text=text, is_terminal=is_terminal)
56
+ def __init__(self, actor, performative, text, is_terminal=False):
57
+ super().__init__(actor, performative=performative, text=text, is_terminal=is_terminal)
57
58
 
58
59
  #------------------------------------------
59
60
  # Define functions
@@ -143,13 +144,13 @@ def recorrer_interacciones(obj):
143
144
  # Normalizamos el valor de "tipo" (se pasa a minúsculas y se reemplaza "í" por "i")
144
145
  tipo = obj["tipo"].lower().replace("í", "i").strip()
145
146
  if tipo == "dialogo":
146
- nuevo_nodo = DeclarativeNode(performative=current_id, text=texto, is_terminal=is_terminal)
147
+ nuevo_nodo = DeclarativeNode(actor=obj["actor"], performative=current_id, text=texto, is_terminal=is_terminal)
147
148
  elif tipo == "llamada a equipo":
148
- nuevo_nodo = ActionNode(performative=current_id, text=texto, action=tipo, team=obj["equipo"], tool=obj["herramienta"], is_terminal=is_terminal)
149
+ nuevo_nodo = ActionNode(actor=obj["actor"], performative=current_id, text=texto, action=tipo, team=obj["equipo"], tool=obj["herramienta"], is_terminal=is_terminal)
149
150
  elif tipo == "respuesta de equipo":
150
- nuevo_nodo = ResponseNode(performative=current_id, text=texto, is_terminal=is_terminal)
151
+ nuevo_nodo = ResponseNode(actor=obj["actor"], performative=current_id, text=texto, is_terminal=is_terminal)
151
152
  else:
152
- nuevo_nodo = Node(performative=current_id, text=texto, is_terminal=is_terminal)
153
+ nuevo_nodo = Node(actor=obj["actor"], performative=current_id, text=texto, is_terminal=is_terminal)
153
154
 
154
155
  # Se asignan los nodos hijos construidos
155
156
  nuevo_nodo.children = children
@@ -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 execute(self, data: any) -> None:
60
- """
61
- Response.
62
- @param data Event data
59
+ def active_timeout(self, ag, time: int) -> None:
60
+ """ Active timeout
61
+ @param time: Time
63
62
  """
64
- ag = self.agent.get_free_queue().get()
65
- self.agent.get_request_dict()[ag] = {
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
- @abstractmethod
102
- def delegate(self, data: any) -> None:
103
- """ Delegate
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.send_response(request)
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
- print('Assign to agent')
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
- print(f'With operation {operation}')
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
- print('The agent is not available')
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
- print('The agent is operational')
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
- print('Without operation')
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
- @See Action
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
- self.adm.send_event(self.agent.id, 'response', 'timeout')
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: Data
57
+ """ Execute the action
58
+ @param data: Event data
51
59
  """
52
- if not self.agent.is_timeout():
53
- self.agent.set_timeout(True)
54
- r = Timer(data['time'], self.handler)
55
- r.start()
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 """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pbesa
3
- Version: 4.0.1
3
+ Version: 4.0.3
4
4
  License-File: LICENSE
5
5
  License-File: LICENSE.txt
6
6
  Requires-Dist: pymongo==4.6.3
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
4
4
 
5
5
  setup(
6
6
  name='pbesa',
7
- version='4.0.1',
7
+ version='4.0.3',
8
8
  packages=find_packages(),
9
9
  install_requires=[
10
10
  'pymongo==4.6.3',
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