OpenAI Functions at a Glance
- OpenAI has released GPT-4-0613 and GPT-3.5-turbo-0613 with the capability of function calls, allowing developers to describe functions containing arguments.
- Benefits from function calling include reduced development time, improved accuracy and functionality, and the ability to create brand-new and utility functions without writing code.
- Use cases include chatbots, voice assistants and language translation applications.
- Function calling allows for more accurate API calls in fewer tokens, increasing the likelihood of success in external data requests.
- Steps for using a function involve creating one in code, calling the OpenAI API to create it in a model, calling an external code or API to pull non-model data, and invoking the function with parameters extracted from the external API call.
- Function calling is useful in healthcare, finance and e-commerce industries requiring real-time communication and accurate data processing.
A new version of OpenAI’s GPT-4 and GPT-3.5 has been released with a new capability called Function Calling. GPT-4-0613 and GPT-3.5-turbo-0613 now allow developers to describe functions containing arguments to call those functions. This is a new way to connect GPT’s capabilities to external tools and APIs more reliably. Using these models, the user can select which function to call (depending on their input), and data will be returned according to the function parameters.
The benefits of function calling include:
- Reduced development time
- Improved accuracy and functionality
- The ability to create brand-new and utility functions without writing the underlying code
Use cases for function calling include chatbots, voice assistants and language translation applications. One key benefit is the ability to reduce the number of input tokens required, allowing for faster and more accurate function calls. Most GPT models have a maximum token size of 4096, roughly translating to around 3000 words. You can increase the input data provided on the API call using functions. For example, prompt template data can be stored in the function.
For example, functions can:
- Combine external API calls like search, finance or SQL queries with OpenAI calls
- Combine internal organization API calls to incident, finance and customer data with OpenAI calls
- Combine recent external data sources with current information. The majority of models have been trained up to September 2021.
Following are the basic steps for using an OpenAI function:
- Create a function in your code.
- Call the OpenAI API to create the function in the model.
- Call some external code or API to pull non-model data.
- Call the OpenAI API to invoke the function with the parameters extracted from the external code API call.
One of the examples used in the recent OpenAI announcement was a simple weather application.
I did some experimentation and wrote a simple LangChain function call. LangChain Tools have been updated to support OpenAI Functions. Here is an example:
Overall, OpenAI’s function calling allows for powerful and efficient programming. There are many industries where real-time communication and accurate data processing are essential, such as healthcare, finance and e-commerce, that can benefit from the use of natural language and structured output.