news 2026/9/11 9:42:35

掌握大语言模型提示词工程:利用工具实现自动推理的高效教程!

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
掌握大语言模型提示词工程:利用工具实现自动推理的高效教程!

Function/Tool Calling

@openai: 函数调用为 OpenAI 模型提供了一种强大而灵活的方式,可以与您的代码或外部服务进行交互。通过函数调用,您可以向 Assistant 描述函数,并让其智能地返回需要调用的函数及其参数。@openai

@langchain: 我们将“工具调用”与“函数调用”互换使用。虽然“函数调用”有时指的是单个函数的调用,但我们将所有模型视为可以在每条消息中返回多个工具或函数调用。

工具调用与 ReACT 的区别

项目ReAct 提示词工程Function Calling
核心思想用提示词引导模型「推理 + 行动 + 观察反馈」循环明确声明函数签名,模型调用结构化函数
技术机制Prompt 模板控制流程,如:Think -> Act -> Obs通过函数描述注册函数接口,模型自动生成调用参数
环境交互灵活性高:适用于复杂多步任务、agent 类流程中:适合明确定义的单步工具调用
开发复杂度中:需要精心设计提示词模板与中间状态管理低~中:注册函数较直接,但需要参数与返回值处理
典型应用场景多步推理、多工具交替使用、信息抽取等复杂场景明确 API 调用、数据库查询、插件系统等
与 Agent 框架集成度高:常用于 LangChain、AutoGPT 中的推理行为生成高:OpenAI、LangChain、Claude 支持直接注册使用
优缺点总结✅ 灵活可控✅ 自动结构化调用
❌ 难以规模化自动解析❌ 不擅长多步控制与反馈处理

function calling 核心概念

  • tools: 函数列表
  • function: 单个函数定义
  • function.name: 函数名字
  • function.description: 函数作用描述
  • parameters: 函数形参说明
"tools": [ { "type": "function", "function": { "name": "current_time", "description": "A tool for getting the current time.", "parameters": { "properties": {}, "required": [], "type": "object" } } }, { "type": "function", "function": { "name": "simple_code", "description": "A tool for running code and getting the result back. Only native packages are allowed, network/IO operations are disabled. and you must use print() or console.log() to output the result or result will be empty.", "parameters": { "properties": { "code": { "description": "code to be executed, only native packages are allowed, network/IO operations are disabled.", "type": "string" }, "language": { "description": "language of the code, only \"python3\" and \"javascript\" are supported", "type": "string" } }, "required": ["language", "code"], "type": "object" } } }]

工具调用的返回格式

  • tool_calls: 工具调用序列,单个或者多个
  • function 函数调用
  • function.name 函数名字
  • function.arguments 函数实参
"message": { "role": "assistant", "content": "", "tool_calls": [ { "function": { "name": "simple_code", "arguments": { "code": "print(0.9111 ** 3)", "language": "python3" } } } ] }

常用工具

  • 代码解析器 python node
  • 命令解析器 bash
  • 文件管理 file directory
  • 浏览器控制 browser use
  • 外部接口 openapi swagger
  • 大模型上下文协议 MCP playwright-mcp

python 工具调用示例

没有工具调用的对话模型

使用工具可以获得更加准确的结果

带有 function call 的请求

{ "model": "qwen3","stream": false,"options": { "temperature": 0 },"messages": [ { "role": "system", "content": "/no_think\n" }, { "role": "user", "content": "使用python计算 0.9111**3=" } ],"tools": [ { "type": "function", "function": { "name": "current_time", "description": "A tool for getting the current time.", "parameters": { "properties": {}, "required": [], "type": "object" } } }, { "type": "function", "function": { "name": "simple_code", "description": "A tool for running code and getting the result back. Only native packages are allowed, network/IO operations are disabled. and you must use print() or console.log() to output the result or result will be empty.", "parameters": { "properties": { "code": { "description": "code to be executed, only native packages are allowed, network/IO operations are disabled.", "type": "string" }, "language": { "description": "language of the code, only \"python3\" and \"javascript\" are supported", "type": "string" } }, "required": ["language", "code"], "type": "object" } } } ]}

大模型的响应

{ "model": "qwen3","created_at": "2025-05-05T16:57:36.016688Z","message": { "role": "assistant", "content": "", "tool_calls": [ { "function": { "name": "simple_code", "arguments": { "code": "print(0.9111 ** 3)", "language": "python3" } } } ] },"done_reason": "stop","done": true,"total_duration": 2037533417,"load_duration": 34440000,"prompt_eval_count": 275,"prompt_eval_duration": 776227166,"eval_count": 42,"eval_duration": 1225024292}

最终请求

{ "model": "qwen3","stream": false,"options": { "temperature": 0 },"messages": [ { "role": "system", "content": "/no_think\n" }, { "role": "user", "content": "使用python计算 0.9111**3=" }, { "role": "assistant", "content": "" }, { "role": "tool", "content": "0.756307034631\n" } ],"tools": [ { "type": "function", "function": { "name": "current_time", "description": "A tool for getting the current time.", "parameters": { "properties": {}, "required": [], "type": "object" } } }, { "type": "function", "function": { "name": "simple_code", "description": "A tool for running code and getting the result back. Only native packages are allowed, network/IO operations are disabled. and you must use print() or console.log() to output the result or result will be empty.", "parameters": { "properties": { "code": { "description": "code to be executed, only native packages are allowed, network/IO operations are disabled.", "type": "string" }, "language": { "description": "language of the code, only \"python3\" and \"javascript\" are supported", "type": "string" } }, "required": ["language", "code"], "type": "object" } } } ]}

最终响应

{ "model": "qwen3","created_at": "2025-05-05T16:57:37.121945Z","message": { "role": "assistant", "content": "<think>\n\n</think>\n\n0.9111 raised to the power of 3 is approximately **0.7563**." },"done_reason": "stop","done": true,"total_duration": 1030672292,"load_duration": 11999667,"prompt_eval_count": 303,"prompt_eval_duration": 122764292,"eval_count": 29,"eval_duration": 892274041}

说真的,这两年看着身边一个个搞Java、C++、前端、数据、架构的开始卷大模型,挺唏嘘的。大家最开始都是写接口、搞Spring Boot、连数据库、配Redis,稳稳当当过日子。

结果GPT、DeepSeek火了之后,整条线上的人都开始有点慌了,大家都在想:“我是不是要学大模型,不然这饭碗还能保多久?”

我先给出最直接的答案:一定要把现有的技术和大模型结合起来,而不是抛弃你们现有技术!掌握AI能力的Java工程师比纯Java岗要吃香的多。

即使现在裁员、降薪、团队解散的比比皆是……但后续的趋势一定是AI应用落地!大模型方向才是实现职业升级、提升薪资待遇的绝佳机遇!

这绝非空谈。数据说话

2025年的最后一个月,脉脉高聘发布了《2025年度人才迁徙报告》,披露了2025年前10个月的招聘市场现状。

AI领域的人才需求呈现出极为迫切的“井喷”态势

2025年前10个月,新发AI岗位量同比增长543%,9月单月同比增幅超11倍。同时,在薪资方面,AI领域也显著领先。其中,月薪排名前20的高薪岗位平均月薪均超过6万元,而这些席位大部分被AI研发岗占据。

与此相对应,市场为AI人才支付了显著的溢价:算法工程师中,专攻AIGC方向的岗位平均薪资较普通算法工程师高出近18%;产品经理岗位中,AI方向的产品经理薪资也领先约20%。

当你意识到“技术+AI”是个人突围的最佳路径时,整个就业市场的数据也印证了同一个事实:AI大模型正成为高薪机会的最大源头。

最后

我在一线科技企业深耕十二载,见证过太多因技术卡位而跃迁的案例。那些率先拥抱 AI 的同事,早已在效率与薪资上形成代际优势,我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在大模型的学习中的很多困惑。

我整理出这套 AI 大模型突围资料包【允许白嫖】:

  • ✅从入门到精通的全套视频教程

  • ✅AI大模型学习路线图(0基础到项目实战仅需90天)

  • ✅大模型书籍与技术文档PDF

  • ✅各大厂大模型面试题目详解

  • ✅640套AI大模型报告合集

  • ✅大模型入门实战训练

这份完整版的大模型 AI 学习和面试资料已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费】

①从入门到精通的全套视频教程

包含提示词工程、RAG、Agent等技术点

② AI大模型学习路线图(0基础到项目实战仅需90天)

全过程AI大模型学习路线

③学习电子书籍和技术文档

市面上的大模型书籍确实太多了,这些是我精选出来的

④各大厂大模型面试题目详解

⑤640套AI大模型报告合集

⑥大模型入门实战训练

👉获取方式:
有需要的小伙伴,可以保存图片到wx扫描二v码免费领取【保证100%免费】🆓

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/1 7:15:28

拼多多主体变更公证流程是什么?新手商家常忽略的3个关键步骤

一、前言&#xff1a;多数商家卡公证的核心原因 很多新手拼多多商家在做店铺主体变更时&#xff0c;普遍存在认知误区&#xff0c;认为私下签署转让协议即可完成变更&#xff0c;殊不知平台仅认可合规公证书。不少商家因不懂平台规则、文书格式不符、材料准备出错&#xff0c;…

作者头像 李华
网站建设 2026/9/2 14:04:07

多智能体系统迁移时如何保持旧链路可用

多智能体系统迁移时如何保持旧链路可用在 AI Agent 项目的研发与工程演进中&#xff0c;Python 依赖管理与基础设施重构是系统稳定性的重要保障。 维护基于 LangChain、LlamaIndex 或 PyTorch 的 Agent 系统时&#xff0c;常常由于环境依赖配置不一致导致本地与 CI/CD 构建结果…

作者头像 李华
网站建设 2026/9/7 15:13:17

【收藏级教程】小白也能看懂的多模态表示:CLIP与MoCo技术详解

什么是多模态表示&#xff1f; 简单来说&#xff0c;多模态 是一门研究如何理解和处理不同类型数据&#xff08;比如文字、图片、声音&#xff09;的科学&#xff0c;这些数据虽然形式各异&#xff0c;但内部紧密关联。 它的核心目标是&#xff1a;将这些五花八门的信息融合成一…

作者头像 李华