Anthropic Tools: Say Goodbye to Traditional Function Calling

Mervin Praison
6 Mar 202405:31

Summary

TLDR这个视频教程向观众展示了如何使用Anthropic工具简化与Anthropic AI模型Claude进行功能调用的过程。首先,演示了如何从GitHub克隆Anthropic工具库并安装必要的依赖项。然后,通过设置工具名称、描述和参数,创建了一个简单的加法工具。最后,演示了如何将此工具分配给Claude,并要求其解决一个涉及水果计数的问题。总的来说,该教程向观众介绍了使用Anthropic工具的基本流程,这种方式比传统的功能调用更加简单高效。

Takeaways

  • 🤖 本视频介绍了 Anthropic 工具的使用, 可以简化函数调用的过程。
  • 📝 首先需要克隆 github.com/anthropic/anthropic-tools 仓库, 安装相关依赖。
  • ✏️ 接着在 app.py 中从 tools 包导入 base_tool 和 tool_user。
  • ➕ 定义了一个加法工具, 可以将两个数相加。
  • 🔖 为工具添加名称、描述和参数说明, 以帮助 AI 理解工具的功能。
  • 🧩 将定义好的工具添加到 tool_user 中。
  • ✉️ 在 messages 变量中提出一个需要计算的问题。
  • 🚀 调用 tool_user.use_tools 来执行任务, 传入 messages 和执行模式。
  • 💻 运行 app.py 后可以看到正确的计算结果。
  • 🌐 其他示例工具包括天气、转换器、维基百科搜索等, 可供进一步尝试。

Q & A

  • 什么是Anthropic工具?

    -Anthropic工具是一种简化函数调用过程的方法,可以让你直接将自己的函数或知识库集成到大型语言模型中,而不需要处理繁琐的XML标记。

  • 为什么需要Anthropic工具?

    -大型语言模型在处理一些任务时表现不佳,比如数学计算。通过Anthropic工具,我们可以将自定义功能集成到语言模型中,弥补其不足。

  • 使用Anthropic工具有哪些步骤?

    -一共有三个步骤:1.创建工具及其描述 2.将工具添加到Anthropic API 3.要求语言模型执行任务

  • 视频中演示的是什么样的工具?

    -视频中演示的是一个加法计算工具,可以将两个数字相加。

  • Anthropic工具是如何与语言模型交互的?

    -通过ToolUser包中的代码,Anthropic工具会将请求发送到API,语言模型会根据工具的功能给出响应。

  • Anthropic工具有哪些优势?

    -Anthropic工具使得集成自定义功能变得非常简单,无需处理复杂的XML标记,可以更高效地利用语言模型的能力。

  • 除了加法工具,视频中还提到了哪些其他工具?

    -视频中还提到了天气工具、信息API转换工具、计算器工具、维基百科搜索工具、Brave搜索工具、ElasticSearch工具和SQL工具。

  • 如何创建自定义的Anthropic工具?

    -你需要从basetools包导入BaseTools类,定义工具的名称、描述和参数,然后将其添加到ToolUser中。

  • 为什么大型语言模型在处理某些任务时表现不佳?

    -大型语言模型通常在某些特定领域或需要外部数据源的任务中表现不佳,这就是需要Anthropic工具来弥补不足的原因。

  • 除了提供的示例,Anthropic工具还可以用于哪些其他场景?

    -Anthropic工具可以用于各种需要调用外部API、数据库或其他服务的场景,为语言模型提供更强大的功能扩展。

Outlines

00:00

🔑 介紹 Anthropic 工具

本段詳細介紹了 Anthropic 工具的概念,並說明了它如何簡化函數調用的過程。作者還提到,他將逐步講解如何創建 Anthropic 工具、設置工具描述、將工具添加到 Anthropic API 中以及執行任務。同時,作者邀請觀眾訂閱他的 YouTube 頻道以獲取更多關於人工智能的視頻內容。最後,他演示了如何設置 Python 開發環境、導入所需的包以及創建一個新文件 app.py 供後續編碼使用。

05:01

🏁 總結和呼籲參與

本段總結了前面介紹的 Anthropic 工具,並讚揚了它簡化函數調用的優勢。作者提到 Anthropic 還提供了其他工具樣例供用戶嘗試,如天氣工具、消息 API 轉換工具、計算器工具等。最後,作者鼓勵觀眾在評論區分享對本教程的反饋,並宣佈了他計劃製作更多類似的視頻內容,敦促觀眾訂閱他的頻道,對視頻點贊。

Mindmap

Keywords

💡anthropic 工具

该视频主要介绍了 Anthropic 公司新推出的 AI 工具。Anthropic 工具是一种简化人工智能模型功能调用的新方式,它能够通过定义工具并添加到 Anthropic API 中,从而直接与语言模型交互以完成特定任务。例如,视频中展示了如何创建一个"加法工具"用于计算两个数字的和。这种工具使用更加简单直观,而无需手动处理 XML 标签和响应解析等复杂步骤。

💡功能调用

功能调用是指调用外部函数或工具来完成特定任务。在人工智能领域,功能调用通常指将语言模型与外部知识库、计算工具或服务集成,以扩展模型的能力。视频中提到,以前的功能调用方式需要手动处理 XML 标签和解析响应,而新的 Anthropic 工具则简化了这一过程。

💡cloe

Cloe 是 Anthropic 公司开发的人工智能语言模型。正如视频所述,之前的教程演示了如何在 Cloe 中进行功能调用。而新的 Anthropic 工具则提供了一种更简单的方式来与 Cloe 模型集成外部工具和功能。

💡api

API(应用程序编程接口)是软件系统与外部工具或服务进行交互的接口。视频演示了如何通过导入并设置 Anthropic API 密钥,然后将定义好的工具添加到 API 中,从而实现与语言模型 Cloe 的无缝集成。这种基于 API 的集成方式提供了灵活性和可扩展性。

💡git克隆

Git 克隆是从远程代码库中复制代码到本地的过程。视频中的第一步就是运行 "git clone" 命令从 Anthropic 的 GitHub 仓库中获取 Anthropic 工具的源代码。这是开始使用该工具的必要步骤。

💡python 环境

Python 环境是指运行 Python 代码所需的依赖库和配置。视频演示了如何使用 conda 创建一个新的 Python 3.11 环境,并将其命名为"anthropic"。这确保了代码在干净隔离的环境中运行,避免与系统上其他 Python 包产生冲突。

💡安装依赖

安装依赖指的是安装运行代码所需的外部 Python 包。在视频中, "pip install -r requirements.txt" 命令用于一次性安装 Anthropic 工具所依赖的所有第三方 Python 包。这确保了代码可以正常运行。

💡工具描述

工具描述是对将要添加到 Anthropic API 中的工具进行的文字描述。在视频代码中,工具描述"Add one number to another number returning a + b"解释了加法工具的功能,使语言模型能够理解该工具的用途。合理的工具描述对于模型正确使用工具至关重要。

💡自动执行模式

自动执行模式是 Anthropic 工具中的一种运行方式。在视频示例中,代码通过"execution_mode='automatic'"参数指定了自动执行模式。这意味着 Cloe 模型将自动识别出需要使用加法工具来计算的情况,而无需人为指示。自动模式提高了使用效率。

💡github

GitHub 是一个面向开源及私有软件项目的托管平台,被广泛用于代码存储、版本控制和协作开发。视频中提到从 Anthropic 的 GitHub 仓库 "github.com/anthropics/anthropic-tools" 克隆工具代码,这说明工具源代码是开源和公开的。

Highlights

This video demonstrates how to use Anthropic Tools to simplify the process of function calling with Claude.

The first step is to create a tool by defining its functionality, such as an addition tool that adds two numbers.

The second step is to create a description for the tool to help Claude understand what the tool does.

The third step is to assign the tool to Claude and provide a task that requires the tool's functionality.

The video shows how to set up the project environment, including cloning the Anthropic Tools repository, creating a virtual environment, and installing the required packages.

The video demonstrates running the code with the addition tool and how Claude uses the tool to solve a word problem involving addition.

The video highlights that Anthropic Tools simplify the process of function calling by handling the heavy lifting of parsing XML values, making API calls, and defining the model.

The video mentions that Anthropic Tools provide various example tools, such as weather, message API converter, calculator, Wikipedia search, Brave search, Elasticsearch, and SQL tools.

The video encourages viewers to try the example tools and provide feedback in the comments.

The video is part of a series on Artificial Intelligence, and the creator regularly creates videos on this topic.

The video emphasizes the importance of subscribing, clicking the bell icon, and liking the video to stay updated and support the creator's efforts.

The video provides step-by-step instructions for setting up the project environment and running the code with the addition tool.

The video explains how the code is structured, with the base_tool package handling the tool functionality and the tool_user package interacting with the Claude API.

The video demonstrates how to define the tool parameters, including the expected data types.

The video showcases the log output that displays each time Claude calls the addition tool, providing transparency into the tool's usage.

Transcripts

play00:00

this is amazing now we have anthropic

play00:02

tools from anthropic so what is

play00:05

anthropic tool this is similar to

play00:07

function calling but simplifies the

play00:10

process of function calling I've already

play00:11

covered how to do function calling in

play00:13

anthropic Cloe in my previous video

play00:15

which I will link that in the

play00:16

description below in function calling

play00:18

you can see a lot of XML tags we need to

play00:21

think about we need to pause these XML

play00:24

tags then calculate to get a final

play00:27

response but this anthropic tool will

play00:30

simplify all that work that's exactly

play00:33

what we're going to see today let's get

play00:35

[Music]

play00:37

started hi everyone I'm really excited

play00:39

to show you about anthropic Tools in

play00:42

this we are going to cover how to create

play00:44

anthropic tool set tool description add

play00:47

the tool to anthropic API and finally

play00:50

perform a task I'm going to take you

play00:52

through step by step but before that I

play00:54

regularly create videos in regards to

play00:55

Artificial Intelligence on my YouTube

play00:57

channel so do subscribe and click the

play00:59

Bell icon to stay stay tuned make sure

play01:00

you click the like button so this video

play01:02

can be helpful for many others like you

play01:04

first git clone github.com

play01:06

anthropics anthropic tools and then

play01:08

click enter next navigate to the

play01:10

anthropic tools folder now cond create

play01:13

hyphen and anthropic python 311 and then

play01:15

click enter Now cond activate anthropic

play01:18

and click enter export your anthropic AP

play01:21

key like this and then click enter now

play01:22

pip install hyphen requirements.txt and

play01:25

then click enter now let's create a file

play01:27

called app.py and let's open it so if

play01:29

you see anthropic tools folder this is

play01:31

how it will look like in the tool use

play01:34

package you have tool user and inside

play01:37

the tools folder we have base tool so

play01:40

these are the two packages which we are

play01:41

going to use base tool and Tool user

play01:44

tool user calls the API using base tool

play01:48

we are going to create a tool so inside

play01:50

app.py from Tool use package tool base

play01:54

tool and import base tool next importing

play01:57

tool user so the first step defining the

play02:00

tool we are going to create a addition

play02:03

tool this is going to add two numbers

play02:05

together which you can see here return a

play02:08

plus b a simple tool so as you probably

play02:11

know function calling is integrating

play02:13

your own function or own tool own

play02:15

knowledge base own rag with a lar

play02:18

language model now second step we need

play02:20

to create description for the tool so

play02:23

this is used by the L language model to

play02:25

understand what this tool does so name

play02:28

of the tool is perform addition tool

play02:30

description is add one number to another

play02:33

number returning a plus b next tool

play02:36

parameters A and B both float which

play02:40

means number in simple terms now we

play02:42

defining the addition tool and pausing

play02:44

the addition tool name addition tool

play02:47

description and addition tool parameters

play02:50

all three together like this now the

play02:53

third step is to assign the tool and ask

play02:55

clo to perform a task so as mentioned

play02:57

before tool user is is where the API

play03:01

request to Cloe happens so we defining

play03:04

that and adding the tool here next we

play03:07

are giving a task it is listed in the

play03:11

messages variable here you can see as a

play03:13

user that is me I'm asking Cloe John has

play03:17

three apples Maggie has nine apples Tim

play03:21

has four bananas if John gives Maggie

play03:23

one apple and Tim gives John two bananas

play03:27

how much total fruits does each person

play03:30

have so as you properly know large

play03:32

language model are not good at

play03:34

mathematical calculation so we need to

play03:36

have a tool to perform this task so

play03:39

that's why we added this addition tool

play03:42

now finally we are going to initiate by

play03:45

calling tool user.use tools and passing

play03:48

the messages execution mode is automatic

play03:51

that's it only three section first we

play03:53

created a tool this could be your own

play03:56

tool our own software then we Define a

play03:58

description for the tool thirdly we

play04:01

assign that tool and asking Cloe to

play04:04

complete this task now we are going to

play04:06

run this code in your terminal Python

play04:08

app.py and then click enter now you can

play04:10

see it's adding three and minus one so

play04:13

I've added the log here so that's what

play04:16

it's printing here so each and every

play04:18

single time Cloe is calling this tool

play04:21

that is the time it is getting printed

play04:23

here so now it's calculating using this

play04:25

calculator tool and finally here is the

play04:27

answer in summary John has four total

play04:30

fruits two apples and two bananas Maggie

play04:34

has 10 apples Tim has two bananas that

play04:37

is correct using anthropic tools is the

play04:41

most simple approach in regards to do

play04:44

function calling in anthropic clo this

play04:47

is just a basic example now to show the

play04:49

files you can see in this tool use

play04:51

package this tool user is doing all the

play04:54

heavy lifting of parsing those XML

play04:57

values which we saw previous ly making

play05:00

the API call defining the model and much

play05:03

more you also have many other example

play05:06

tools which you can try which is the

play05:09

weather tool messages API converter tool

play05:12

calculator tool Wikipedia search tool

play05:15

Brave Search tool elastic search tool

play05:17

SQL tool now you can try and let me know

play05:20

in the comments below what you think

play05:22

about this I'm really excited about this

play05:24

I'm going to create more videos similar

play05:25

to this so stay tuned I hope you like

play05:28

this video do like sh subscribe and

play05:30

thanks for watching

Rate This

5.0 / 5 (0 votes)

Related Tags
教程视频Anthropic ToolsClaude模型函数集成自定义工具简化API代码示例AI开发Python编程人工智能
Do you need a summary in English?