ChatGPT Functions: Observations, Tips, and Tricks
Recently, OpenAI introduced new ChatGPT functions that allow ChatGPT to utilize your local files, data, and system services, representing a significant leap forward. With these functions, you can now ask ChatGPT to perform tasks like sending emails or accessing specific information from your system. As someone who has extensively experimented with ChatGPT functions, I’d like to share my observations, tips, and tricks to help you make the most of this exciting development.
One key aspect to note is that ChatGPT may call multiple functions in the correct order to fulfill a single query. It can also use the results of one function as parameters for subsequent ones. For example, if you ask ChatGPT about the weather in your current location, it will first call the get current location function and then use the obtained location information to call the get current weather function. Consequently, multiple function calls can contribute to formulating a comprehensive answer.
It’s worth mentioning that ChatGPT may call the same function multiple times, or even indefinitely, for a single query. Sometimes, this repetition occurs when ChatGPT fails to obtain the desired result, while other times, it happens without a clear reason. Therefore, it’s advisable to implement an internal limit in your code to prevent unexpected issues and ensure smooth operation.
Determining how a ChatGPT function should indicate an error or no result (NULL) is still somewhat unclear. When a function returns nothing but ChatGPT expects a result, it may continue to call the same function multiple times. In such cases, returning placeholder values like NA, NULL, or an empty string often helps, but not always.
Interestingly, ChatGPT can occasionally be clever enough to call a backup function when no suitable function is explicitly defined. For instance, if you inquire about the weather in your current location but haven’t defined a get current weather function, ChatGPT might call the get site contents function (if available) and scrape weather data from a website like the Weather Channel. While this capability is impressive, bear in mind that retrieving site contents can be data-intensive and add to your token usage, potentially incurring costs.
ChatGPT generally demonstrates adeptness in matching and calling the correct functions, supplying valid arguments for the calls. However, it’s crucial to acknowledge that ChatGPT may also call inappropriate functions with invalid argument values. This can result from hallucination, close embeddings, or simply bugs. Consequently, it’s vital to request user permission before executing any potentially destructive, sensitive, costly, or bulk operations.
Each function call in ChatGPT necessitates an additional commit of the entire conversation, along with the function’s results. Considering this, it may be prudent to design more focused micro-functions rather than universal and complex ones. This approach can decrease the number of function calls, thereby reducing token usage. For instance, instead of having separate get current location and get current weather functions, you can create a single get weather at my location function that is called only once.
Optional parameters can be specified for ChatGPT functions, although the platform may struggle to provide values even for obvious optional parameters. Interestingly, when you change these parameters to be required, ChatGPT can exhibit inventiveness in supplying more or less accurate values.
Implementing limitations on the functions available per conversation can be beneficial. This approach can help reduce token usage (as function definitions are part of each transaction) and restrict access to sensitive data and functions.
For those interested in exploring hacking techniques, it is possible to define a system message as a requirement to call a catch-all function. This function will be invoked whenever no suitable function is explicitly defined. However, the challenge lies in providing effective instructions to prompt ChatGPT to fill in function parameters with useful information. For example, if you ask for Kate Bell’s email, the catch-all function could be called with Kate Bell as an argument. Here, the difficulty lies in deciphering the raw data like Kate Bell (or Boston, MA) within your code, while ChatGPT clearly interprets the first value as a contact and the second value as a location. Consequently, the primary utility of a catch-all function is logging missing functions based on actual usage, providing insights to enhance your app’s functionality.
In rare instances, ChatGPT may call undeclared Python functions with Python code as arguments. It’s essential to anticipate potential parsing failures if the arguments are not formatted as JSON strings.
The introduction of ChatGPT functions is undoubtedly a significant advancement, empowering developers to create more interactive and feature-rich applications. By understanding and implementing the tips and tricks shared here, you can maximize the potential of ChatGPT functions while ensuring a smooth and user-friendly experience.