INNER CODE UNIT · Python

to_num

Arthur-Ficial/apfel · mcp/calculator/server.py:120

def to_num(v):
    """Coerce one argument value to a number, or None if it is not numeric.
    The model routinely sends numbers as strings ({"a":"999"}); without
    coercion Python string-concatenates and add() silently lies (#322)."""
    if isinstance(v, bool):
        return None
    if isinstance(v, (int, float)):
        return v
    if isinstance(v, str):
        try:
            return float(v) if "." in v else int(v)
        except ValueError:
            return None
    return None


def execute(name, args):
    """Execute a tool by name. Tolerates improvised argument keys."""

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…