function calling简介

拒绝废话

是什么 {#是什么}

函数调用是将 LLM 可靠地连接到外部工具以实现有效使用工具以及与外部 API 交互的能力。
LLM 经过微调,可以检测何时需要调用函数,从 prompt 中提取出参数和结构,输出 JSON 以调用该函数。函数调用调用的函数将充当 AI 应用程序中的工具,

有什么用 {#有什么用}

  1. 可以有效地使用外部工具回答问题的对话代理
  2. 帮助将自然语言转换为 API 调用或有效数据库查询的应用程序

怎么用(Demo) {#怎么用–demo}

  1. 首先我们按格式定义一组 tools.
tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA",
                    },
                    "unit": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"]},
                },
                "required": ["location"],
            },
        },
    }
]
  1. name 就是 function name
  2. description LLM会根据 de scription来判断 你的promtp 是不是和这个函数相关, (怎么判断的? 2 个文本量化计算相关性)
  3. parameters 就是 function 的入参.
  1. 然后, 我们有个prompt “What is the weather like in London?” 构建一个 messages
messages = [
  4. {
        "role": "user",
        "content": "What is the weather like in London?"
    }
]

最后把 messages 和 tools 都发给LLM, 生成 response

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值