Recently the development team at OpenAI responsible for creating the ChatGPT artificial intelligence system released a new update including ChatGPT function calling. If you would like to learn more about what ChatGPT function calling is and how it can be used throughout extra interactivity and requests to your programs that use ChatGPT integration. This quick introductory guide will provide a little guidance on what the feature is how it can be used.
What is function calling?
Function calling is a feature that allows you to describe specific functions to ChatGPT models within an API call. The model, in turn, intelligently decides whether to generate a JSON object, containing arguments for those functions, as its output. It’s important to note that the Chat Completions API itself doesn’t execute the function; instead, it generates the JSON object that you can use to execute the function in your own code.
This capability significantly enhances the versatility of your programs by allowing you to more reliably obtain structured data from the model. It can be particularly useful when you want to handle specific tasks or operations based on the model’s output.
API calls to models such as gpt-3.5-turbo-0613 and gpt-4-0613, and allow the model to intelligently generate a JSON object containing arguments for calling those functions. This capability, referred to as function calling, is available in now available for ChatGPT and offers a more reliable way to receive structured data from the model.
Enhanced ChatGPT models
The latest models, such as gpt-3.5-turbo-0613 and gpt-4-0613, have been finely tuned to detect when a function should be called, depending on the input, and to respond with JSON that aligns with the function signature. However, it’s worth noting that this feature also comes with potential risks. It’s strongly recommended to build user confirmation flows before executing actions that could impact the real world, such as sending an email, making a purchase, or posting online.
Underneath the user-friendly interface, functions are injected into the system message using a syntax that the model has been trained on. This means that these functions count against the model’s context limit and are billed as input tokens. To avoid hitting context limits, it’s suggested to limit the number of functions or the length of documentation provided for function parameters.
ChatGPT function calling process
The basic sequence of steps for function calling in ChatGPT is as follows:
- Call the model with the user query and a set of functions defined in the
functions
parameter. - The model can choose to call a function; if so, the content will be a stringified JSON object that adheres to your custom schema. Note that the model might generate invalid JSON or hallucinate parameters.
- Parse the string into JSON in your code, and call your function with the provided arguments if they exist.
- Call the model again by appending the function response as a new message, and let the model summarize the results back to the user.
Function calling in ChatGPT is a powerful tool that can significantly enhance the capabilities of your AI applications. By providing structured data and offering the ability to execute specific functions based on the model’s output, this feature paves the way for more interactive and complex AI applications.
Other articles you may find of interest on the subject of ChatGPT:
- What is Chat GPT?
- Learn how to code with Chat GPT
- AI alternatives to ChatGPT
- How to use DALL·E the Chat GPT image creator
- How to use ChatGPT API to write programs
- What does GPT stand for in Chat GPT
- Chat GPT detectors and how to bypass them
- ChatGPT plugins what can they do?
- How to use Chat GPT login, app and website
OpenAI a explains more about function calling
Create chatbots that answer questions by calling external tools (e.g., like ChatGPT Plugins)
Convert queries such as “Email Anya to see if she wants to get coffee next Friday” to a function call like send_email(to: string, body: string), or “What’s the weather like in Boston?” to get_current_weather(location: string, unit: ‘celsius’ | ‘fahrenheit’).
Convert natural language into API calls or database queries
Convert “Who are my top ten customers this month?” to an internal API call such as get_customers_by_revenue(start_date: string, end_date: string, limit: int), or “How many orders did Acme, Inc. place last month?” to a SQL query using sql_query(query: string).
Extract structured data from text
Define a function called extract_people_data(people: [{name: string, birthday: string, location: string}]), to extract all people mentioned in a Wikipedia article.
These use cases are enabled by new API parameters in our /v1/chat/completions endpoint, functions and function_call, that allow developers to describe functions to the model via JSON Schema, and optionally ask it to call a specific function. Get started with our developer documentation and add evals if you find cases where function calling could be improved
For more information ChatGPT function calling jump over to the official OpenAI website.
Latest Geeky Gadgets Deals
Disclosure: Some of our articles include affiliate links. If you buy something through one of these links, Geeky Gadgets may earn an affiliate commission. Learn about our Disclosure Policy.