收到描述函数名和参数的 JSON,程序怎样将它变成一次函数调用?

1 个问题1 份回答整棵树 · 全部版本PythonJSON工具调用
起始问题

提问原文

I have a function:

def multiply(a: int, b: int) -> int:
    """Multiply two numbers.

    Args:
        a: First integer
        b: Second integer
    """
    return a * b

And I receive a Json file document a function call to the above function:

{
  "action": "multiply",
  "args": [
    {"a": 3},
    {"b": 4}
  ]
}

How can I write a python code to automate the function call once I recieve the json file?

这一版的回答 · 1

回答 1 · 社区回答_本次整理(2026-09-08),非原对话逐字回答。_ 可以把它分成 解析 JSON、验证请求、从允许的函数映射中分派调用 三步。JSON 只是数据;让它对应哪段代码,应由程序明确决定。 下面的示例保留原问的 args 列表格式,只允许调用 multiply 。把阅读全文 →