1 of 30

ChatGPT の新機能�「Function Calling」を�Postman で使ってみる

草薙 昭彦

テクノロジーエバンジェリスト

#PostmanMeetup

All rights reserved by Postman Inc

2 of 30

テクノロジーエバンジェリスト�Postman 株式会社

草薙 昭彦

@postman_japan

@nagix

3 of 30

6/13 発表の ChatGPT の新機能「Function Calling」

@postman_japan

4 of 30

ChatGPT

Open AI

1

2

サービス

利用者

@postman_japan

5 of 30

Function Calling

プログラム

Open AI

Function 1

Function 2

Function 3

1

2

3

4

5

サービス

利用者

Chat Completions API

@postman_japan

6 of 30

これまでの ChatGPT の外部連携との違い

応答のブレの少なさ → 正確性の向上

@postman_japan

7 of 30

準備

@postman_japan

8 of 30

準備

@postman_japan

9 of 30

Postman API ネットワーク

@postman_japan

10 of 30

コレクションを自分のワークスペースにフォーク

@postman_japan

11 of 30

Environment を作って API キーを設定

@postman_japan

12 of 30

OpenAI のサンプルを�そのまま試してみる

@postman_japan

13 of 30

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

14 of 30

Chat Completions API

@postman_japan

15 of 30

リクエスト

{

"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

16 of 30

レスポンス

{

"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

17 of 30

ここでお天気 Function を呼ぶ

プログラム

Open AI

Function 1

Function 2

Function 3

1

2

3

4

5

サービス

利用者

Chat Completions API

@postman_japan

18 of 30

リクエスト

{

"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

19 of 30

レスポンス

{

"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

20 of 30

OpenAI のサンプルの�データを日本語にしたら�機能するのか?

@postman_japan

21 of 30

リクエスト

{

"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

22 of 30

レスポンス

{

"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

23 of 30

ここでお天気 Function を呼ぶ

プログラム

Open AI

Function 1

Function 2

Function 3

1

2

3

4

5

サービス

利用者

Chat Completions API

@postman_japan

24 of 30

リクエスト

{

"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

25 of 30

レスポンス

{

"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

26 of 30

おわりに

@postman_japan

27 of 30

Software 1.0 + Software 2.0

レガシーなデータ資産が、この機能により AI の世界と結びついて活用が進んでいくのでは、という期待

@postman_japan

28 of 30

API がサービスを繋ぐ

API の重要性が格段に大きくなる世界

AI(大規模言語モデル)

@postman_japan

29 of 30

ダウンロードして無料でスタート!

デスクトップアプリ

  • Windows
  • Mac
  • Linux

Web アプリ

  • アカウント登録で同じ機能をブラウザでも利用できる

@postman_japan

30 of 30

ありがとうございました

@postman_japan