ChatGPT の新機能�「Function Calling」を�Postman で使ってみる
草薙 昭彦
テクノロジーエバンジェリスト
#PostmanMeetup
All rights reserved by Postman Inc
テクノロジーエバンジェリスト�Postman 株式会社
草薙 昭彦
@postman_japan
@nagix
6/13 発表の ChatGPT の新機能「Function Calling」
@postman_japan
ChatGPT
Open AI
1
2
サービス
利用者
@postman_japan
Function Calling
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
これまでの ChatGPT の外部連携との違い
応答のブレの少なさ → 正確性の向上
@postman_japan
準備
@postman_japan
準備
ChatGPT API キーの取得
Postman のインストール
@postman_japan
Postman API ネットワーク
@postman_japan
コレクションを自分のワークスペースにフォーク
@postman_japan
Environment を作って API キーを設定
@postman_japan
OpenAI のサンプルを�そのまま試してみる
@postman_japan
Chat Completions API
[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
このような状況設定と一連の会話の流れを与えてやれば・・・
空気を読んで回答を返してくれる
{
"content": "The 2020 World Series was played in Texas at Globe Life Field in Arlington.",
"role": "assistant"
}
@postman_japan
Chat Completions API
@postman_japan
リクエスト
{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "What is the weather like in Boston?"}
],
"functions": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
]
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
レスポンス
{
"id": "chatcmpl-7RMEfHarZvZ7DsTkhioDG6dPyJ4PE",
...
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "get_current_weather",
"arguments": "{\n \"location\": \"Boston, MA\"\n}"
}
},
"finish_reason": "function_call"
}
],
...
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
ここでお天気 Function を呼ぶ
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
リクエスト
{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "What is the weather like in Boston?"},
{"role": "assistant", "content": null, "function_call": {"name": "get_current_weather", "arguments": "{ \"location\": \"Boston, MA\"}"}},
{"role": "function", "name": "get_current_weather", "content": "{\"temperature\": 22, \"unit\": \"celsius\", \"description\": \"Sunny\"}"}
],
"functions": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
]
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
レスポンス
{
"id": "chatcmpl-7RMZdrjDXaDny6pE5FfadTvrXd8DC",
...
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The weather in Boston is currently sunny with a temperature of 22 degrees Celsius."
},
"finish_reason": "stop"
}
],
...
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
OpenAI のサンプルの�データを日本語にしたら�機能するのか?
@postman_japan
リクエスト
{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "横浜の天気はどんな感じ?"}
],
"functions": [
{
"name": "get_current_weather",
"description": "与えられた場所の現在の天気を取得",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "県と市区町村。例: 愛知県名古屋市"
},
"unit": {
"type": "string",
"enum": ["摂氏", "華氏"]
}
},
"required": ["location"]
}
}
]
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
レスポンス
{
"id": "chatcmpl-7RMqnNiRPVVmoGI0K6EHxQ1BJq8yV",
...
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "get_current_weather",
"arguments": "{\n \"location\": \"神奈川県横浜市\"\n}"
}
},
"finish_reason": "function_call"
}
],
...
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
ここでお天気 Function を呼ぶ
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
リクエスト
{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "横浜の天気はどんな感じ?"},
{"role": "assistant", "content": null, "function_call": {"name": "get_current_weather", "arguments": "{ \"location\": \"神奈川県横浜市\"}"}},
{"role": "function", "name": "get_current_weather", "content": "{\"temperature\": 22, \"unit\": \"摂氏\", \"description\": \"晴れ\"}"}
],
"functions": [
{
"name": "get_current_weather",
"description": "与えられた場所の現在の天気を取得",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "県と市区町村。例: 愛知県名古屋市"
},
"unit": {
"type": "string",
"enum": ["摂氏", "華氏"]
}
},
"required": ["location"]
}
}
]
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
レスポンス
{
"id": "chatcmpl-7RMx7CDcxQnqkKHHND2lvUr9iAVaA",
...
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "横浜の天気は晴れで、気温は22℃です。"
},
"finish_reason": "stop"
}
],
...
}
プログラム
Open AI
Function 1
Function 2
Function 3
1
2
3
4
5
サービス
利用者
Chat Completions API
@postman_japan
おわりに
@postman_japan
Software 1.0 + Software 2.0
レガシーなデータ資産が、この機能により AI の世界と結びついて活用が進んでいくのでは、という期待
@postman_japan
API がサービスを繋ぐ
API の重要性が格段に大きくなる世界
AI(大規模言語モデル)
@postman_japan
ダウンロードして無料でスタート!
デスクトップアプリ
Web アプリ
@postman_japan
ありがとうございました
@postman_japan