pbesa 4.0.7__tar.gz → 4.0.8__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.7 → pbesa-4.0.8}/PKG-INFO +1 -1
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/cognitive.py +182 -20
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/dispatcher_team.py +14 -8
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/prompts.py +26 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa.egg-info/PKG-INFO +1 -1
- {pbesa-4.0.7 → pbesa-4.0.8}/setup.py +1 -1
- {pbesa-4.0.7 → pbesa-4.0.8}/.gitignore +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/LICENSE +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/LICENSE.txt +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/MANIFEST +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/README.md +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/db.sqlite3 +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/settings.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/wsgi.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/asgi.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/pbesa.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/settings.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/urls.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/wsgi.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/manage.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/views.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/admin.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/apps.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/translatecontroller.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/translatedelegate.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/translateresponse.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/worker/translatetask.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/worker/workeragent.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/migrations/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/migrations/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/models.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/tests.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/urls.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/views.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/__pycache__/countercontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/__pycache__/counterdelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/__pycache__/counterresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/__pycache__/translatecontroller.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/__pycache__/translatedelegate.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/__pycache__/translateresponse.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/countercontroller.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/counterdelegate.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/controller/counterresponse.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/workeragent.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/counteragent.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/countertask.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/remote_a.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/remote_b.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/remote_c.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/adapter.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/agent.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/io/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/io/system_file.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/io/tcp_server.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/res/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/res/__pycache__/__init__.cpython-36.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/res/__pycache__/__init__.cpython-37.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/res/__pycache__/__init__.cpython-38.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/res/__pycache__/__init__.cpython-39.pyc +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/res/conf.json +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/util.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/kernel/world.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/mas.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/models.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/remote/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/remote/adm_listener.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/remote/adm_listener_handler.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/remote/exceptions.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/remote/remote_adm.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/remote/remote_adm_handler.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/__init__.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/collaborative_team.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/delegator.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/delegator_team.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/dialog.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/selected_dispatcher_team.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/templates.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa/social/worker.py +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa.egg-info/SOURCES.txt +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa.egg-info/dependency_links.txt +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa.egg-info/requires.txt +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/pbesa.egg-info/top_level.txt +0 -0
- {pbesa-4.0.7 → pbesa-4.0.8}/setup.cfg +0 -0
@@ -17,6 +17,7 @@ import uuid
|
|
17
17
|
import json
|
18
18
|
import logging
|
19
19
|
import traceback
|
20
|
+
from .mas import Adm
|
20
21
|
from pydantic import BaseModel
|
21
22
|
from typing import List, Optional
|
22
23
|
from abc import ABC, abstractmethod
|
@@ -24,7 +25,7 @@ from pbesa.models import AIFoundry, AzureInference, GPTService, ServiceProvider
|
|
24
25
|
from pbesa.social.dialog import (
|
25
26
|
DialogState, imprimir_grafo, recorrer_interacciones, extraer_diccionario_nodos,
|
26
27
|
ActionNode, DeclarativeNode, GotoNode) #, TerminalNode
|
27
|
-
from pbesa.social.prompts import CLASSIFICATION_PROMPT, DERIVE_PROMPT, RECOVERY_PROMPT
|
28
|
+
from pbesa.social.prompts import CLASSIFICATION_PROMPT, DERIVE_PROMPT, RECOVERY_PROMPT, ADAPT_PROMPT
|
28
29
|
# --------------------------------------------------------
|
29
30
|
# Define DTOs
|
30
31
|
# --------------------------------------------------------
|
@@ -481,7 +482,7 @@ class Dialog(ABC):
|
|
481
482
|
"counter": 0
|
482
483
|
}
|
483
484
|
# Define recovery message
|
484
|
-
self.RECOVERY_MSG = "Lo lamento, puedes darme más detalles o reformular"
|
485
|
+
self.RECOVERY_MSG = "Lo lamento, puedes darme más detalles o reformular. O puedes recibir asistencia humana vía correo electrónico al atencion@minjsuticia.com.co o al Whatsapp 321456987."
|
485
486
|
# Define vertices list
|
486
487
|
self.__vertices = []
|
487
488
|
# Define visited nodes
|
@@ -586,6 +587,9 @@ class Dialog(ABC):
|
|
586
587
|
"performative": DialogState.START,
|
587
588
|
"counter": 0
|
588
589
|
}
|
590
|
+
# Reset visited nodes
|
591
|
+
self.__visited_nodes = 0
|
592
|
+
self.__vertices = []
|
589
593
|
|
590
594
|
def notify(self, text):
|
591
595
|
try:
|
@@ -611,6 +615,14 @@ class Dialog(ABC):
|
|
611
615
|
canales = self.state['canales']
|
612
616
|
canal = canales.get(team)
|
613
617
|
if session_flag:
|
618
|
+
# Actualiza la sesion
|
619
|
+
session_manager = self.state['session_manager']
|
620
|
+
session_manager.update_session(self.state['session_id'], {
|
621
|
+
'team': team,
|
622
|
+
'owner': team,
|
623
|
+
'performative': DialogState.START,
|
624
|
+
})
|
625
|
+
# Construye el mensaje
|
614
626
|
dto = {
|
615
627
|
"data": {
|
616
628
|
'text': data,
|
@@ -690,7 +702,7 @@ class Dialog(ABC):
|
|
690
702
|
}
|
691
703
|
logging.info(f"Recovery attemps: {self.__recovery["counter"]}")
|
692
704
|
# Verifica si se ha alcanzado el límite de recuperación
|
693
|
-
if self.__recovery['counter'] <= 3 and self.__visited_nodes
|
705
|
+
if self.__recovery['counter'] <= 3 and self.__visited_nodes <= 3:
|
694
706
|
self.notify("identificando concepto...")
|
695
707
|
#--------------------------
|
696
708
|
# Verifica que exista la performativa
|
@@ -740,6 +752,8 @@ class Dialog(ABC):
|
|
740
752
|
select_node = children[0]
|
741
753
|
else:
|
742
754
|
logging.info("???> Es un nodo terminal o iniciador")
|
755
|
+
logging.warning(f"???> Es un nodo terminal o iniciador: {node.text}")
|
756
|
+
logging.warning(f"???> Es un nodo terminal o iniciador: {node.performative}")
|
743
757
|
return self.recovery(query)
|
744
758
|
#--------------------------
|
745
759
|
# Verifica si es un nodo
|
@@ -764,7 +778,20 @@ class Dialog(ABC):
|
|
764
778
|
# Efectua transicion
|
765
779
|
if select_node:
|
766
780
|
res = select_node.text
|
767
|
-
|
781
|
+
if select_node.children and len(select_node.children) > 0:
|
782
|
+
res = select_node.children[0].text
|
783
|
+
node = select_node.children[0]
|
784
|
+
else:
|
785
|
+
logging.info(f"-> El nodo de transición es terminal: {select_node.text}")
|
786
|
+
res = select_node.text
|
787
|
+
node = select_node
|
788
|
+
else:
|
789
|
+
logging.info(f"-> !!!!!!!!!!!!!! Concepto no encontrado !!!!!!!!!!!!!!")
|
790
|
+
if isinstance(node, list) and len(node) > 0:
|
791
|
+
node = node[0]
|
792
|
+
else:
|
793
|
+
logging.info(f"-> !!!!!!!!!!!!!! Concepto no encontrado ????????????????")
|
794
|
+
return self.recovery(query)
|
768
795
|
logging.info(f"Flujo normal: {res}")
|
769
796
|
self.notify(res)
|
770
797
|
#---------------------------
|
@@ -780,9 +807,12 @@ class Dialog(ABC):
|
|
780
807
|
# trabajo
|
781
808
|
if team_source:
|
782
809
|
self.__work_memory.append({"role": "user", "content": res})
|
810
|
+
logging.info(f"-> Actualiza WM: {res}")
|
783
811
|
else:
|
784
812
|
self.__work_memory.append({"role": "user", "content": query})
|
785
|
-
self.__work_memory.append({"role": "user", "content": res})
|
813
|
+
#self.__work_memory.append({"role": "user", "content": res})
|
814
|
+
logging.info(f"-> Actualiza q-WM: {query}")
|
815
|
+
#logging.info(f"-> Actualiza r-WM: {res}")
|
786
816
|
#---------------------------
|
787
817
|
# Efectua inferencia
|
788
818
|
new_owner, new_dialog_state, res, team = self.do_transition(owner, node, query)
|
@@ -839,16 +869,22 @@ class Dialog(ABC):
|
|
839
869
|
if node.is_terminal:
|
840
870
|
logging.info(f"-> node team -> es terminal -> {node.text}")
|
841
871
|
self.__work_memory.append({"role": "user", "content": node.text})
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
self.
|
851
|
-
|
872
|
+
|
873
|
+
res = query
|
874
|
+
if "consulta" in node.text.lower():
|
875
|
+
logging.info(f"-> node team -> consulta: {query}")
|
876
|
+
else:
|
877
|
+
logging.info("-----")
|
878
|
+
logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
|
879
|
+
logging.info("-----")
|
880
|
+
res = self.__ai_service.generate(self.__work_memory)
|
881
|
+
res = self.get_text(res)
|
882
|
+
self.__work_memory.append({"role": "system", "content": res})
|
883
|
+
# Check if res is empty
|
884
|
+
if not res or res == "":
|
885
|
+
self.notify(f"no pude contactar al agente: {node.team}")
|
886
|
+
return self.recovery(query)
|
887
|
+
|
852
888
|
self.notify(f"le envio al agente {node.team}: {res}")
|
853
889
|
logging.info(f"-> node team -> envia: {res}")
|
854
890
|
res = self.team_inquiry(node.team, res, None, True)
|
@@ -860,11 +896,27 @@ class Dialog(ABC):
|
|
860
896
|
else:
|
861
897
|
return self.recovery(query)
|
862
898
|
else:
|
899
|
+
|
863
900
|
logging.info("-> node team -> continua")
|
864
|
-
self.__work_memory.append({"role": "user", "content": node.text})
|
865
|
-
|
866
|
-
|
901
|
+
self.__work_memory.append({"role": "user", "content": node.text})
|
902
|
+
res = query
|
903
|
+
if "consulta" in node.text.lower():
|
904
|
+
logging.info(f"-> node team -> consulta: {query}")
|
905
|
+
else:
|
906
|
+
logging.info(f"-> node team -> sentencia: {node.text}")
|
907
|
+
logging.info("-----")
|
908
|
+
logging.info("\n%s", json.dumps(self.__work_memory, indent=4))
|
909
|
+
logging.info("-----")
|
910
|
+
res = self.get_text(res)
|
911
|
+
self.__work_memory.append({"role": "system", "content": res})
|
912
|
+
# Check if res is empty
|
913
|
+
if not res or res == "":
|
914
|
+
self.notify(f"no pude contactar al agente: {node.team}")
|
915
|
+
return self.recovery(query)
|
916
|
+
self.notify(f"le envio al agente {node.team}: {res}")
|
917
|
+
res = self.team_inquiry(node.team, res, node.tool, False)
|
867
918
|
self.notify(f"continuando con díalogo")
|
919
|
+
|
868
920
|
# Adiciona el texto al work memory
|
869
921
|
if res and not res == "ERROR" and not res == "":
|
870
922
|
logging.info(f"-> Adicion WM node team -> text: {res}")
|
@@ -908,8 +960,10 @@ class Dialog(ABC):
|
|
908
960
|
self.notify(f"finalizando díalogo de inferencia")
|
909
961
|
logging.info(f"Tipe node: {type(node)}")
|
910
962
|
logging.info(f"$$$> new_owner: {owner} new_dialog_state: {new_dialog_state}")
|
963
|
+
#logging.info(f"------------RESET---------------")
|
964
|
+
#self.reset()
|
911
965
|
self.notify("STOP")
|
912
|
-
return
|
966
|
+
return "Web", DialogState.START, res, "Web"
|
913
967
|
logging.info("END: do_transition")
|
914
968
|
except Exception as e:
|
915
969
|
traceback.print_exc()
|
@@ -923,4 +977,112 @@ class Dialog(ABC):
|
|
923
977
|
:param query: query
|
924
978
|
:return: str
|
925
979
|
"""
|
926
|
-
self.knowledge = knowledge
|
980
|
+
self.knowledge = knowledge
|
981
|
+
|
982
|
+
def adapt(self, data, profile) -> any:
|
983
|
+
""" Adapt method
|
984
|
+
:param data: data
|
985
|
+
:return: str
|
986
|
+
"""
|
987
|
+
try:
|
988
|
+
logging.info(f"Adaptando respuesta: {data}")
|
989
|
+
# Get text
|
990
|
+
text = ""
|
991
|
+
if isinstance(data, str):
|
992
|
+
text = data
|
993
|
+
elif isinstance(data, dict):
|
994
|
+
text = data['dto']['text'] if data and 'dto' in data and data['dto']['text'] is not None else ''
|
995
|
+
else:
|
996
|
+
raise ValueError("Respuesta mal formada")
|
997
|
+
# Adapt the data
|
998
|
+
tmp_work_memory = []
|
999
|
+
prompt = ADAPT_PROMPT % (text, profile)
|
1000
|
+
tmp_work_memory.append({"role": "user", "content": prompt})
|
1001
|
+
res = self.__ai_service.generate(tmp_work_memory)
|
1002
|
+
res = self.get_text(res)
|
1003
|
+
logging.info(f"Respuesta adaptada: {res}")
|
1004
|
+
if not res or res == "":
|
1005
|
+
res = text
|
1006
|
+
logging.warning(f"No se pudo adaptar la respuesta.")
|
1007
|
+
return res
|
1008
|
+
except Exception as e:
|
1009
|
+
logging.error(f"Error al adaptar el dato: {data}")
|
1010
|
+
logging.error(e)
|
1011
|
+
return None
|
1012
|
+
|
1013
|
+
# --------------------------------------------------------
|
1014
|
+
# Define Special Dispatch
|
1015
|
+
# --------------------------------------------------------
|
1016
|
+
|
1017
|
+
class SpecialDispatch():
|
1018
|
+
""" Special dispatch """
|
1019
|
+
|
1020
|
+
def __init__(self) -> None:
|
1021
|
+
""" Constructor method """
|
1022
|
+
self.model:any = None
|
1023
|
+
self.model_conf:dict = None
|
1024
|
+
self.__meta_work_memory:list = []
|
1025
|
+
# Define AI service
|
1026
|
+
self.__ai_service = None
|
1027
|
+
self.knowledge = None
|
1028
|
+
# Define options dictionary
|
1029
|
+
self.__options_dict = {}
|
1030
|
+
# Reference of ADM
|
1031
|
+
self.adm = Adm()
|
1032
|
+
|
1033
|
+
def load_model(self, provider, config, ai_service=None) -> None:
|
1034
|
+
self.__service_provider, service = define_service_provider(provider, ai_service)
|
1035
|
+
service.setup(config)
|
1036
|
+
self.__ai_service = service
|
1037
|
+
# Setup options dictionary
|
1038
|
+
agent_list = self.get_agent_list()
|
1039
|
+
# Get the agent asocciated with the data.
|
1040
|
+
for agent_id in agent_list:
|
1041
|
+
agent = self.adm.get_agent(agent_id)
|
1042
|
+
# Check if the agent is instance of Dialog
|
1043
|
+
if isinstance(agent, Dialog):
|
1044
|
+
# Get the role
|
1045
|
+
role = agent.get_role()
|
1046
|
+
self.__options_dict[agent_id] = role.description
|
1047
|
+
|
1048
|
+
def get_text(self, mensaje) -> str:
|
1049
|
+
if mensaje:
|
1050
|
+
mensaje_limpio = mensaje.replace("<|im_start|>user<|im_sep|>", "").replace("<|im_start|>system<|im_sep|>", "") \
|
1051
|
+
.replace("<|im_start|>", "").replace("<|im_sep|>", "").replace("<|im_end|>", "") \
|
1052
|
+
.replace("[Usuario]: ", "").replace("[Sistema]: ", "") \
|
1053
|
+
.replace("<|user|>", "").replace("<|system|>", "")
|
1054
|
+
return mensaje_limpio.strip()
|
1055
|
+
else:
|
1056
|
+
return ""
|
1057
|
+
|
1058
|
+
def special_dispatch(self, data: any) -> None:
|
1059
|
+
"""
|
1060
|
+
Response.
|
1061
|
+
@param data Event data
|
1062
|
+
"""
|
1063
|
+
logging.info("Despachando por descripcion...")
|
1064
|
+
options = ""
|
1065
|
+
cont = 1
|
1066
|
+
agent_options = {}
|
1067
|
+
for agent, item in self.__options_dict.items():
|
1068
|
+
agent_options[cont] = agent
|
1069
|
+
options += f"{cont}) {item}\n"
|
1070
|
+
cont += 1
|
1071
|
+
query = data['dto']['text'] if data and 'dto' in data and data['dto']['text'] is not None else ''
|
1072
|
+
prompt = CLASSIFICATION_PROMPT % (query, options)
|
1073
|
+
logging.info(f"Query: {query},\n Options:\n{options}")
|
1074
|
+
self.__meta_work_memory.append({"role": "user", "content": prompt})
|
1075
|
+
res = self.__ai_service.generate(self.__meta_work_memory)
|
1076
|
+
logging.info(f"Thought: {res}")
|
1077
|
+
self.__meta_work_memory = []
|
1078
|
+
res = self.get_text(res)
|
1079
|
+
select_agent = None
|
1080
|
+
for option in range(1, cont+1):
|
1081
|
+
if str(option) in res:
|
1082
|
+
select_agent = agent_options[option]
|
1083
|
+
logging.info(f"Descripcion del agente seleccionado: {select_agent}")
|
1084
|
+
break
|
1085
|
+
if not select_agent:
|
1086
|
+
logging.info("=> No se seleccionó ningun agente")
|
1087
|
+
return select_agent
|
1088
|
+
|
@@ -113,15 +113,21 @@ class ResponseAction(Action):
|
|
113
113
|
""" Execute
|
114
114
|
@param data: Data
|
115
115
|
"""
|
116
|
-
|
117
|
-
if '
|
118
|
-
|
119
|
-
|
116
|
+
logging.info(f"[ResponseAction][{self.agent.id}]: Response: {data}")
|
117
|
+
if data['source'] in self.agent.get_request_dict():
|
118
|
+
request = self.agent.get_request_dict()[data['source']]
|
119
|
+
|
120
|
+
if 'timeout' in data:
|
121
|
+
logging.info(f"[ResponseAction][{self.agent.id}]: Timeout ******************")
|
122
|
+
request['gateway'].put("TIMEOUT")
|
123
|
+
else:
|
124
|
+
request['dtoList'].append(data['result'])
|
125
|
+
if len(request['dtoList']) >= self.agent.get_buffer_size():
|
126
|
+
self.send_response(request)
|
127
|
+
self.adm.send_event(data['source'], 'timeout', {'command': 'stop'})
|
120
128
|
else:
|
121
|
-
|
122
|
-
|
123
|
-
self.send_response(request)
|
124
|
-
self.adm.send_event(data['source'], 'timeout', {'command': 'stop'})
|
129
|
+
logging.warning(f"[ResponseAction][{self.agent.id}]: Warning ******************")
|
130
|
+
logging.warning(f"[ResponseAction][{self.agent.id}]: {data}")
|
125
131
|
|
126
132
|
# --------------------------------------------------------
|
127
133
|
# Define component
|
@@ -60,5 +60,31 @@ Ahora, evalúa el siguiente caso:
|
|
60
60
|
|
61
61
|
Texto: "%s"
|
62
62
|
|
63
|
+
Respuesta:
|
64
|
+
"""
|
65
|
+
|
66
|
+
ADAPT_PROMPT = """
|
67
|
+
Instrucciones:
|
68
|
+
|
69
|
+
Eres un un asistente experto en comunicación. Recibirás un texto original y un perfil de adaptación. Tu tarea es reescribir el texto para que se alinee completamente con el estilo, tono y objetivo comunicativo del perfil.
|
70
|
+
|
71
|
+
Requisitos:
|
72
|
+
|
73
|
+
- No incluyas explicaciones, razonamientos ni texto adicional.
|
74
|
+
|
75
|
+
Ejemplo:
|
76
|
+
|
77
|
+
Texto: "Para solicitar el certificado, debe ingresar al sitio web, crear una cuenta, llenar el formulario y esperar el correo de confirmación."
|
78
|
+
|
79
|
+
Perfil de adaptación: "Usaurio Autonomo - Proporcionar respuestas directas y concisas para realizar trámites rápidamente."
|
80
|
+
|
81
|
+
Respuesta: Ingrese al sitio, cree su cuenta, complete el formulario y revise su correo.
|
82
|
+
|
83
|
+
Ahora, evalúa el siguiente caso:
|
84
|
+
|
85
|
+
Texto: "%s"
|
86
|
+
|
87
|
+
Perfil de adaptación: "%s"
|
88
|
+
|
63
89
|
Respuesta:
|
64
90
|
"""
|
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.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/pbesa.cpython-36.pyc
RENAMED
File without changes
|
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/helloworld/__pycache__/urls.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/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.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/__init__.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/admin.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/apps.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/models.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/__pycache__/urls.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/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.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/translatedelegate.py
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/django/helloworld/translate/mas/controller/translateresponse.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/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.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/counteragent.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/countertask.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/examples/remote/mas/worker/__pycache__/translatetask.cpython-36.pyc
RENAMED
File without changes
|
{pbesa-4.0.7 → pbesa-4.0.8}/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
|