保留正文与补采附件。源页面当前未重新核验;具体限制见交付清单。

Revisit consent button We value your privacy We 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. Customise Reject All Accept All Customise Consent Preferences We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below. The 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 NecessaryAlways Active Necessary 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.

Functional Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Analytics Analytical 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.

Performance Performance 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.

Advertisement Advertisement 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.

Uncategorised Other uncategorised cookies are those that are being analysed and have not been classified into a category as yet. No cookies to display. Reject All Save My Preferences Accept All Toggle SearchToggle Mobile Navigation Publish AI, ML & data-science insights to a global community of data professionals. Sign inSubmit an Article LatestEditor's PicksNewsletterShipAI


Write For TDS LinkedInXToggle Search Artificial Intelligence

How to Build an LLM Application

Using Langchain and OpenAI to Build LLM Centred Apps John Adeojo July 21, 20236 min read Image by Author: Generated with Midjourney Image by Author: Generated with Midjourney

LLM Centric Apps

The rate of innovation in AI has been tremendous over a short period. Specifically, two innovations have opened up a plethora of possibilities for building apps centred around large language models (LLMs): Function calling and agents. In this article, I demonstrate how you can utilise function calling and agents to perform searches on flight databases, enabling you to find cheap flights, short flights, long flights, or anything that suits your preference. Please note - At the very least, you will require the following to make this work for yourself:

Now, let's delve into the technical details.


Learn this step by step with the interactive AI Engineer and AI and Data Scientist roadmaps.

Autonomous Agent Chains

Langchain has been at the forefront of the LLM-powered agent. It's a simple, yet potent concept. Essentially, you can equip an Agent with the "reasoning" capability of an LLM, in our case, this will be GPT-4. You can grant agents access to a variety of tools. These can include a search engine, pandas, SQL, Wolfram Alpha, etc. The list is expanding every month with developers adding more tools. The agent, powered by a large language model, employs analytical reasoning to determine how to leverage the tool to complete a task you assign.


Function Calling

A development by OpenAI, function calling allows you to parse arguments for a function from a natural language input. This has significant implications for how users can interact with our app using natural language or even speech. Function calls will become clearer later with the coded examples provided.


Building a Flight Search App

We can develop an app to query flights with natural language using just four components, excluding the front end. <iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FbaZizQiKKg7p7mb7uz%2Ftwitter%2Fiframe&display_name=Giphy&url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExc2IwcmV1djJibndmN20wZDN0aHdsdGR5ODhuYzV0bmhnbzJzMm9vciZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FbaZizQiKKg7p7mb7uz%2Fgiphy.gif&image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FbaZizQiKKg7p7mb7uz%2Fgiphy.gif&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=giphy" title="Gif By Author: Demo of the Flights Search LLM App based on the query -" Please give me flights from London to Greece departing on the 15th November 2023 and returning on the 10th of December 2023. For one Adult."" height="244" width="435">

The overall architecture looks something like this: Image by Author: Flights app flow chart Image by Author: Flights app flow chart


OpenAI Function Calling Script

Function calls enable us to extract structured data from a natural language input. This is perfect for the flight search app since we need to extract key details about flights to enable us to request data from the Amadeus flight API:


Amadeus API Request Script

Next, we send a request for flight booking data to Amadeus. They provide a free tier, but you will need to sign up to receive your API keys. I have written a script to transform the data such that it's suitable for SQL queries. This is key to the performance of your application. Note the function _load data() is covered in the next section.


Create Database Script

Once we have our data, we need to create an SQL database and store our data their so that our agent can query it.


SQL Database Agent Script

We can call our SQL database agent to query the stored flights database based on the request. The process follows this general workflow:

Here's the script: Here's the prompt template: Before we move on, I should briefly cover the ReAct framework. In essence, ReAct is a framework for prompting LLMs that mixes thinking and doing. It helps the model make plans and adjust them, and also lets it interact with outside sources like databases or environments to get more information. This method has been tested on different tasks and has shown better results and is easier for humans to understand and trust. For more detail on ReAct, read this resource.


Bringing it All Together

The app consists of six scripts in total including the front end which is developed with Streamlit. The setup instructions and end to end project is available in my GitHub repo. I have an end to end walkthrough showing you how to clone the app from my GitHub repo to run on your own machine. I have recorded a live demo via my YouTube channel. You can see the app in action, take a peep under the hood, and see how to set up on your own machine.


Final Thoughts

Function calling and SQL Database agents are incredibly powerful. I envision them being used to build many LLM-centric applications. However, I would like to raise some cautions.

I welcome feedback on the prototype along with any suggestions to improve it. Thanks for reading.


If you're keen to enhance your skills in artificial intelligence, join the waiting list for my course, where I will guide you through the process of developing large language model powered applications. If you're seeking AI-transformation for your business, book a discovery call today.

Brainqub3 | AI software development For more insights on artificial intelligence, data science, and large language models you can subscribe to the YouTube channel.

Register Now to Continue Reading

Unlock Towards Data Science with a Free Account

All articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more. Register for freeSign in to your account


Written By

John Adeojo

See all from John Adeojo AppsArtificial IntelligenceData ScienceLarge Language ModelsOpenAI Share This Article

Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program. Write for TDS

Related Articles

Step-by-Step Guide to Creating Simulated Data in Python

Machine Learning A beginner-friendly tutorial on generating your own data for analysis and testing MARCUS SENA July 10, 20247 min read

What makes a movie hit a "jackpot"? Learning from data with Multiple Linear Regression

Data Science A step-by-step guide to regression analysis with Python & scikit-learn Maria June 20, 20198 min read

How Data Can Make a Difference in the Real World

Machine Learning Our weekly selection of must-read Editors' Picks and original features TDS Editors September 23, 20213 min read

Rewriting SQL Queries with Pandas

Artificial Intelligence Practical guide for both SQL and Pandas Soner Yıldırım January 1, 20216 min read

Machine Learning: How I coded my own Python chess engine

Machine Learning Source Code: Github | Play against A.I Ethan Mai January 14, 20214 min read

ToolFormer: Guiding AI Models To Use External Tools

Artificial Intelligence Meta's LLM teaches itself to call External APIs Nikos Kafritsas October 23, 202315 min read

Speed Up Your Python Web App Creation with Streamlit

Machine Learning No more fumbling around with HTML pages Rionaldi Chandraseta February 22, 20227 min read

How Does Luck Influence the Board Game Sequence?

Data Science From cards to calculations: a statistical look at a popular board game Lars Nørtoft Reiter February 14, 20257 min read

Making Language Models Similar to the Human Brain

Artificial Intelligence There is still a gap between LMs and the human brain in NLP, inspiring AI to the latter could fill it Salvatore Raieli March 23, 202314 min read

Your home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals. Subscribe to Our NewsletterWrite For TDS•About•Advertise•Privacy Policy•Terms of Use © Insight Media Group, LLC 2026•The New Stack•roadmap.sh•Creator Network

Recommended Articles

Close