如何实现LLM的通用function-calling能力?

SenseNova 商汤日日新大模型 Function Call(函数调用)功能讲解和应用示例 在 LLM(Large Language Model) 语言大模型时代,Function Call(函数调用)是指可靠地连接LLM 与外部工具的能力。让用户能够使用高效的外部工具、与外部API进行交互。GPT-4 和国内 SenseNova 等经过微调的 LLM,能够检测函数是否被调用,随后输出包含调用函数参数的 JSON。通过这一过程被调用的函数能够作为工具添加到您的 AI 应用中,并且您可以在单个请求中定义多个函数。函数调用是一项重要能力。它对于构建 LLM 驱动的聊天机器人或代理至关重要。这些聊天机器 阅读详情

众所周知,LLM的函数function-calling能力很强悍,解决了大模型与实际业务系统的交互问题。其本质就是函数调用。

从openai官网摘图:

简而言之:

  1. LLM起到决策的作用,告知业务系统应该调用什么函数,以及入参是什么。

  2. 业务系统负责实现对应的函数(比如本地实现,或者调用其他系统提供的服务),并且将函数的响应结果再次抛给LLM。

  3. LLM根据响应结果,组织自然语言,继续与业务系统进行交互。

在这里,有很多小伙伴会有一个误区:误以为函数调用是有LLM本身执行的。其实,LLM仅仅做决策,而实际的调用是由业务系统完成的。

现阶段,function-calling能力的实现有两种主流方式:

  1. LLM本身支持。

  2. 利用Prompt模板实现,典型如ReAct模板。

在实际的应用过程中,我们还要解决另一个重要问题:

function-calling触发机制是怎样的?也即:何时要使用function-calling能力,何时不应该使用?

这个问题的处理方式,对于整体流程的运行至关重要。

此时,我们可以使用特定Prompt来解决该问题:

You have access to the following tools:  
{json.dumps(tools)}  
You can select one of the above tools or just response user's content and respond with only a JSON object matching the following schema:  
{{  
  "tool": <name of the selected tool>,  
  "tool_input": <parameters for the selected tool, matching the tool'  
s JSON schema>,  
  "message": <direct response users content>}

该Prompt告知了LLM:如果需要使用function-calling能力,那么就从tools(tools是预定义的functions)中选取一个最匹配的函数;如果不需要,就用自然语言与用户交互,此时与正常的对话流程无异。输出的格式固定为json,方便解析。

由此,我们受到启发:只要LLM基座够强(能够严格遵循Prompt响应诉求),即使LLM本身不支持function-calling,我们也可以自己实现function-calling,脱离对特定LLM的依赖!

拿到function-calling的结果后,若要用自然语言的形式输出结果,还要再调用一次LLM,对结果进行整合。此时可以使用另一个Prompt:

Please generate a natural language description based on the following question and answer.  
Question: [Content of the question]  
Answer: [Content of the answer]  
Generated Description: The result of [key phrase from the question] is [answer].  
If necessary, you can polish the description.Only output the Description, with Chinese language.

该Prompt的作用就是告诉LLM,你要根据我的问题和答案,用自然语言重新描述一遍。这里指定了中文输出,可根据实际需要进行调整。

以下是一个可运行的完整Python脚本:

import requests  
import json  
import random  
  
# 预置函数定义  
tools = [  
    {  
        "name": "get_current_weather",  
        "description": "Get the current weather in a given location",  
        "parameters": {  
            "type": "object",  
            "properties": {  
                "location": {  
                    "type": "string",  
                    "description": "The city e.g. Beijing"  
                },  
                "unit": {  
                    "type": "string",  
                    "enum": [  
                        "celsius"  
                    ]  
                }  
            },  
            "required": [  
                "location"  
            ]  
        }  
    },  
    {  
        "name": "calculator",  
        "description": "计算器",  
        "parameters": {  
            "type": "int",  
            "properties": {  
                "a": {  
                    "type": "int",  
                    "description": "the first number"  
                },  
                "b": {  
                    "type": "int",  
                    "description": "the second number"  
                }  
            },  
            "required": [  
                "a",  
                "b"  
            ]  
        }  
    }  
]  
  
# 获取天气(随机返回,实际使用可以替换为api调用)  
def get_current_weather(*args):  
    # 定义可能的天气状态  
    weather_conditions = ["sunny", "cloudy", "rainy", "snowy"]  
    # 定义可能的温度范围  
    temperature_min = -10  # 最低温度,摄氏度  
    temperature_max = 35  # 最高温度,摄氏度  
    # 随机选择一个天气状态  
    condition = random.choice(weather_conditions)  
    # 随机生成一个温度  
    temperature = random.randint(temperature_min, temperature_max)  
    # 返回一个描述当前天气的字符串  
    return f"The weather of {args[0].get('location')} is {condition}, and the temperature is {temperature}°C."  
  
def calculator(args):  
    return sum(value for value in args.values() if isinstance(value, int))  
  
# 函数映射集合  
functions = {  
    "get_current_weather": get_current_weather,  
    "calculator": calculator,  
}  
  
# 驱动整体流程的入口prompt  
entrance_prompt = f"""You have access to the following tools:  
{json.dumps(tools)}  
You can select one of the above tools or just response user's content and respond with only a JSON object matching the following schema:  
{{  
  "tool": <name of the selected tool>,  
  "tool_input": <parameters for the selected tool, matching the tool's JSON schema>,  
  "message": <direct response users content>  
}}"""  
  
# 请以自然语言的形式对结果进行描述  
conformity_prompt = f"""  
Please generate a natural language description based on the following question and answer.  
Question: [Content of the question]  
Answer: [Content of the answer]  
Generated Description: The result of [key phrase from the question] is [answer].  
If necessary, you can polish the description.  
Only output the Description, with Chinese language.  
"""  
  
def extract_json(s):  
    stack = 0  
    start = s.find('{')  
    if start == -1:  
        return None  
  
    for i in range(start, len(s)):  
        if s[i] == '{':  
            stack += 1  
        elif s[i] == '}':  
            stack -= 1  
            if stack == 0:  
                return s[start:i + 1]  
    return None  
  
# 结果包装器,type为func表示是函数调用返回的结果,default表示是自然语言结果。对于func返回的结果,会用LLM再次总结  
class ResultWrapper:  
    def __init__(self, type, result):  
        self.type = type  
        self.result = result  
  
# 解析LLM返回的结果,如果有json则去解析json  
def parse_result(res):  
    json_str = extract_json(res["message"]["content"])  
    if json_str is not None:  
        obj = json.loads(json_str)  
        if "tool" in obj:  
            if obj["tool"] in functions:  
                fun = functions[obj["tool"]]  
                return ResultWrapper("func", fun(obj["tool_input"]))  
            else:  
                return ResultWrapper("default", obj["message"])  
        else:  
            return ResultWrapper("default", res["message"]["content"])  
    else:  
        return ResultWrapper("default", res["message"]["content"])  
  
def invokeLLM(messages):  
    url = "${domain}/v1/chat/completions" #需替换域名  
    model = ""  
    payload = {  
        "model": model,  
        "messages": messages,  
    }  
    payload = json.dumps(payload)  
    headers = {  
        'Content-Type': 'application/json'  
    }  
    print("PAYLOAD: ", payload)  
    response = requests.request("POST", url, headers=headers, data=payload)  
    print("RESPONSE: ", response.text)  
    print("=======================================================================")  
    resp = json.loads(response.text)  
    return resp["choices"][0]  
  
  
if __name__ == '__main__':  
    while True:  
        messages = [  
            {  
                "role": "system",  
                "content": entrance_prompt  
            }  
        ]  
        user_input = input('Enter a string: ')  
        messages.append({  
            "role": "user",  
            "content": user_input  
        })  
        result_wrapper = parse_result(invokeLLM(messages))  
        if result_wrapper.type == "func":  
            messages = [  
                {  
                    "role": "user",  
                    "content": f"{conformity_prompt}\n\nThe question:{user_input}\nThe answer:{result_wrapper.result}"  
                }  
            ]  
            print("FINAL RESULT WITH FUNCTION CALL: ", parse_result(invokeLLM(messages)).result)  
        else:            print("FINAL RESULT: ", result_wrapper.result

实验效果:

Enter a string: 你好  
PAYLOAD: {"model": "", "messages": [{"role": "system", "content": "You have access to the following tools:\n[{\"name\": \"get_current_weather\", \"description\": \"Get the current weather in a given location\", \"parameters\": {\"type\": \"object\", \"properties\": {\"location\": {\"type\": \"string\", \"description\": \"The city e.g. Beijing\"}, \"unit\": {\"type\": \"string\", \"enum\": [\"celsius\"]}}, \"required\": [\"location\"]}}, {\"name\": \"calculator\", \"description\": \"\\u8ba1\\u7b97\\u5668\", \"parameters\": {\"type\": \"int\", \"properties\": {\"a\": {\"type\": \"int\", \"description\": \"the first number\"}, \"b\": {\"type\": \"int\", \"description\": \"the second number\"}}, \"required\": [\"a\", \"b\"]}}]\nYou can select one of the above tools or just response user's content and respond with only a JSON object matching the following schema:\n{\n \"tool\": <name of the selected tool>,\n \"tool_input\": <parameters for the selected tool, matching the tool's JSON schema>,\n \"message\": <direct response users content>\n}"}, {"role": "user", "content": "\u4f60\u597d"}]}  
RESPONSE: {"model":"","object":"","choices":[{"index":0,"message":{"role":"assistant","content":"```json\n{\"tool\": null, \"tool_input\": null, \"message\": \"你好,有什么可以帮您的吗?\"}\n```","function_call":null},"finish_reason":"stop"}],"queueTime":0.0020923614501953125,"costTime":0.7685532569885254,"usage":{"prompt_token":244,"completion_token":29,"total_tokens":273}}  
=======================================================================  
FINAL RESULT: 你好,有什么可以帮您的吗?  
  
  
Enter a string: 厦门天气如何?  
PAYLOAD: {"model": "", "messages": [{"role": "system", "content": "You have access to the following tools:\n[{\"name\": \"get_current_weather\", \"description\": \"Get the current weather in a given location\", \"parameters\": {\"type\": \"object\", \"properties\": {\"location\": {\"type\": \"string\", \"description\": \"The city e.g. Beijing\"}, \"unit\": {\"type\": \"string\", \"enum\": [\"celsius\"]}}, \"required\": [\"location\"]}}, {\"name\": \"calculator\", \"description\": \"\\u8ba1\\u7b97\\u5668\", \"parameters\": {\"type\": \"int\", \"properties\": {\"a\": {\"type\": \"int\", \"description\": \"the first number\"}, \"b\": {\"type\": \"int\", \"description\": \"the second number\"}}, \"required\": [\"a\", \"b\"]}}]\nYou can select one of the above tools or just response user's content and respond with only a JSON object matching the following schema:\n{\n \"tool\": <name of the selected tool>,\n \"tool_input\": <parameters for the selected tool, matching the tool's JSON schema>,\n \"message\": <direct response users content>\n}"}, {"role": "user", "content": "\u53a6\u95e8\u5929\u6c14\u5982\u4f55\uff1f"}]}  
RESPONSE: {"model":"","object":"","choices":[{"index":0,"message":{"role":"assistant","content":"```json\n{\"tool\": \"get_current_weather\", \"tool_input\": {\"location\": \"Xiamen\", \"unit\": \"celsius\"}, \"message\": \"\"}\n```","function_call":null},"finish_reason":"stop"}],"queueTime":0.0021338462829589844,"costTime":0.9370713233947754,"usage":{"prompt_token":247,"completion_token":36,"total_tokens":283}}  
=======================================================================  
PAYLOAD: {"model": "", "messages": [{"role": "user", "content": "\nPlease generate a natural language description based on the following question and answer.\nQuestion: [Content of the question]\nAnswer: [Content of the answer]\nGenerated Description: The result of [key phrase from the question] is [answer].\nIf necessary, you can polish the description.\nOnly output the Description, with Chinese language.\n\n\nThe question:\u53a6\u95e8\u5929\u6c14\u5982\u4f55\uff1f\nThe answer:The weather of Xiamen is cloudy, and the temperature is 35\u00b0C."}]}  
RESPONSE: {"model":"","object":"","choices":[{"index":0,"message":{"role":"assistant","content":"厦门天气情况是:多云,气温35°C。","function_call":null},"finish_reason":"stop"}],"queueTime":0.008246660232543945,"costTime":0.3240656852722168,"usage":{"prompt_token":143,"completion_token":12,"total_tokens":155}}  
=======================================================================  
FINAL RESULT WITH FUNCTION CALL: 厦门天气情况是:多云,气温35°C。  
  
  
Enter a string: 383加上135721等于多少?  
PAYLOAD: {"model": "", "messages": [{"role": "system", "content": "You have access to the following tools:\n[{\"name\": \"get_current_weather\", \"description\": \"Get the current weather in a given location\", \"parameters\": {\"type\": \"object\", \"properties\": {\"location\": {\"type\": \"string\", \"description\": \"The city e.g. Beijing\"}, \"unit\": {\"type\": \"string\", \"enum\": [\"celsius\"]}}, \"required\": [\"location\"]}}, {\"name\": \"calculator\", \"description\": \"\\u8ba1\\u7b97\\u5668\", \"parameters\": {\"type\": \"int\", \"properties\": {\"a\": {\"type\": \"int\", \"description\": \"the first number\"}, \"b\": {\"type\": \"int\", \"description\": \"the second number\"}}, \"required\": [\"a\", \"b\"]}}]\nYou can select one of the above tools or just response user's content and respond with only a JSON object matching the following schema:\n{\n \"tool\": <name of the selected tool>,\n \"tool_input\": <parameters for the selected tool, matching the tool's JSON schema>,\n \"message\": <direct response users content>\n}"}, {"role": "user", "content": "383\u52a0\u4e0a135721\u7b49\u4e8e\u591a\u5c11\uff1f"}]}  
RESPONSE: {"model":"","object":"","choices":[{"index":0,"message":{"role":"assistant","content":"```json\n{\"tool\": \"calculator\", \"tool_input\": {\"a\": 383, \"b\": 135721}, \"message\": null}\n```","function_call":null},"finish_reason":"stop"}],"queueTime":0.0021514892578125,"costTime":0.9161381721496582,"usage":{"prompt_token":252,"completion_token":35,"total_tokens":287}}  
=======================================================================  
PAYLOAD: {"model": "", "messages": [{"role": "user", "content": "\nPlease generate a natural language description based on the following question and answer.\nQuestion: [Content of the question]\nAnswer: [Content of the answer]\nGenerated Description: The result of [key phrase from the question] is [answer].\nIf necessary, you can polish the description.\nOnly output the Description, with Chinese language.\n\n\nThe question:383\u52a0\u4e0a135721\u7b49\u4e8e\u591a\u5c11\uff1f\nThe answer:136104"}]}  
RESPONSE: {"model":"","object":"","choices":[{"index":0,"message":{"role":"assistant","content":"383加上135721等于136104。","function_call":null},"finish_reason":"stop"}],"queueTime":0.0064160823822021484,"costTime":0.28981900215148926,"usage":{"prompt_token":134,"completion_token":11,"total_tokens":145}}  
=======================================================================  
FINAL RESULT WITH FUNCTION CALL: 383加上135721等于136104。

在这个例子中,预置了两个函数,分别为天气查询和计算器,实验效果中进行了三轮,其中第一次属于未命中函数调用的闲聊场景,后两次分别命中了天气查询和计算器。

在实际的工作中,可能需要预置非常多函数能力,此时可能需要考虑到LLM的输入token限制,必要时需要进行模块划分,将一次LLM决策转化为多次决策,更通用一点的说法就是意图层级识别。

如何学习大模型 AI ?

由于新岗位的生产效率,要优于被取代岗位的生产效率,所以实际上整个社会的生产效率是提升的。

但是具体到个人,只能说是:

“最先掌握AI的人,将会比较晚掌握AI的人有竞争优势”。

这句话,放在计算机、互联网、移动互联网的开局时期,都是一样的道理。

我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。

我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在人工智能学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多互联网行业朋友无法获得正确的资料得到学习提升,故此将并将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。

在这里插入图片描述

第一阶段(10天):初阶应用

该阶段让大家对大模型 AI有一个最前沿的认识,对大模型 AI 的理解超过 95% 的人,可以在相关讨论时发表高级、不跟风、又接地气的见解,别人只会和 AI 聊天,而你能调教 AI,并能用代码将大模型和业务衔接。

  • 大模型 AI 能干什么?
  • 大模型是怎样获得「智能」的?
  • 用好 AI 的核心心法
  • 大模型应用业务架构
  • 大模型应用技术架构
  • 代码示例:向 GPT-3.5 灌入新知识
  • 提示工程的意义和核心思想
  • Prompt 典型构成
  • 指令调优方法论
  • 思维链和思维树
  • Prompt 攻击和防范
  • …

第二阶段(30天):高阶应用

该阶段我们正式进入大模型 AI 进阶实战学习,学会构造私有知识库,扩展 AI 的能力。快速开发一个完整的基于 agent 对话机器人。掌握功能最强的大模型开发框架,抓住最新的技术进展,适合 Python 和 JavaScript 程序员。

  • 为什么要做 RAG
  • 搭建一个简单的 ChatPDF
  • 检索的基础概念
  • 什么是向量表示(Embeddings)
  • 向量数据库与向量检索
  • 基于向量检索的 RAG
  • 搭建 RAG 系统的扩展知识
  • 混合检索与 RAG-Fusion 简介
  • 向量模型本地部署
  • …

第三阶段(30天):模型训练

恭喜你,如果学到这里,你基本可以找到一份大模型 AI相关的工作,自己也能训练 GPT 了!通过微调,训练自己的垂直大模型,能独立训练开源多模态大模型,掌握更多技术方案。

到此为止,大概2个月的时间。你已经成为了一名“AI小子”。那么你还想往下探索吗?

  • 为什么要做 RAG
  • 什么是模型
  • 什么是模型训练
  • 求解器 & 损失函数简介
  • 小实验2:手写一个简单的神经网络并训练它
  • 什么是训练/预训练/微调/轻量化微调
  • Transformer结构简介
  • 轻量化微调
  • 实验数据集的构建
  • …

第四阶段(20天):商业闭环

对全球大模型从性能、吞吐量、成本等方面有一定的认知,可以在云端和本地等多种环境下部署大模型,找到适合自己的项目/创业方向,做一名被 AI 武装的产品经理。

  • 硬件选型
  • 带你了解全球大模型
  • 使用国产大模型服务
  • 搭建 OpenAI 代理
  • 热身:基于阿里云 PAI 部署 Stable Diffusion
  • 在本地计算机运行大模型
  • 大模型的私有化部署
  • 基于 vLLM 部署大模型
  • 案例:如何优雅地在阿里云私有部署开源大模型
  • 部署一套开源 LLM 项目
  • 内容安全
  • 互联网信息服务算法备案
  • …

学习是一个过程,只要学习就会有挑战。天道酬勤,你越努力,就会成为越优秀的自己。

如果你能在15天内完成所有的任务,那你堪称天才。然而,如果你能完成 60-70% 的内容,你就已经开始具备成为一名大模型 AI 的正确特征了。

这份完整版的大模型 AI 学习资料已经上传优快云,朋友们如果需要可以微信扫描下方优快云官方认证二维码免费领取【保证100%免费】
大语言模型应用指南:function calling 大语言模型应用指南:function calling 1. 背景介绍 1.1 大语言模型概述 大语言模型(Large Language Model, LLM)是近年来自然语言处理(NLP)领域最重要的突破之一。它们是在海 阅读详情

相关推荐

1.1 大语言模型调用方式与函数调用(Function Calling):从基础到实战

本文深入探讨了大语言模型(LLM)的调用方式,重点介绍函数调用(Function Calling)技术。函数调用作为LLM与外部世界交互的桥梁,使模型能够识别需要调用外部API的场景并输出规范参数。文章详细解析了OpenAI函数调用的核心原理,包括JSON Schema定义工具参数结构和Tool Call+Response Chain流程,并提供了完整的代码实现示例,展示了如何构建能够执行复杂任务的智能代理系统。通过天气查询和数据库搜索的实战案例,展示了函数调用技术的实际应用价值。

yonggeit的博客 3811

关于LLM进行函数(工具)调用的思考

拆解openai的function_call功能,理解函数调用的底层原理,然后手搓一个自定义的Agent_call_tools

weixin_65416260的博客 4371

使用Intel编译器编译OpenFOAM

本文总结了使用INTEL编译器编译OpenFOAM的过程

姜蜉蝣的博客 1551

LLM:函数调用(Function Calling)

虽然大模型能解决很多问题,但大模型并不能知晓一切。比如,大模型不知道最新消息(GPT-3.5 的知识截至 2021年9月,GPT-4 是 2023 年12月)。另外,大模型没有“真逻辑”。它表现出的逻辑、推理,是训练文本的统计规律,而不是真正的逻辑,所以有幻觉。所以大模型需要连接真实世界,并对接真逻辑系统。这就需要用到“函数调用”。让用户能够使用高效的外部工具、与外部API进行交互。函数调用(Function Calling)可以。在使用GPT模型进行函数调用时,需要用到。

读万卷书 行万里路 3826

Genesis物理引擎实战指南:轻量级确定性刚体仿真核心

刚体物理仿真作为机器人控制、嵌入式运动学验证和确定性游戏开发的基础技术,其核心在于数值稳定性、跨平台可复现性与约束求解精度。本文围绕线性互补问题(LCP)求解、半隐式欧拉积分和零依赖C++实现三大关键技术展开,解析如何在无GUI、低算力环境下构建可单步调试、帧级可控的确定性仿真系统。重点覆盖碰撞检测数学建模、关节局部坐标系绑定、质量-惯性张量一致性校验等工程落地关键点,适用于STM32、树莓派及教育实验场景。内容深度结合Genesis Physics Engine的源码实践,直击‘穿模’‘NaN’‘关节发软

ciya3282的博客 1592

树莓派驱动DLPDLCR230NPEVM+framebuffer显示图片

DLPDLCR230NPEVM DLP® LightCrafter™ Display 230NP 是一个易于使用的紧凑型即插即用评估平台,适用于消费类产品、工业、医疗和物联网 (IoT) 市场中的各种超便携显示应用。此评估模块 (EVM) 采用 DLP230NP 芯片组,该芯片组由DLP230NP.23 1080p DMD、DLPC3436显示控制器和DLPA2005PMIC/LED 驱动器组成。此 EVM 外形小巧,配备生产就绪型光学引擎以及支持 18 位 RGB 并行视频接口...

L_Y000的博客 2621

【AI大模型】如何实现LLM的通用function-calling能力?

众所周知,LLM的函数function-calling能力很强悍,解决了大模型与实际业务系统的交互问题。其本质就是函数调用。

2401_85325557的博客 1294

ransac拟合2D圆(三点定圆 c++详细版)

RANSAC(Random Sample Consensus,随机采样一致性)算法是一种基于随机采样的迭代算法,主要用于从一组包含大量噪声和异常值(外点)的数据中估计数学模型的参数。

twnkie的博客 1048

Function Calling:大语言模型与外部系统交互的标准化协议

大语言模型(LLM)作为当前人工智能的核心技术,其核心能力在于理解和生成自然语言。然而,要让LLM从“思考者”转变为“执行者”,需要解决其与外部系统交互的“最后一公里”问题。Function Calling(函数调用)正是为此设计的标准化协议,它通过一套结构化机制,让LLM能够理解、选择并请求调用预定义的外部函数或API。这项技术的核心价值在于将开放域的自然语言交互转化为封闭域、格式确定的函数调用,从而极大提升了AI应用与真实世界互动的可靠性和效率。在工程实践中,Function Calling已成为构建智

weixin_34269583的博客 343

详解Agent Skills:让AI拥有更多专业能力(什么是Agent Skills?如何创建?如何使用?如何获取?)

本文分享如何将零散指令沉淀为可复用的 AI 能力模块🧩,介绍什么是Agent Skills?如何创建?如何获取?📚

XiaoqiangClub的博客 1272

Python接入企业微信群机器人图文教程,实现恐贪指标自动触发微信消息提醒功能!Python 企业微信 群机器人 消息提醒 Webhook 企业微信接口

✅ 企业微信群机器人的添加方式;✅ 如何获取 Webhook 地址;✅ Python 如何用 requests 发消息;✅ 如何在实际业务中触发自动提醒;这种方式不仅适合个人开发者、测试人员,也适用于小团队、运维通知等场景,部署简单、触发灵活、响应及时!

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 916

第2篇:Tools 与 MCP —— 让 LLM 从“只会说“变成“能做事“

本文探讨了大型语言模型(LLM)工具集成的演进过程。传统Function Calling方式存在N×M的集成复杂度问题,不同厂商API互不兼容。Anthropic开源的MCP协议通过基于JSON-RPC 2.0的标准协议,将复杂度降至N+M,实现了工具调用的标准化。MCP采用三层架构(Host→Client→Server),支持工具、资源和提示词三类能力的暴露。与CLI方式相比,MCP更适合长期维护和参数化操作。但文章也指出,当工具数量超过15个时,LLM的选择准确率会显著下降,此时需要采用Skill打包多

HICKER_BOY的博客 633

QQ也能连接OpenClaw啦!手机QQ远程操控本地AI保姆级教程

2026年最新OpenClaw与QQ连接教程发布,支持手机远程操控本地AI。腾讯官方推出QQ Bot插件,无需服务器即可实现三步绑定。教程提供三种连接方案:新手首选的扫码连接(10分钟搞定)、稳定的QQ群机器人方案,以及公网接入方案。详细步骤包括版本更新、插件安装、扫码绑定和功能测试,并附常见问题解决方案。该功能让用户通过QQ指令即可实现文件整理、文档生成等电脑操作,真正实现"手机发指令,电脑自动干"。

通俗易懂学IT 594

LLM、GPT与Agent:从原理到落地的完全指南

大语言模型(LLM)正成为人工智能领域的基础设施,而GPT作为其最具代表性的技术路线,让机器具备了接近人类的语言理解与生成能力。然而,真正让LLM从“会聊天”走向“会干活”的,是Agent架构的兴起——它通过规划、工具调用与记忆机制,将模型能力转化为实际任务执行。理解Token、上下文窗口、温度参数等核心概念,是掌握大模型应用开发的起点。在此基础上,RAG(检索增强生成)技术解决了私有知识库接入的现实需求,而Dify等低代码平台则大幅降低了Agent与工作流的搭建门槛。从API调用到本地部署,从提示词工程到

weixin_33402252的博客 217

Unity零基础到进阶 | Unity 探针系统深度解析:光照探针、反射探针与相关技术

在 Unity 渲染管线中,探针(Probe) 是一类通过预计算或实时采样来捕捉空间光照信息的核心组件。它们弥补了传统静态光照贴图和实时光源各自的局限性,是实现高质量、高性能全局光照效果的关键工具。 本文将系统介绍光照探针(Light Probe)和反射探针(Reflection Probe)的作用与用法,分析二者之间的协同关系,并延伸介绍自适应探针体积(APV)、光照探针代理体(LPPV)、探针体积等进阶技术。

努力前行,总会成为自己心中的那道光 1万+

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

AI Agent 是怎么“想一步做一步“的?拆解 ReAct 模式

就是 ReAct 的"工作记忆"。它之所以成为 90% 生产级 Agent 的默认架构,就是因为这个"想→做→看"的循环足够通用——不管你的任务是查天气、做研究、写代码还是排查 bug,都可以用这个模式来处理。比如工具返回了一堆 HTML 或者报错的 stack trace,LLM 不知道该怎么理解这个结果,就决定"再试一次"——然后又得到一样的结果——然后又"再试一次"……:给 Agent 提供"退路"。这就是从"单 Agent + 多工具"到"多 Agent 协作"的演进方向,后面的文章会专门讲。

LuckyWinty的博客 368

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

07—langchain Agent

文章摘要 Agent(智能体)是一种通过协调大语言模型(LLM)和工具(Tools)来完成复杂任务的智能系统。与固定流程的Chain不同,Agent具备自主决策能力,能动态决定任务分解、工具调用顺序等。其核心组件包括:LLM(推理大脑)、记忆系统、工具集、规划能力和行动执行。 Agent分为两种工作模式: Function Call模式:结构化函数调用,高效但需特定LLM支持 ReAct模式:自然语言推理,更具解释性但延迟较高 创建方式包括传统initialize_agent()和更灵活的AgentExec

m0_65519288的博客 860

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LLM的工具调用能力(如Function Calling)

核心机制LLM通过生成符合工具接口的指令(如JSON参数),触发外部工具执行。例如,用户提问天气时,模型生成{"location": "北京", "date": "2025-03-22"},系统调用天气API获取数据。分工明确:LLM仅负责决策和参数生成,实际执行由业务系统完成。技术演进提示工程:通过Few-shot示例引导模型输出特定格式(如ReAct框架)。例如,动态选择语义相似的示例可提升准确率。模型微调:如Toolformer模型通过插入API调用标记训练LLM,使其自主决定何时调用工具。

u010249118的博客 1438

这篇文章终于讲清楚了MCP与Function Calling的关系!

自从大语言模型(LLM)横空出世以来,如何将 LLM 与现有商业系统有效结合、让其真正赋能各类业务,已成为当前最热门的研究方向之一。

m0_59163425的博客 6724

Tool Calling/Function Calling

LLM 是一个"只会说话的大脑",Function Calling 就是给它装上了"手"。场景没有 Function Calling有 Function Calling你问“今天北京天气怎么样?“今天北京天气怎么样?LLM回答“我不知道,我的知识截止到2023年…”心里想:用户要查天气 → 我该调 get_weather() 函数 → 返回结果:“北京今天晴,25°C”本质:LLM 不自己回答,而是决定"该调用哪个函数",然后把结果拿回来说给你听。把 LLM 想象成一个。

Ycy的博客 407

一文读懂 LLM 核心技术栈:LLM、RAG、Function Calling、MCP 与 Agent

作为一名开发者,你是否曾被大语言模型(LLM)生态中层出不穷的术语搞得晕头转向?RAG、Function Calling、Agent、MCP... 这些概念听起来高大上,但它们究竟解决了什么问题?它们之间又是如何协作的? 在这篇文章中,我们将用最直白的语言和代码对比,为你揭示 LLM 技术栈的完整拼图。

st_andrews的博客 1450

Function Calling 和 MCP的区别

Function Calling 和 MCP的区别

core815的专栏 1859

Tool Calling 与 Function Call 深度指南

AI Agent通过Tool Calling赋予大语言模型(LLM)连接外部世界的能力。本文解析了两种实现方式:早期不稳定的Prompt Engineering和现代标准化的Function Calling。后者通过JSON Schema定义工具,LLM生成结构化指令,由外部程序执行具体操作。文章详细展示了工作流程、数据结构,并提供了LangChain实现的代码示例,说明如何让LLM识别数学计算需求、调用乘法工具并返回结果。随着技术发展,AI正从单一工具调用向自主规划的多轮Agent交互演进。

nvd11的专栏 3333
上一篇: 【大模型技术】什么时候需要训练和微调属于自己的大模型——小微企业必须要明白的问题
下一篇: 0基础也可以转行做产品经理吗?
爱喝白开水a
博客等级 码龄3年 6793粉丝 763原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值