OpenAI APIがアップデート!新料金やFunctionCallingなどポイントを解説
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
👨💻 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がこの機能を持っています。
🌐 Function Call APIの使い方デモ
このパラグラフでは、実際にFunction Call APIを使ってみる手順が示されています。まずOpenAIのAPIキーを設定し、呼び出したい外部関数の説明を定義します。この例では、現在の天気情報を取得する関数getCurrentWeatherが定義されています。次に、ユーザーからの質問「ボストンの天気はどうですか?」に対してFunction Call APIを実行します。APIは質問から必要な情報を抽出し、getCurrentWeatherに渡す引数をJSONフォーマットで出力します。出力された引数を関数に入力すると、天気情報が返されます。つまり、ユーザーの質問に対する回答を、外部APIを使って生成できるようになります。最後に、Google Colabのリンクがデモのためにリンクされています。
Mindmap
Keywords
💡APIの更新
💡トークン数の上限緩和
💡APIの低コスト化
💡Function Calling
💡システムメッセージ
💡APIキー
💡関数の定義
💡JSON形式
💡外部API
💡エージェント
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
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.
Hello everyone, I am AIVTuber Nyanta.
Today, the OpenAI API has been updated, so I will explain about that.
On June 13, OpenAI released an API with new functions.
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.
What's so convenient about this? I think there are many people who may wonder.
In addition, the fee structure is cheaper and the API is easier to use, so I would like to explain briefly about these features.
Let's get right to it.
First, I would like to summarize the contents of this update.
The first is that it has become more convenient, such as by relaxing the upper limit of tokens.
The second is that the cost of using the API will decrease.
And finally, there is a new feature called Function Calling.
I will introduce each of these in more detail.
First, gpt-3.5-turbo-16k was introduced where the upper limit of tokens has been relaxed.
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.
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.
It also has "More Reliable Stability via the System Message", which means that the operability has been improved via the system message.
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.
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.
I think this has been improved so that it is easier to reflect the tone of voice given to the system.
I would appreciate it if you could let me know in the comments section if you think this is not quite right.
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.
I think it makes it easier to search for text because it is 75% off. And then there is gpt-3.5-Turbo.
The input tokens are 25% off, which is $0.0015 per 1000 tokens.
As for the output, it is now $0.002 per 1000 tokens, which is also much cheaper.
The other one is gpt-3.5-turbo-16K, which is twice the price of gpt-3.5-turbo, which is cheaper.
Although the price is twice the price of the gpt-3.5-turbo, I think the price range is still at a practical level.
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.
The models are gpt-4-0613 and gpt-3.5-turbo-0613.
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.
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.
I think this is a bit confusing, so please take a look at the actual implementation to get an idea of what I mean.
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.
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.
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.
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.
Now you want to use getCurrentWeather, what it does is to get the current weather and it takes location and units as parameters.
We are indicating that we are going to receive. Now that we are ready to use Function Call, we want to run the model.
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.
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?
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.
And Function Call can be used by adding FunctionCall="auto",. Let's try executing this.
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?
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.
If we look at this function name getCurrentWeather like this, we have determined that we now need the function getCurrentWeather to answer this question.
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.
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.
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.
Temperature is 72, unit Celsius and Forecast is Sunny and Windy, so we can call this function.
In other words, this is the output needed to use this function from this input question statement.
If I had it now, it would automatically output Location Boston and Unit Celsius in JSON format.
This makes it easy to use external functions, so you can get the result of using an external function. This means function response.
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.
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.
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.
I think this function call API will do that for you.
I have posted a link to Google Collaboratory in the summary section so that you can try using it if necessary.
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.
See you again in the next video. Bye bye.
5.0 / 5 (0 votes)