当前位置: 首页 > news >正文

[GenAI] Function Calling

image-20250707152011083

前面是通过 提示词 的形式,将工具箱带过去。

🙋这种方式有什么问题?

  1. 繁琐:大段大段的提示词,仅仅是为了约束大模型的输出
  2. 不标准:每个开发者的提示词的描述千差万别
  3. 约束力不高:即便使用了语气最重的提示词,大模型的底层原理决定了它总会有不按照要求回复的情况

为了解决这个问题,OpenAI 出手了,在 2023 年 6 月推出了 Function Calling,通过 JSON Schema 格式来进行标准化,主要标准两个部分:

  1. 工具箱的提供

    // 工具箱
    const tools = [{type: "function",name: "get_weather",description: "Get current temperature for provided coordinates in celsius.",parameters: {type: "object",properties: {latitude: { type: "number" },longitude: { type: "number" }},required: ["latitude", "longitude"],additionalProperties: false},strict: true
    }];
    
  2. 返回的调用工具请求

    [{"type": "function_call","id": "fc_12345xyz","call_id": "call_12345xyz","name": "get_weather","arguments": "{\"latitude\":48.8566,\"longitude\":2.3522}"
    }]
    

可以在 OpenAI 官方文档 看到这个过程,也可以在 Playground 这里体验整个过程。

🤔 为什么采用 Function Calling 能约束大模型,让它要一定按照要求输出一个 JSON ?

其实就是大模型微调的效果。

也正因为如此,并非所有的模型都支持 Function Calling,可以在 Hugging Face 上面查询某一模型是否支持 Function Calling 特性。

[!note]

Hugging Face 是目前最主流的开源 AI 模型托管与使用平台,相当于 AI 界的 Github.

注意不同的模型,Function Calling的格式不一致。

deepseek

tools = [{"type": "function","function": {"name": "get_weather","description": "Get weather of an location","parameters": {"type": "object","properties": {"location": {"type": "string","description": "The city and state, e.g. San Francisco, CA",}},"required": ["location"]},}
}]

GPT

const tools = [{type: "function",name: "get_weather",description: "Get current temperature for provided coordinates in celsius.",parameters: {type: "object",properties: {latitude: { type: "number" },longitude: { type: "number" }},required: ["latitude", "longitude"],additionalProperties: false},strict: true
}];

claude

"tools": [{"name": "get_weather","description": "Get the current weather in a given location","input_schema": {"type": "object","properties": {"location": {"type": "string","description": "The city and state, e.g. San Francisco, CA"}},"required": ["location"]}
}],

我们使用 deepseek 模型:https://api-docs.deepseek.com/guides/function_calling


-EOF-

http://www.wxhsa.cn/company.asp?id=2965

相关文章:

  • form表单
  • 【Zotero7】使用Attanger和百度同步空间如何进行同步?
  • XSS 漏洞挖掘学习
  • str
  • 到底该用 KPI 还是 OKR ?
  • 【重点!!!】必知必会必须掌握的serializers序列化器类之Serializer和ModelSerializer核心区别
  • StringUtils.isNotBlank和StringUtils.isNotEmpty的区别
  • ECT-OS-JiuHuaShan框架元推理,已在DeepSeek上实现agi
  • 9.13CSP-S Day6 模拟赛
  • 助教工作总结
  • 了解一下Redis Stack扩展功能
  • 游戏运行库合集 集成VC++、.NET、DirectX、XNA等千款组件,一键安装游戏必备依赖库 - 指南
  • 【CE】图形化CE游戏教程通关手册 - 详解
  • GZHOIOJ律(三)
  • visual studio 切换重载
  • [AGC022F] Checkers 题解
  • 程序员的副业变现之路:我的双平台矩阵打法
  • Python 潮流周刊#119:Google 停止开发 Pytype!
  • 利用k8s client-go库创建CRD的informer的操作流程
  • Golang并发编程及其高级特性
  • 单个光子的行为、传播特性、物质相互作用及其应用就是[光学原理与应用-449]:量子光学 - 量子光学研究的
  • 和为 K 的子数组-leetcode
  • 元推理agi不是象人思维,而是教人思维,人类脸上挂不住啊
  • 《10人以下小团队管理手册》读后感
  • GZHOIOJ律(二)
  • 优惠券
  • GZHOIOJ律(一)
  • 基于ArcGIS Pro SDK 3.4.2 + C# + .NET 8 的自动化制图系统初探
  • Kali Linux 虚拟机安装(VMware Workstation 17)
  • 单例模式:线程安全,以及volatile关键字