Skip to content

非公式 / UnofficialCloudflare, Inc. 非提携。アカウント情報は入力しないでください。Not affiliated with Cloudflare, Inc. Do not enter Cloudflare credentials here.Official docsこのサイトについてプライバシー

従来方式

最終更新 Markdown で表示Agent セットアップ

このページでは、業界標準に沿った従来方式の function calling の手順を説明します。Workers AI では 埋め込み function calling も使えます。従来方式より大幅に簡単です。

従来方式の function calling では、名前、説明、ツール引数を持つツールの配列を定義します。次の例は、推論リクエストで getWeather というツールをモデルに渡す方法です。

Traditional function calling examplejs
const response = await env.AI.run("@hf/nousresearch/hermes-2-pro-mistral-7b", {
	messages: [
		{
			role: "user",
			content: "what is the weather in london?",
		},
	],
	tools: [
		{
			name: "getWeather",
			description: "Return the weather for a latitude and longitude",
			parameters: {
				type: "object",
				properties: {
					latitude: {
						type: "string",
						description: "The latitude for the given location",
					},
					longitude: {
						type: "string",
						description: "The longitude for the given location",
					},
				},
				required: ["latitude", "longitude"],
			},
		},
	],
});

return new Response(JSON.stringify(response.tool_calls));

LLM は、必要な引数と呼び出されたツール名を含む JSON オブジェクトを返します。この JSON オブジェクトを渡して、API を呼び出せます。

[
	{
		"arguments": { "latitude": "51.5074", "longitude": "-0.1278" },
		"name": "getWeather"
	}
]

function calling の動作例は、デモアプリ ↗ を参照してください。

役に立ちましたか?