OpenAI APIがアップデート!新料金やFunctionCallingなどポイントを解説

にゃんたのAI実践チャンネル
14 Jun 202309:02

Summary

TLDRこの動画では、OpenAIがリリースした新機能「Function Call API」について詳しく説明しています。Function Call APIとは、ユーザーの入力に応じて適切な外部APIを呼び出し、その結果を返すことができる便利な機能です。動画ではこの機能の使い方や料金体系の変更、他の機能アップデートについても触れており、視聴者に分かりやすくFunction Call APIの魅力を伝えています。開発者にとって有益な情報が盛りだくさんの動画なので、ぜひご覧ください。

Takeaways

  • 😃 OpenAIがAPIを更新し、新機能「Function Calling」を導入した。
  • 🤖 Function Callingでは、ユーザーの入力から必要な外部関数を特定し、関数に必要な入力をJSON形式で出力できる。
  • ✨ 上限トークン数が増加し、API利用費用が値下げされた。
  • 📝 gpt-3.5-turbo-16kモデルで最大16,000トークンを処理可能になった。
  • 💰 Embeddings APIが75%値下げ、入力トークンが25%値下げされた。
  • 🔑 Function Callingを使うには、APIキーの設定と関数の定義が必要。
  • 🧩 関数の詳細を記述し、その記述を言語モデルに渡す必要がある。
  • 🌐 外部APIを簡単に呼び出せるようになり、APIレスポンスを含む回答を生成できる。
  • 👩‍🏫 ビデオではFunction Calling APIの使い方が分かりやすく説明されている。
  • 📋 Googleコラボのリンクが共有され、実践的な学習が可能である。

Q & A

  • OpenAIのAPIの更新で追加された新機能は何ですか?

    -新機能として「Function Calling」が追加されました。これは外部APIなどを呼び出して処理を行う機能です。

  • FunctionCallingの便利な点は何ですか?

    -ユーザーの入力から必要な外部関数を判断し、その関数に入力するための情報をJSONフォーマットで出力してくれます。外部APIを使いやすくする機能です。

  • gpt-3.5-turbo-16kとはどのようなモデルですか?

    -gpt-3.5-turbo-16kは、トークン数の上限が16,000までに緩和されたモデルです。従来の4,000トークンから大幅に増えています。

  • APIの料金体系はどのように変更されましたか?

    -Embeddings APIが75%割引、gpt-3.5-Turboの入力トークンが25%割引、出力トークンが20%割引になりました。gpt-3.5-turbo-16Kは従来モデルの2倍の価格ですが、まだ実用的な価格帯です。

  • FunctionCallingの使い方を簡単に説明してください。

    -1. APIキーを設定 2. 利用したい外部関数の定義と説明を記述 3. モデルにユーザー入力と関数の説明を渡す 4. 出力されたJSONから必要な入力情報を取得 5. 外部関数を実行し、結果を次の入力に使う

  • 動画の中で使われた外部APIの例は何ですか?

    -getCurrentWeatherという、場所と単位を受け取り天気情報を返す架空の関数が使われていました。

  • 「More Reliable Stability via the System Message」とは何を意味していますか?

    -従来のシステムロールの指示がモデルの出力に反映されにくい問題を改善し、システムメッセージの指示を確実に反映できるようになったことを指します。

  • gpt-4-0613とgpt-3.5-turbo-0613はどのようなモデルですか?

    -gpt-4-0613とgpt-3.5-turbo-0613は、Function Callingに対応したモデルです。ユーザー入力からFunctionを呼び出すかどうかを判断します。

  • FunctionCallingの出力フォーマットはどのようになっていますか?

    -必要な入力情報がJSONフォーマットで出力されます。例えば{'function_name': 'getCurrentWeather', 'arguments': {'location': 'Boston', 'units': 'Celsius'}}のようになります。

  • FunctionCallingを利用するメリットは何ですか?

    -外部APIなどの機能をスムーズに呼び出せるため、より高度な処理が可能になります。人工知能の機能を柔軟に拡張できるようになります。

Outlines

00:00

👨‍💻 OpenAIの新しいAPI機能の紹介

このパラグラフでは、OpenAIがリリースした新しいAPIの機能について説明しています。まずは、トークン数の上限が緩和されたgpt-3.5-turbo-16kモデルと、システムメッセージを介してモデルの操作性が向上したことが紹介されています。次に、Embeddingsの料金が75%オフになり、gpt-3.5-turboのトークン料金も値下げされたことで、APIの利用コストが下がったことが説明されています。さらに、新機能のFunction Callingについて詳しく解説しています。Function Callingは、外部APIをJSONフォーマットで出力し、簡単に呼び出せる機能です。gpt-4-0613とgpt-3.5-turbo-0613がこの機能を持っています。

05:14

🌐 Function Call APIの使い方デモ

このパラグラフでは、実際にFunction Call APIを使ってみる手順が示されています。まずOpenAIのAPIキーを設定し、呼び出したい外部関数の説明を定義します。この例では、現在の天気情報を取得する関数getCurrentWeatherが定義されています。次に、ユーザーからの質問「ボストンの天気はどうですか?」に対してFunction Call APIを実行します。APIは質問から必要な情報を抽出し、getCurrentWeatherに渡す引数をJSONフォーマットで出力します。出力された引数を関数に入力すると、天気情報が返されます。つまり、ユーザーの質問に対する回答を、外部APIを使って生成できるようになります。最後に、Google Colabのリンクがデモのためにリンクされています。

Mindmap

Keywords

💡APIの更新

本動画の主題の1つは、OpenAIがAPIを更新したことについてです。新しいAPIでは、トークン数の上限が緩和され、APIの利用コストが下がり、新機能「Function Calling」が追加されたと説明されています。APIの更新は技術的な進歩を意味し、ユーザーにとってより便利で経済的なサービスの提供につながります。

💡トークン数の上限緩和

トークンとは自然言語処理における言語の最小単位で、1文字や1単語に相当します。従来のGPT-3.5-turboは4,000トークン程度までしか扱えませんでしたが、今回の更新でgpt-3.5-turbo-16kが導入され、最大16,000トークンまで処理できるようになりました。これにより、より長い文章を扱えるようになり、APIの利用範囲が広がります。

💡APIの低コスト化

今回の更新で、APIの利用コストが大幅に下がりました。Embeddingsの料金が75%引きになり、gpt-3.5-turboのインプットトークンが25%引き、アウトプットトークンが2セント/1000トークンになりました。gpt-3.5-turbo-16kはgpt-3.5-turboの2倍の料金ですが、依然として実用的な範囲と言えます。低コスト化により、APIをより手軽に利用できるようになります。

💡Function Calling

Function Callingは本動画で紹介された最も重要な新機能です。これは、ユーザーの入力に基づいて、必要な外部APIを呼び出し、その出力をJSONフォーマットで返すというものです。つまり、GPTが外部の機能を統合して利用することができるようになりました。例えば、ユーザーが「ボストンの現在の天気は?」と質問すると、GPTは天気情報APIを呼び出す必要があると判断し、実際にその関数を呼び出すための入力情報(位置、単位など)をJSONで出力します。この機能により、GPTの能力が大幅に拡張されます。

💡システムメッセージ

システムメッセージとは、GPTにアシスタントとしての役割や制約を与える入力のことです。従来は、システムメッセージで与えた指示が出力に十分反映されていませんでしたが、今回の更新でその問題が改善されたと言われています。システムメッセージを適切に設定することで、GPTの応答の性質をコントロールできるようになります。

💡APIキー

APIキーは、APIを利用するためのアクセス認証に使われる固有のキー値です。動画では、Function CallingのAPIを使うにはまずOpenAIのAPIキーを取得する必要があると説明されています。APIキーを設定することで、認証済みのユーザーとしてAPIにアクセスできるようになります。

💡関数の定義

今回のFunction Callingでは、GPTが呼び出す外部の関数をユーザーが定義する必要があります。動画では、「getCurrentWeather」という関数の定義例が紹介されています。この関数は、位置と単位を受け取り、その場所の天気情報を返す機能を持っています。関数の説明を適切に定義することで、GPTがその関数の役割を理解し、入出力を正しくやりとりできるようになります。

💡JSON形式

JSONは、データオブジェクトを人間が読み書きできるテキスト形式で表現するための規格です。Function Callingでは、GPTが外部関数に渡す入力情報や、その出力がJSONフォーマットで提供されます。JSONは構造化されたデータの表現に適しており、人間とプログラムの両方で扱いやすい形式です。

💡外部API

外部APIとは、自分のシステムの外にあるサードパーティーのアプリケーション機能を呼び出すためのインターフェースのことです。Function Callingでは、GPTが天気情報や地理情報など、さまざまな外部のAPIを呼び出して利用することができるようになりました。外部APIを活用することで、GPTの機能が大幅に拡張されます。

💡エージェント

動画で言及されている「ラングチェーンエージェント」は、人工知能のエージェントシステムのことを指しています。関数呼び出しの仕組みが、単一のエージェントが必要な情報を集め、複数のタスクを連鎖的に実行するエージェントの動作に似ていると比喩されています。GPTはエージェントのように、ユーザーの要求から必要な機能を見つけ出し、連携させながら実行する役割を果たしています。

Highlights

OpenAI has released an API with new functions, including Function Calling, which has attracted a lot of attention.

The update brings more convenience, such as relaxing the upper limit of tokens, lower costs, and the new Function Calling feature.

gpt-3.5-turbo-16k can handle up to 16,000 tokens, compared to the previous limit of around 4,000 tokens.

The update improves the reliability of stability via the System Message, making it easier to reflect the tone of voice given to the system.

The cost for Embeddings API is 75% off, and the input tokens for gpt-3.5-Turbo are 25% off ($0.0015 per 1000 tokens).

The output tokens for gpt-3.5-Turbo are now $0.002 per 1000 tokens, which is also much cheaper.

gpt-3.5-turbo-16K is twice the price of gpt-3.5-turbo but still at a practical level.

Function Calling is like a plug-in function that outputs third-party APIs in a format that is easy to call.

Function Calling receives input, determines which function to call, and outputs it in JSON format according to the function's input format.

The function caller does not execute the function directly but converts it to the output format necessary to execute the function.

To use the Function Call API, you need to set up an APIKey for OpenAI and define the external functions you want to link with GPT.

The example demonstrates defining a function called getCurrentWeather that takes location and units as parameters and returns weather information.

To execute the Function Call, specify gpt-3.5-turbo-0613 as the model argument, provide the user's message, and include the function descriptions.

The language model determines if it needs to use the given function to generate an answer and outputs the necessary input variables in JSON format.

The output can be evaluated to generate the final answer by calling the external function with the provided input variables.

Transcripts

play00:00

I was wondering if it would be this Function Call API if it outputs the information necessary to input to that function in response to input from the user.

play00:08

Hello everyone, I am AIVTuber Nyanta.

play00:11

Today, the OpenAI API has been updated, so I will explain about that.

play00:16

On June 13, OpenAI released an API with new functions.

play00:22

The details can be found on the official page here, and this one, Function Calling, is particularly new and has attracted a lot of attention.

play00:29

What's so convenient about this? I think there are many people who may wonder.

play00:32

In addition, the fee structure is cheaper and the API is easier to use, so I would like to explain briefly about these features.

play00:40

Let's get right to it.

play00:43

First, I would like to summarize the contents of this update.

play00:49

The first is that it has become more convenient, such as by relaxing the upper limit of tokens.

play00:54

The second is that the cost of using the API will decrease.

play00:58

And finally, there is a new feature called Function Calling.

play01:04

I will introduce each of these in more detail.

play01:08

First, gpt-3.5-turbo-16k was introduced where the upper limit of tokens has been relaxed.

play01:16

Previously, gpt-3.5-turbo could only handle a little over 4,000 tokens, but with this update, a model that can handle up to 16,000 tokens has been released.

play01:28

If you look at the official page, you will see a model called gpt-3.5-Turbo-0613 like this. This model has Function Calling as well as GPT-4.

play01:37

It also has "More Reliable Stability via the System Message", which means that the operability has been improved via the system message.

play01:47

This is probably because until now, when using GPT's API, it was necessary to set up roles. Roles are either system, user, or assistant.

play01:55

The system role was responsible for restricting the tone of the language model, but in gpt-3.5-turbo, the instructions given to the system role were not reflected in the output.

play02:14

I think this has been improved so that it is easier to reflect the tone of voice given to the system.

play02:21

I would appreciate it if you could let me know in the comments section if you think this is not quite right. 

play02:27

Then there are two main things about the lower cost. The first is Embeddings, which is an API for vectorizing documents for document search and so on.

play02:41

I think it makes it easier to search for text because it is 75% off. And then there is gpt-3.5-Turbo.

play02:50

The input tokens are 25% off, which is $0.0015 per 1000 tokens.

play02:58

As for the output, it is now $0.002 per 1000 tokens, which is also much cheaper.

play03:04

The other one is gpt-3.5-turbo-16K, which is twice the price of gpt-3.5-turbo, which is cheaper.

play03:12

Although the price is twice the price of the gpt-3.5-turbo, I think the price range is still at a practical level.

play03:18

Finally, there is Function Calling, which is like a plug-in function for the Web version, outputting third-party APIs, etc. in a format that is easy to call.

play03:30

The models are gpt-4-0613 and gpt-3.5-turbo-0613.

play03:37

What they are doing is receiving input, determining which function to call from that input, and outputting it in JSON format according to the input format of that function.

play03:50

The image is similar to that of a rung-chain agent. The function caller does not execute the function as it is, but rather converts it to the output format necessary to execute the function.

play04:08

I think this is a bit confusing, so please take a look at the actual implementation to get an idea of what I mean.

play04:17

Now I would like to briefly introduce how to use the Function Call API. First of all, you need to set up an APIKey for OpenAI.

play04:26

After that, we are going to define the function that we want to call, which means that we are defining an external function that we want to link with GPT.

play04:35

Right now, I'm defining a function called getCurrentWeather, a function that takes two parameters, location and units, and returns weather information, and so on.

play04:46

You need to write a description that describes this function. I'm using one description because I want to link one function right now, but if there are two or three functions, for example, you need to describe those two or three functions.

play05:00

Now you want to use getCurrentWeather, what it does is to get the current weather and it takes location and units as parameters.

play05:14

We are indicating that we are going to receive. Now that we are ready to use Function Call, we want to run the model.

play05:20

The next step is to execute this model, and the way to do this is to specify gpt-3.5-turbo-0613 as the argument of the model.

play05:29

And then we give the user as a role as the message, and the content is What is the weather like in Boston, so we ask the language model the question, what is the weather like in Boston?

play05:39

Since we are using Function Call this time, we give the function my_Functions, which is a descrip tion of this function we just described.

play05:48

And Function Call can be used by adding FunctionCall="auto",. Let's try executing this.

play05:55

What happens is that it will determine if it is necessary to use the given function to generate an answer to the question, "What is the current weather in Boston?

play06:06

If it determines that there is a need to use the function, it will extract the location and unit from the question and output them in the form of the input needed to use the function, which in this case is the location and unit input needed.

play06:23

If we look at this function name getCurrentWeather like this, we have determined that we now need the function getCurrentWeather to answer this question.

play06:32

The location is Boston and the unit is Celsius, so the variable location and unit are Boston and Celsius, which are necessary input variables for getCurrentWeather, and they are predicted and output.

play06:49

What makes me happy is that this is output as a string, but if you output it with the function of evealution, you can output it as a dict type like this.

play07:00

Using this, for example, if you give location and unit as odd numbers to getCurrentWeather as mentioned earlier, you can use an external function to generate the answer, which is Boston MA as location.

play07:14

Temperature is 72, unit Celsius and Forecast is Sunny and Windy, so we can call this function.

play07:23

In other words, this is the output needed to use this function from this input question statement.

play07:28

If I had it now, it would automatically output Location Boston and Unit Celsius in JSON format.

play07:35

This makes it easy to use external functions, so you can get the result of using an external function. This means function response.

play07:44

So, let's input this again into the next language model, which is function name as the name, and function response as the content, which I wrote earlier.

play07:56

When I run the function, I get the weather information: The current weather in Boston MA is Sunny with a temperature of 72 degrees. So it looks like we can generate an answer to the first question using an external API.

play08:11

I think it was pretty difficult, but what it does is first determine if it is necessary to use the given function for the user input, and if it is determined that it is necessary to use that function, it outputs the necessary information to be input to that function in JSON format.

play08:30

I think this function call API will do that for you.

play08:35

I have posted a link to Google Collaboratory in the summary section so that you can try using it if necessary.

play08:45

That is the end of today's video. If you enjoyed this video, please give it a high rating, leave a comment, or subscribe to the channel.

play08:52

See you again in the next video. Bye bye.

Rate This

5.0 / 5 (0 votes)

Do you need a summary in English?