fix: made beliefs a dict of lists
[
Before it was a list of a dict of lists of lists of strings
now it is a dict of lists of lists of strings as prescribed by architecture (knowledge base)
*also added some tests, but will have to add some more
]
[ref]: N25B-206
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
from spade.behaviour import CyclicBehaviour
|
||||
from spade.message import Message
|
||||
from spade.agent import Message
|
||||
from control_backend.core.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -62,20 +62,29 @@ class ContinuousBeliefCollector(CyclicBehaviour):
|
||||
Expected payload:
|
||||
{
|
||||
"type": "belief_extraction_text",
|
||||
"beliefs": [
|
||||
{"user_said": [["hello"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
|
||||
]
|
||||
"beliefs": {"user_said": [["hello","test"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
|
||||
|
||||
}
|
||||
|
||||
"""
|
||||
beliefs = payload.get("beliefs", [])
|
||||
if not isinstance(beliefs, list):
|
||||
logger.warning("BeliefCollector: 'beliefs' is not a list: %r", beliefs)
|
||||
beliefs = payload.get("beliefs", dict)
|
||||
|
||||
if not beliefs:
|
||||
logger.info("BeliefCollector: no beliefs to process.")
|
||||
return
|
||||
|
||||
if not isinstance(beliefs, dict):
|
||||
logger.warning("BeliefCollector: 'beliefs' is not a dict: %r", beliefs)
|
||||
return
|
||||
|
||||
if not all(isinstance(v, list) for v in beliefs.values()):
|
||||
logger.warning("BeliefCollector: 'beliefs' values are not all lists: %r", beliefs)
|
||||
return
|
||||
|
||||
logger.info("BeliefCollector: forwarding %d beliefs.", len(beliefs))
|
||||
for b in beliefs:
|
||||
logger.info(" - %s", b)
|
||||
for belief_name, belief_lists in beliefs.items():
|
||||
for args in belief_lists:
|
||||
logger.info(" - %s %s", belief_name, " ".join(map(str, args)))
|
||||
|
||||
await self._send_beliefs_to_bdi(beliefs, origin=origin)
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@ class BeliefTextAgent(Agent):
|
||||
# Send multiple beliefs in one JSON payload
|
||||
payload = {
|
||||
"type": "belief_extraction_text",
|
||||
"beliefs": [
|
||||
{"user_said": [["hello"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
|
||||
]
|
||||
"beliefs": {"user_said": [["hello","test"],["Can you help me?"],["stop talking to me"],["No"],["Pepper do a dance"]]}
|
||||
|
||||
}
|
||||
|
||||
msg = Message(to=to_jid)
|
||||
|
||||
Reference in New Issue
Block a user