robot_monitoring_tools.tools.battery_tool — robot_monitoring_tools 문서

# robot_monitoring_tools.tools.battery_tool의 소스 코드

    # robot_monitoring_tools/tools/battery_tool.py
    from langchain.tools import BaseTool
    from typing import List, Type
    import requests
    from .schemas import BatteryCheckRequest, BatteryCheckResponse
    from .api_schemas import RobotStatusRequest, RobotStatusResponse
    from langchain.tools import BaseTool
    from pydantic import BaseModel

    class CheckBatteryTool(BaseTool):
        name : str = "check_robot_battery"
        description : str = "로봇의 배터리 상태를 확인합니다. 특정 배터리 레벨보다 높거나 낮은 로봇들을 찾을 수 있습니다."
        args_schema : Type[BaseModel] = BatteryCheckRequest
        def _run(self, battery: int, condition: str = "lower") -> List[BatteryCheckResponse]:
            result = []
            url = "http://localhost:8000/robots/status"
            payload = RobotStatusRequest(
                columnName = "battery",
                battery = battery,
                batteryCondition = condition
            ).model_dump()
            response = requests.post(url, json=payload)
            if response.status_code == 200:
                for item in response.json():
                    response_item = RobotStatusResponse(**item)
                    result_item = BatteryCheckResponse(
                        robot_name = response_item.robot_name,
                        serial_number = response_item.serial_number,
                        battery = response_item.battery
                    )
                    result.append(result_item)
                return result
            return []

        async def _arun(self):
            raise NotImplementedError("비동기 실행은 지원하지 않습니다")