feat: setup gesture agent and adjust command port for the UI

ref: N25B-334
This commit is contained in:
Björn Otgaar
2025-12-02 15:00:10 +01:00
parent c85753f834
commit 95c7585bf1
5 changed files with 151 additions and 8 deletions

View File

@@ -3,12 +3,13 @@ import json
import logging
import zmq.asyncio
from fastapi import APIRouter, Request
from fastapi import APIRouter, HTTPException, Request
from fastapi.responses import StreamingResponse
from pydantic import ValidationError
from zmq.asyncio import Context, Socket
from control_backend.core.config import settings
from control_backend.schemas.ri_message import SpeechCommand
from control_backend.schemas.ri_message import GestureCommand, SpeechCommand
logger = logging.getLogger(__name__)
@@ -22,17 +23,29 @@ async def receive_command(command: SpeechCommand, request: Request):
Publishes the command to the internal 'command' topic. The
:class:`~control_backend.agents.actuation.robot_speech_agent.RobotSpeechAgent`
or
:class:`~control_backend.agents.actuation.robot_speech_agent.RobotGestureAgent`
will forward this to the robot.
:param command: The speech command payload.
:param request: The FastAPI request object.
"""
# Validate and retrieve data.
SpeechCommand.model_validate(command)
validated = None
valid_commands = (GestureCommand, SpeechCommand)
for command_model in valid_commands:
try:
validated = command_model.model_validate(command)
except ValidationError:
continue
if validated is None:
raise HTTPException(status_code=422, detail="Payload is not valid for command models")
topic = b"command"
pub_socket: Socket = request.app.state.endpoints_pub_socket
await pub_socket.send_multipart([topic, command.model_dump_json().encode()])
await pub_socket.send_multipart([topic, validated.model_dump_json().encode()])
return {"status": "Command received"}