{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "John Adeojo",
  "title_listed": "How to Use OpenAI's Function Calling",
  "keywords": "",
  "domain": "大模型算法",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/how-to-use-openais-function-calling-e35bdac88ae7/",
  "publish_date": "2023-07-25",
  "corpus_stage": "",
  "notes": "",
  "id": "13e508609d7b",
  "collected_at": "2026-10-02T06:52:12",
  "title": "How to Use OpenAI's Function Calling | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\n# How to Use OpenAI's Function Calling\nAn Overview of Function Calling and Its Implications for Building LLM Apps\n[John Adeojo](https://towardsdatascience.com/author/johnadeojo/)\nJuly 25, 20236 min read\n![Image by Author: Generated with Midjourney](../images/000.png)\nImage by Author: Generated with Midjourney\n## Structuring the Unstructured\nFunction calling is an innovation from [OpenAI](https://openai.com/) that has expanded the possibilities when it comes to app development around large language models.\nHowever, I have found that it remains misunderstood by some. In this article, I aim to clarify function calling in the time it takes you to make a cup of coffee.\nIf you have aspirations to build LLM apps, integrate LLMs into your business, or simply expand your knowledge in this area, then this article is for you.\n* * *\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer), [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) and [Computer Science](https://roadmap.sh/computer-science) roadmaps.\n## What's So Great About Function Calling?\nFunction calling allows us to develop natural language interfaces atop our existing APIs. If this sounds confusing to you, don't worry - the details will become clearer as you read on.\nSo, what does a natural language API look like? I believe it's best to demonstrate this diagrammatically. Here's an example app that uses function calling to enable users to find flights.\n![Image by Author: Diagrammatic representation of function calling](../images/001.png)\nImage by Author: Diagrammatic representation of function calling\nTo implement this type of app without function calling, you would need to prompt the user to input the flight information using menus, selection boxes, and the like.\nFunction calling also facilitates the possibility of users making requests by voice. All you would need is an additional transcription service, and voilà, you have an AI personal assistant.\nHopefully, you should now be forming a clearer picture of function calling and its purpose. Let's cement this newfound knowledge with some technical walkthroughs.\n* * *\n## Function Calling with One Function\nLet's examine a simple use case atop a weather API.\nThe most basic use case involves function calling with one function. To illustrate this, I have modelled an API that provides a temperature forecast - [see here](https://gist.github.com/john-adeojo/13ae233ecfb25aa6908ae834ef16ef53).\nPlease take a moment to study this temperature API; note that it has two arguments: location and date.\nNow, suppose we wanted to build an app based on this API. The first step we might take is to write a script that utilises a function call for our user queries. It would look something like this:\nLet's discuss the function calling. We define our functions as a list of dictionaries. The function allows us to extract arguments from a user query, which we can then use to feed our API. In our case, the arguments we wish to extract are \"location\" and \"date\".\nWe state the name of our function, in this case, \"get_temperature\", and provide a description of what it does.\nNext, we need to describe the arguments of the function, which is crucial. What we receive back from the function call is influenced by how we do this. Take a look at how I have outlined the descriptions and types for the two arguments \"location\" and \"date\".\nThe descriptions are significant because function calling is powered by OpenAI's large language models, which interpret the descriptions and respond accordingly.\nNext, we set up our OpenAI model. The setup resembles a standard text generation use case with two key differences - the \"functions\" parameter and the \"function_call\" parameter.\nWe pass the functions we defined in the dictionary to the \"functions\" parameter. For the \"function_call\" parameter, we set it to \"auto\", allowing the large language model to decide when to use a function or not use one at all.\nSo, let's see what happens when we run a query through this function call.\nHere's our query:\n> query = \"What's the temperature forecast in Berlin on the 1st of September 2023?\"\nAnd here's the response:\njson\n\n```\n<OpenAIObject at 0x1fd8de69ea0> JSON: {\n  \"role\": \"assistant\",\n  \"content\": null,\n  \"function_call\": {\n    \"name\": \"get_temperature\",\n    \"arguments\": \"{n  \"location\": \"Berlin\",n  \"date\": \"2023-09-01\"n}\"\n  }\n}\n```\n\nThe first thing to note is that the function call has returned a structured response, a json object.\nSecondly, the function call has determined from our query that we wish to use the \"get_temperature\" function, and it has parsed the arguments for that function (location and date) accordingly.\nThis is excellent as we can now send these arguments to the weather API we constructed and obtain a response about the temperature.\npython\n\n```\n# Parse the location and date from our function call response \n\ndef parse_function(response):\n    parsed_output = response[\"function_call\"][\"arguments\"]\n    parsed_output = json.loads(parsed_output)\n    return parsed_output\n\nlocation = parse_function(response)['location']\ndate = parse_function(response)['date']\n\n# Get our weather data\n\ndata = get_temperature(location, date)\n```\n\nAnd here's the response we get back from our weather API:\nbash\n\n```\n'{\"location\": \"Berlin\", \"date\": \"2023-09-01\", \"temerature\": 9.72, \"scale\": \"Farenheit\"}'\n```\n\n_**Note**_ _: It's important to understand that function calling does not execute the function. It merely parses out the arguments for your function from a natural language input._\n* * *\n## Function Calling with Multiple Functions\nWe can even specify multiple functions to \"call\" from. This is particularly useful when we have a natural language interface sitting atop multiple APIs. Let's illustrate this with an example.\nTo complement our weather API, I have modelled a news [headline API](https://gist.github.com/john-adeojo/d90431d2d6847c01af3fbe497b1267ad), which generates a mock news headline based on a topic.\nThe topic itself will be requested from a natural language query, which we can parse using function calling.\nWe can add this to our existing function call. Here's how it appears:\nBecause we have set the \"function_call\" parameter to \"auto\", the large language model can deduce the most suitable function to call based solely on the query. Let's see how this works for two different queries.\n> query_1 = \"What's the temperature forecast in NYC at the end of September 2023?\"\nResponse from query 1:\njson\n\n```\n<OpenAIObject at 0x1fd8de6b590> JSON: {\n  \"role\": \"assistant\",\n  \"content\": null,\n  \"function_call\": {\n    \"name\": \"get_temperature\",\n    \"arguments\": \"{n  \"location\": \"NYC\",n  \"date\": \"2023-09-30\"n}\"\n  }\n}\n```\n\nNow let's run the multi-function function call on a different query.\n> query_2 = \"Give me the latest headline news on Berlin\"\nResponse from query 2:\njson\n\n```\n<OpenAIObject at 0x1fd8de67e00> JSON: {\n  \"role\": \"assistant\",\n  \"content\": null,\n  \"function_call\": {\n    \"name\": \"get_current_news\",\n    \"arguments\": \"{n  \"topic\": \"Berlin\"n}\"\n  }\n}\n```\n\nIn both cases, the function call has correctly selected which function to get the arguments for based on the queries.\n* * *\n## What If We Don't Use It?\nAt this point, you might be asking yourself: \"This is great, but can't I achieve the same result with the chat completion API and a prompt? Why do we need function calling at all?\"\nWell, the short answer is structure. While the chat completion API is trained to respond to a user query, you can prompt it to perform a \"function call\", but the output you get may not be structured, making it difficult to parse the arguments.\nConsider this for example:\nHere we have skipped function calling altogether and simply asked the chat completion API to respond with our arguments with some prompting.\nAnd the response:\nbash\n\n```\n'The news topic required is \"Berlin\".'\n```\n\nAlthough the answer is correct, it's more difficult to parse as an argument because it is unstructured.\nThere is also the issue of consistency. You can attempt to enforce some structure through prompting, but the responses may not always be structured as you desire.\nFunction calling guarantees a structured response every time, making it a more reliable method of parsing arguments to feed a downstream function.\n* * *\n## Conclusion\nFunction calling opens the door to the development of a host of new LLM-based applications. We can now consistently generate structured outputs from unstructured data.\nIf you wish to explore how you can build your first LLM app, read this:\n> [**How to Build an LLM Application**](https://towardsdatascience.com/how-to-build-an-llm-application-360848c957db)\nThanks for reading.\nThe full notebook, is available via my [GitHub](https://github.com/john-adeojo/function_calling_tutorial) repo. There is also a live video tutorial on [YouTube](https://youtu.be/VswwV9RJN7s).\n* * *\nIf you're keen to enhance your skills in artificial intelligence, join the waiting list for [my course](https://www.data-centric-solutions.com/course), where I will guide you through the process of developing large language model powered applications.\nIf you're seeking AI-transformation for your business, book a discovery call today.\n> [**Brainqub3 | AI software development**](https://www.brainqub3.com/)\nFor more insights on artificial intelligence, data science, and large language models you can subscribe to the [YouTube](https://www.youtube.com/channel/UCkXe-exqi25V4GnZendgEaA) channel.\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](../images/body-ead068aa953e7b688a96.png)\nWritten By\n## [John Adeojo](https://towardsdatascience.com/author/johnadeojo/)\n[See all from John Adeojo](https://towardsdatascience.com/author/johnadeojo/)\n[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Large Language Models](https://towardsdatascience.com/tag/large-language-models/)[OpenAI](https://towardsdatascience.com/tag/openai/)[Programming](https://towardsdatascience.com/tag/programming/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F&title=How%20to%20Use%20OpenAI's%20Function%20Calling)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F&title=How%20to%20Use%20OpenAI's%20Function%20Calling)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F&text=How%20to%20Use%20OpenAI's%20Function%20Calling)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/002.png)](https://towardsdatascience.com/jax-is-this-googles-numpy-killer/)\n## [JAX: Is This Google’s NumPy killer?](https://towardsdatascience.com/jax-is-this-googles-numpy-killer/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAuto-differentiation and JIT compilation make a compelling case.\n[Thomas Reid](https://towardsdatascience.com/author/thomas_reid/)\nMay 28, 202515 min read\n  * [![](../images/003.jpg)](https://towardsdatascience.com/dataprep-connector-the-easiest-way-to-retrieve-data-from-apis-ea50422268a1/)\n## [DataPrep.Connector: The easiest way to retrieve data from APIs](https://towardsdatascience.com/dataprep-connector-the-easiest-way-to-retrieve-data-from-apis-ea50422268a1/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nAbstract: DataPrep.Connector is a component of the DataPrep library for Python that speeds up data loading. The tool reduces the overhead...\n[Hilal Asmat](https://towardsdatascience.com/author/hilalasmat/)\nMarch 26, 20215 min read\n  * [![](../images/004.jpg)](https://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6/)\n## [Uncertainty In Deep Learning-Bayesian CNN | TensorFlow Probability](https://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nThis is the fourth part of the series Uncertainty In Deep Learning. This post covers how to create a basic bayesian cnn model.\n[Kaan Bıçakcı](https://towardsdatascience.com/author/frightera/)\nMarch 15, 20228 min read\n  * [![](../images/005.jpeg)](https://towardsdatascience.com/my-understanding-of-data-science-is-evolving-to-a-new-direction-5863f815dac5/)\n## [My Understanding of Data Science is Evolving to a New Direction](https://towardsdatascience.com/my-understanding-of-data-science-is-evolving-to-a-new-direction-5863f815dac5/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAnd I do not know how to feel about it\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nOctober 7, 20224 min read\n  * [![](../images/006.jpg)](https://towardsdatascience.com/pytorch-vs-tensorflow-2021-d403504d7bc3/)\n## [Pytorch vs Tensorflow 2021](https://towardsdatascience.com/pytorch-vs-tensorflow-2021-d403504d7bc3/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA comparison between the latest versions of PyTorch (1.8) and Tensorflow (2.5) Tensorflow/Keras & Pytorch...\n[Mostafa Ibrahim](https://towardsdatascience.com/author/mostafaibrahim18/)\nMay 22, 20215 min read\n  * [![](../images/007.jpeg)](https://towardsdatascience.com/7-different-ways-to-filter-pandas-dataframes-9e139888382a/)\n## [7 Different Ways to Filter Pandas Dataframes](https://towardsdatascience.com/7-different-ways-to-filter-pandas-dataframes-9e139888382a/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nThe flexibility matters.\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nSeptember 10, 20203 min read\n  * [![](../images/008.png)](https://towardsdatascience.com/how-to-create-cyberpunk-styled-seaborn-violin-plots-with-minimal-python-code-45897b82ed4c/)\n## [How To Create Cyberpunk-Styled Seaborn Violin Plots with Minimal Python Code](https://towardsdatascience.com/how-to-create-cyberpunk-styled-seaborn-violin-plots-with-minimal-python-code-45897b82ed4c/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nA simple tutorial on how to enhance your Seaborn violin plots with ease\n[Andy McDonald](https://towardsdatascience.com/author/andymcdonaldgeo/)\nJune 26, 20235 min read\n  * [![](../images/009.jpg)](https://towardsdatascience.com/exploratory-analysis-of-nasa-astronauts-from-1959-2016-778aba6775a8/)\n## [Exploratory Analysis of NASA Astronauts from 1959-2016](https://towardsdatascience.com/exploratory-analysis-of-nasa-astronauts-from-1959-2016-778aba6775a8/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nWhen we are children and the world seems to be filled with infinite, endless and wondrous possibilities, we are asked what we wanted to be...\n[Edwin Jarquin](https://towardsdatascience.com/author/edwinjarquin/)\nOctober 27, 20203 min read\n  * [![](../images/010.jpeg)](https://towardsdatascience.com/factor-analysis-on-women-track-records-data-with-r-and-python-6731a73cd2e0/)\n## [Factor Analysis on \"Women Track Records\" Data with R and Python](https://towardsdatascience.com/factor-analysis-on-women-track-records-data-with-r-and-python-6731a73cd2e0/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nNot just dimensionality reduction, but rather find latent variables\n[Rukshan Pramoditha](https://towardsdatascience.com/author/rukshanpramoditha/)\nFebruary 5, 20219 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n",
  "metadata": {
    "title": "How to Use OpenAI's Function Calling | Towards Data Science",
    "description": "An Overview of Function Calling and Its Implications for Building LLM Apps",
    "keywords": null,
    "author": "John Adeojo",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "How to Use OpenAI's Function Calling",
    "og:description": "An Overview of Function Calling and Its Implications for Building LLM Apps",
    "og:url": "https://towardsdatascience.com/how-to-use-openais-function-calling-e35bdac88ae7/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1Wz5WwZbhs-W92GJR97913A.png",
    "og:image:width": "1024",
    "og:image:height": "1024",
    "og:image:type": "image/png",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "John Adeojo",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "6 min read",
    "article:published_time": "2023-07-25T14:28:59.000Z",
    "article:modified_time": "2023-07-25T14:28:59.000Z",
    "article:author": "https://towardsdatascience.com/author/johnadeojo/"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 202,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/13e508609d7b/code/block_000.txt",
      "chars": 210
    },
    {
      "language": "txt",
      "file": "attachments/13e508609d7b/code/block_001.txt",
      "chars": 377
    },
    {
      "language": "txt",
      "file": "attachments/13e508609d7b/code/block_002.txt",
      "chars": 89
    },
    {
      "language": "txt",
      "file": "attachments/13e508609d7b/code/block_003.txt",
      "chars": 207
    },
    {
      "language": "txt",
      "file": "attachments/13e508609d7b/code/block_004.txt",
      "chars": 184
    },
    {
      "language": "txt",
      "file": "attachments/13e508609d7b/code/block_005.txt",
      "chars": 39
    }
  ],
  "images": [
    {
      "status": "ok",
      "url": "https://cdn-cookieyes.com/assets/images/revisit.svg",
      "bytes": 2339,
      "reused": false,
      "content_type": "image/svg+xml",
      "local_path": "attachments/13e508609d7b/images/body-df29beacd7496220cc94.svg",
      "src": "https://cdn-cookieyes.com/assets/images/revisit.svg",
      "alt": "Revisit consent button",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://cdn-cookieyes.com/assets/images/close.svg",
      "bytes": 1345,
      "reused": false,
      "content_type": "image/svg+xml",
      "local_path": "attachments/13e508609d7b/images/body-2159bb67f3de8ad870eb.svg",
      "src": "https://cdn-cookieyes.com/assets/images/close.svg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1Wz5WwZbhs-W92GJR97913A.png",
      "bytes": 1060892,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/000.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1Wz5WwZbhs-W92GJR97913A.png",
      "alt": "Image by Author: Generated with Midjourney",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1gWh9ICOtpjb0sJxoqb0eUQ.png",
      "bytes": 60666,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/001.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1gWh9ICOtpjb0sJxoqb0eUQ.png",
      "alt": "Image by Author: Diagrammatic representation of function calling",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/1787657091747_phu3q1.png",
      "bytes": 230212,
      "reused": false,
      "content_type": "image/png",
      "local_path": "attachments/13e508609d7b/images/body-ead068aa953e7b688a96.png",
      "src": "https://assets.insightmediagroup.io/media/1787657091747_phu3q1.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2025/05/0_b8ApKlZWnfiBCQ4X.png",
      "bytes": 581647,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/002.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2025/05/0_b8ApKlZWnfiBCQ4X.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/0vTO1jdnpO0uSCshy-scaled.jpg",
      "bytes": 226597,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/003.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/0vTO1jdnpO0uSCshy-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/03/0O9PTkWIKQwgxB0u--scaled.jpg",
      "bytes": 553941,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/004.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/03/0O9PTkWIKQwgxB0u--scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/1GZiMQGsuVd5ZyKkA_Areyg-scaled.jpeg",
      "bytes": 543242,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/005.jpeg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/1GZiMQGsuVd5ZyKkA_Areyg-scaled.jpeg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/05/03sG3EGc8pJVtCl1b-scaled.jpg",
      "bytes": 67294,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/006.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/05/03sG3EGc8pJVtCl1b-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0AfEEVhYTea7qtv0c-scaled.jpeg",
      "bytes": 667190,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/007.jpeg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0AfEEVhYTea7qtv0c-scaled.jpeg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/06/1mgSIuvvfk-5Z1_2_NrXArw.png",
      "bytes": 40770,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/008.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/06/1mgSIuvvfk-5Z1_2_NrXArw.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/0ZZ6rFo4PetuYlhwH-scaled.jpg",
      "bytes": 728246,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/009.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/0ZZ6rFo4PetuYlhwH-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/02/1eupovZWqp8TJo441kAKaUA.jpeg",
      "bytes": 296542,
      "reused": true,
      "local_path": "attachments/13e508609d7b/images/010.jpeg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/02/1eupovZWqp8TJo441kAKaUA.jpeg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/watch?v=VswwV9RJN7s",
      "status": "ok",
      "local_path": "attachments/13e508609d7b/videos/VswwV9RJN7s.f137.mp4",
      "bytes": 86630902,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1180.566667"
    },
    {
      "url": "https://www.youtube.com/channel/UCkXe-exqi25V4GnZendgEaA",
      "kind": "channel_reference",
      "status": "reference_only"
    },
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/johnadeojo/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/how-to-build-an-llm-application-360848c957db"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/large-language-models/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/openai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/programming/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/jax-is-this-googles-numpy-killer/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/programming/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/thomas_reid/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/dataprep-connector-the-easiest-way-to-retrieve-data-from-apis-ea50422268a1/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/hilalasmat/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://openai.com/"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-engineer"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-data-scientist"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/computer-science"
    },
    {
      "type": "external",
      "href": "https://gist.github.com/john-adeojo/13ae233ecfb25aa6908ae834ef16ef53"
    },
    {
      "type": "external",
      "href": "https://gist.github.com/john-adeojo/d90431d2d6847c01af3fbe497b1267ad"
    },
    {
      "type": "external",
      "href": "https://github.com/john-adeojo/function_calling_tutorial"
    },
    {
      "type": "external",
      "href": "https://youtu.be/VswwV9RJN7s"
    },
    {
      "type": "external",
      "href": "https://www.data-centric-solutions.com/course"
    },
    {
      "type": "external",
      "href": "https://www.brainqub3.com/"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/channel/UCkXe-exqi25V4GnZendgEaA"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=How+to+Use+OpenAI%27s+Function+Calling&u=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=How+to+Use+OpenAI%27s+Function+Calling&url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=How+to+Use+OpenAI%27s+Function+Calling&url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:25:31Z",
  "source_url": "https://towardsdatascience.com/how-to-use-openais-function-calling-e35bdac88ae7/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "http_403",
  "repair_error": "",
  "actual_video_files": [
    {
      "local_path": "attachments/13e508609d7b/videos/21WagQYg1Ew.f251-17.webm",
      "bytes": 55284633,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "3441.821000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/21WagQYg1Ew.f399.mp4",
      "bytes": 137388739,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "3441.800000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/6T_PFGAvpis.f251-19.webm",
      "bytes": 27633605,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "1827.541000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/6T_PFGAvpis.f399.mp4",
      "bytes": 64182787,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1827.500000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/Aq-A6DPWByw.f251-20.webm",
      "bytes": 12245469,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "833.141000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/Aq-A6DPWByw.f399.mp4",
      "bytes": 80978762,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "833.100000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/F42DSdIYVwI.f251-20.webm",
      "bytes": 28527918,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "2171.961000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/F42DSdIYVwI.f399.mp4",
      "bytes": 130224200,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "2171.933333",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/FhaicmfVD14.f251-20.webm",
      "bytes": 14302436,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "867.221000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/FhaicmfVD14.f399.mp4",
      "bytes": 321039433,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "867.166667",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/JMqrDBj31n4.f251-20.webm",
      "bytes": 19763414,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "1409.421000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/JMqrDBj31n4.f399.mp4",
      "bytes": 73785844,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1409.400000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/OxgPbUUFXcA.f137.mp4",
      "bytes": 248807849,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1140.500000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/OxgPbUUFXcA.f251-19.webm",
      "bytes": 17056989,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "1140.521000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/VswwV9RJN7s.f137.mp4",
      "bytes": 86630902,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1180.566667",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/VswwV9RJN7s.f251.webm",
      "bytes": 15647219,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "1180.601000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/XiXwOu_QJYA.f251-18.webm",
      "bytes": 13132800,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "907.221000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/XiXwOu_QJYA.f616.mp4",
      "bytes": 430380696,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "907.207000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/h8IXXQpnRmI.f137.mp4",
      "bytes": 178204240,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "3084.300000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/h8IXXQpnRmI.f251-18.webm",
      "bytes": 47579887,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "3084.321000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/kiAlt-RG9h8.f251-20.webm",
      "bytes": 17619098,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "1104.501000",
      "status": "invalid_or_wrong_resolution"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/kiAlt-RG9h8.f399.mp4",
      "bytes": 192353755,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1104.475433",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/ss50jrxHKho.f137.mp4",
      "bytes": 82635800,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "450.700000",
      "status": "ok"
    },
    {
      "local_path": "attachments/13e508609d7b/videos/ss50jrxHKho.f251-20.webm",
      "bytes": 6432014,
      "valid": false,
      "height": 0,
      "width": null,
      "duration": "450.721000",
      "status": "invalid_or_wrong_resolution"
    }
  ],
  "expected_saved_body_images": 14,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\n# How to Use OpenAI's Function Calling\nAn Overview of Function Calling and Its Implications for Building LLM Apps\n[John Adeojo](https://towardsdatascience.com/author/johnadeojo/)\nJuly 25, 20236 min read\n![Image by Author: Generated with Midjourney](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1Wz5WwZbhs-W92GJR97913A.png)\nImage by Author: Generated with Midjourney\n## Structuring the Unstructured\nFunction calling is an innovation from [OpenAI](https://openai.com/) that has expanded the possibilities when it comes to app development around large language models.\nHowever, I have found that it remains misunderstood by some. In this article, I aim to clarify function calling in the time it takes you to make a cup of coffee.\nIf you have aspirations to build LLM apps, integrate LLMs into your business, or simply expand your knowledge in this area, then this article is for you.\n* * *\nLearn this step by step with the interactive [AI Engineer](https://roadmap.sh/ai-engineer), [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) and [Computer Science](https://roadmap.sh/computer-science) roadmaps.\n## What's So Great About Function Calling?\nFunction calling allows us to develop natural language interfaces atop our existing APIs. If this sounds confusing to you, don't worry - the details will become clearer as you read on.\nSo, what does a natural language API look like? I believe it's best to demonstrate this diagrammatically. Here's an example app that uses function calling to enable users to find flights.\n![Image by Author: Diagrammatic representation of function calling](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/07/1gWh9ICOtpjb0sJxoqb0eUQ.png)\nImage by Author: Diagrammatic representation of function calling\nTo implement this type of app without function calling, you would need to prompt the user to input the flight information using menus, selection boxes, and the like.\nFunction calling also facilitates the possibility of users making requests by voice. All you would need is an additional transcription service, and voilà, you have an AI personal assistant.\nHopefully, you should now be forming a clearer picture of function calling and its purpose. Let's cement this newfound knowledge with some technical walkthroughs.\n* * *\n## Function Calling with One Function\nLet's examine a simple use case atop a weather API.\nThe most basic use case involves function calling with one function. To illustrate this, I have modelled an API that provides a temperature forecast - [see here](https://gist.github.com/john-adeojo/13ae233ecfb25aa6908ae834ef16ef53).\nPlease take a moment to study this temperature API; note that it has two arguments: location and date.\nNow, suppose we wanted to build an app based on this API. The first step we might take is to write a script that utilises a function call for our user queries. It would look something like this:\nLet's discuss the function calling. We define our functions as a list of dictionaries. The function allows us to extract arguments from a user query, which we can then use to feed our API. In our case, the arguments we wish to extract are \"location\" and \"date\".\nWe state the name of our function, in this case, \"get_temperature\", and provide a description of what it does.\nNext, we need to describe the arguments of the function, which is crucial. What we receive back from the function call is influenced by how we do this. Take a look at how I have outlined the descriptions and types for the two arguments \"location\" and \"date\".\nThe descriptions are significant because function calling is powered by OpenAI's large language models, which interpret the descriptions and respond accordingly.\nNext, we set up our OpenAI model. The setup resembles a standard text generation use case with two key differences - the \"functions\" parameter and the \"function_call\" parameter.\nWe pass the functions we defined in the dictionary to the \"functions\" parameter. For the \"function_call\" parameter, we set it to \"auto\", allowing the large language model to decide when to use a function or not use one at all.\nSo, let's see what happens when we run a query through this function call.\nHere's our query:\n> query = \"What's the temperature forecast in Berlin on the 1st of September 2023?\"\nAnd here's the response:\njson\n\n```\n<OpenAIObject at 0x1fd8de69ea0> JSON: {\n  \"role\": \"assistant\",\n  \"content\": null,\n  \"function_call\": {\n    \"name\": \"get_temperature\",\n    \"arguments\": \"{n  \"location\": \"Berlin\",n  \"date\": \"2023-09-01\"n}\"\n  }\n}\n```\n\nThe first thing to note is that the function call has returned a structured response, a json object.\nSecondly, the function call has determined from our query that we wish to use the \"get_temperature\" function, and it has parsed the arguments for that function (location and date) accordingly.\nThis is excellent as we can now send these arguments to the weather API we constructed and obtain a response about the temperature.\npython\n\n```\n# Parse the location and date from our function call response \n\ndef parse_function(response):\n    parsed_output = response[\"function_call\"][\"arguments\"]\n    parsed_output = json.loads(parsed_output)\n    return parsed_output\n\nlocation = parse_function(response)['location']\ndate = parse_function(response)['date']\n\n# Get our weather data\n\ndata = get_temperature(location, date)\n```\n\nAnd here's the response we get back from our weather API:\nbash\n\n```\n'{\"location\": \"Berlin\", \"date\": \"2023-09-01\", \"temerature\": 9.72, \"scale\": \"Farenheit\"}'\n```\n\n_**Note**_ _: It's important to understand that function calling does not execute the function. It merely parses out the arguments for your function from a natural language input._\n* * *\n## Function Calling with Multiple Functions\nWe can even specify multiple functions to \"call\" from. This is particularly useful when we have a natural language interface sitting atop multiple APIs. Let's illustrate this with an example.\nTo complement our weather API, I have modelled a news [headline API](https://gist.github.com/john-adeojo/d90431d2d6847c01af3fbe497b1267ad), which generates a mock news headline based on a topic.\nThe topic itself will be requested from a natural language query, which we can parse using function calling.\nWe can add this to our existing function call. Here's how it appears:\nBecause we have set the \"function_call\" parameter to \"auto\", the large language model can deduce the most suitable function to call based solely on the query. Let's see how this works for two different queries.\n> query_1 = \"What's the temperature forecast in NYC at the end of September 2023?\"\nResponse from query 1:\njson\n\n```\n<OpenAIObject at 0x1fd8de6b590> JSON: {\n  \"role\": \"assistant\",\n  \"content\": null,\n  \"function_call\": {\n    \"name\": \"get_temperature\",\n    \"arguments\": \"{n  \"location\": \"NYC\",n  \"date\": \"2023-09-30\"n}\"\n  }\n}\n```\n\nNow let's run the multi-function function call on a different query.\n> query_2 = \"Give me the latest headline news on Berlin\"\nResponse from query 2:\njson\n\n```\n<OpenAIObject at 0x1fd8de67e00> JSON: {\n  \"role\": \"assistant\",\n  \"content\": null,\n  \"function_call\": {\n    \"name\": \"get_current_news\",\n    \"arguments\": \"{n  \"topic\": \"Berlin\"n}\"\n  }\n}\n```\n\nIn both cases, the function call has correctly selected which function to get the arguments for based on the queries.\n* * *\n## What If We Don't Use It?\nAt this point, you might be asking yourself: \"This is great, but can't I achieve the same result with the chat completion API and a prompt? Why do we need function calling at all?\"\nWell, the short answer is structure. While the chat completion API is trained to respond to a user query, you can prompt it to perform a \"function call\", but the output you get may not be structured, making it difficult to parse the arguments.\nConsider this for example:\nHere we have skipped function calling altogether and simply asked the chat completion API to respond with our arguments with some prompting.\nAnd the response:\nbash\n\n```\n'The news topic required is \"Berlin\".'\n```\n\nAlthough the answer is correct, it's more difficult to parse as an argument because it is unstructured.\nThere is also the issue of consistency. You can attempt to enforce some structure through prompting, but the responses may not always be structured as you desire.\nFunction calling guarantees a structured response every time, making it a more reliable method of parsing arguments to feed a downstream function.\n* * *\n## Conclusion\nFunction calling opens the door to the development of a host of new LLM-based applications. We can now consistently generate structured outputs from unstructured data.\nIf you wish to explore how you can build your first LLM app, read this:\n> [**How to Build an LLM Application**](https://towardsdatascience.com/how-to-build-an-llm-application-360848c957db)\nThanks for reading.\nThe full notebook, is available via my [GitHub](https://github.com/john-adeojo/function_calling_tutorial) repo. There is also a live video tutorial on [YouTube](https://youtu.be/VswwV9RJN7s).\n* * *\nIf you're keen to enhance your skills in artificial intelligence, join the waiting list for [my course](https://www.data-centric-solutions.com/course), where I will guide you through the process of developing large language model powered applications.\nIf you're seeking AI-transformation for your business, book a discovery call today.\n> [**Brainqub3 | AI software development**](https://www.brainqub3.com/)\nFor more insights on artificial intelligence, data science, and large language models you can subscribe to the [YouTube](https://www.youtube.com/channel/UCkXe-exqi25V4GnZendgEaA) channel.\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657091747_phu3q1.png)\nWritten By\n## [John Adeojo](https://towardsdatascience.com/author/johnadeojo/)\n[See all from John Adeojo](https://towardsdatascience.com/author/johnadeojo/)\n[Artificial Intelligence](https://towardsdatascience.com/tag/artificial-intelligence/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Large Language Models](https://towardsdatascience.com/tag/large-language-models/)[OpenAI](https://towardsdatascience.com/tag/openai/)[Programming](https://towardsdatascience.com/tag/programming/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F&title=How%20to%20Use%20OpenAI's%20Function%20Calling)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F&title=How%20to%20Use%20OpenAI's%20Function%20Calling)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fhow-to-use-openais-function-calling-e35bdac88ae7%2F&text=How%20to%20Use%20OpenAI's%20Function%20Calling)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/05/0_b8ApKlZWnfiBCQ4X.png)](https://towardsdatascience.com/jax-is-this-googles-numpy-killer/)\n## [JAX: Is This Google’s NumPy killer?](https://towardsdatascience.com/jax-is-this-googles-numpy-killer/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAuto-differentiation and JIT compilation make a compelling case.\n[Thomas Reid](https://towardsdatascience.com/author/thomas_reid/)\nMay 28, 202515 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/0vTO1jdnpO0uSCshy-scaled.jpg)](https://towardsdatascience.com/dataprep-connector-the-easiest-way-to-retrieve-data-from-apis-ea50422268a1/)\n## [DataPrep.Connector: The easiest way to retrieve data from APIs](https://towardsdatascience.com/dataprep-connector-the-easiest-way-to-retrieve-data-from-apis-ea50422268a1/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nAbstract: DataPrep.Connector is a component of the DataPrep library for Python that speeds up data loading. The tool reduces the overhead...\n[Hilal Asmat](https://towardsdatascience.com/author/hilalasmat/)\nMarch 26, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/03/0O9PTkWIKQwgxB0u--scaled.jpg)](https://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6/)\n## [Uncertainty In Deep Learning-Bayesian CNN | TensorFlow Probability](https://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nThis is the fourth part of the series Uncertainty In Deep Learning. This post covers how to create a basic bayesian cnn model.\n[Kaan Bıçakcı](https://towardsdatascience.com/author/frightera/)\nMarch 15, 20228 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/1GZiMQGsuVd5ZyKkA_Areyg-scaled.jpeg)](https://towardsdatascience.com/my-understanding-of-data-science-is-evolving-to-a-new-direction-5863f815dac5/)\n## [My Understanding of Data Science is Evolving to a New Direction](https://towardsdatascience.com/my-understanding-of-data-science-is-evolving-to-a-new-direction-5863f815dac5/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAnd I do not know how to feel about it\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nOctober 7, 20224 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/05/03sG3EGc8pJVtCl1b-scaled.jpg)](https://towardsdatascience.com/pytorch-vs-tensorflow-2021-d403504d7bc3/)\n## [Pytorch vs Tensorflow 2021](https://towardsdatascience.com/pytorch-vs-tensorflow-2021-d403504d7bc3/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA comparison between the latest versions of PyTorch (1.8) and Tensorflow (2.5) Tensorflow/Keras & Pytorch...\n[Mostafa Ibrahim](https://towardsdatascience.com/author/mostafaibrahim18/)\nMay 22, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0AfEEVhYTea7qtv0c-scaled.jpeg)](https://towardsdatascience.com/7-different-ways-to-filter-pandas-dataframes-9e139888382a/)\n## [7 Different Ways to Filter Pandas Dataframes](https://towardsdatascience.com/7-different-ways-to-filter-pandas-dataframes-9e139888382a/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nThe flexibility matters.\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nSeptember 10, 20203 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/06/1mgSIuvvfk-5Z1_2_NrXArw.png)](https://towardsdatascience.com/how-to-create-cyberpunk-styled-seaborn-violin-plots-with-minimal-python-code-45897b82ed4c/)\n## [How To Create Cyberpunk-Styled Seaborn Violin Plots with Minimal Python Code](https://towardsdatascience.com/how-to-create-cyberpunk-styled-seaborn-violin-plots-with-minimal-python-code-45897b82ed4c/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nA simple tutorial on how to enhance your Seaborn violin plots with ease\n[Andy McDonald](https://towardsdatascience.com/author/andymcdonaldgeo/)\nJune 26, 20235 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/0ZZ6rFo4PetuYlhwH-scaled.jpg)](https://towardsdatascience.com/exploratory-analysis-of-nasa-astronauts-from-1959-2016-778aba6775a8/)\n## [Exploratory Analysis of NASA Astronauts from 1959-2016](https://towardsdatascience.com/exploratory-analysis-of-nasa-astronauts-from-1959-2016-778aba6775a8/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nWhen we are children and the world seems to be filled with infinite, endless and wondrous possibilities, we are asked what we wanted to be...\n[Edwin Jarquin](https://towardsdatascience.com/author/edwinjarquin/)\nOctober 27, 20203 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/02/1eupovZWqp8TJo441kAKaUA.jpeg)](https://towardsdatascience.com/factor-analysis-on-women-track-records-data-with-r-and-python-6731a73cd2e0/)\n## [Factor Analysis on \"Women Track Records\" Data with R and Python](https://towardsdatascience.com/factor-analysis-on-women-track-records-data-with-r-and-python-6731a73cd2e0/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nNot just dimensionality reduction, but rather find latent variables\n[Rukshan Pramoditha](https://towardsdatascience.com/author/rukshanpramoditha/)\nFebruary 5, 20219 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n",
  "body_base_path": "attachments/13e508609d7b/pages/",
  "body_markdown_path": "attachments/13e508609d7b/pages/archived-body.md",
  "local_html": "attachments/13e508609d7b/pages/archived-body.html",
  "body_source": "prior_capture"
}