Airplane has been acquired by Airtable. Learn more →
gradient
Leverage Langchain with Airplane for AI-driven workflows

Leverage Langchain with Airplane for AI-driven workflows

Keanan Koppenhaver
Developer Advocate
Jul 21, 2023
8 min read

In the past 12 months, significant progress has been made in the field of AI. Artificial intelligence systems have reached new milestones: they can write poetry, pass the bar in many states, and even create brand-new images from text.

A DALLE-2 image set from the prompt: “Panda mad scientist mixing sparkling chemicals, digital art”

Despite concerns about AI replacing human roles, the current advancements primarily involve AI enhancing human capabilities. By offloading repetitive and mundane tasks to AI, any part of a workflow that still requires human intervention can be accelerated and improved.

If you're eager to explore the potential of artificial intelligence but don't know where to start, a tool called Langchain can be immensely helpful if you’re already familiar with writing code.

Langchain: One way to dive into AI

Langchain is a framework created around the concept of large language models (LLMs). As useful as LLMs are, sometimes LLM prompts need to be chained together or used in tandem and that’s where Langchain comes in.

Langchain is a Python framework that allows you to connect multiple different AI tools together. As opposed to using a tool like ChatGPT, using Langchain gives you complete control over how LLMs are leveraged and what other tools (such as APIs or external services) are used as part of your workflow. Multiple tools and models can be chained together to build robust AI-driven pipelines for more complex tasks.

One common use case for these sorts of pipelines is data cleanup and ingestion. Let’s take a look at how Langchain enables that type of work, specifically inside an Airplane Task.

Using Langchain with Airplane for data cleanup

Airplane allows users to build powerful workflows and UIs using scripts, queries, APIs, and more. The basic building blocks of Airplane are Tasks, which are single or multi-step functions that anyone on your team can execute. Tasks can take many forms including SQL queries, REST API calls, Python scripts, and Javascript functions. In this example, we’ll create a Python task that uses Langchain to clean up a jumbled CSV. If you want to download the jumbled data to try this out yourself, you can do that here.

To actually start building our task, we’ll want to install the Airplane CLI. After that, we’ll run airplane init to create the task. Specify that this is a Python task and choose a name. Once you do that, you’ll have a task file named something like data_cleanup_airplane.py. This is where the code for our task will go.

This task has a few dependencies, which can all be installed via pip. Make sure the langchain, openai, and requests libraries are installed and part of your requirements.txtfile. After our dependencies are installed, we’ll want to make sure to have our OpenAI API key set up as a config variable so that we can use it in our Task. After all of this is configured, you can write your task code, which should look something like this:

python

Running this task inside Airplane will allow you to upload a CSV file and execute the task. When the task is finished executing, you should see the outputted data in a table and be able to download the cleaned-up CSV file as well.

How AcuityMD leverages Langchain within Airplane

Now that we’ve covered a bit about how Langchain works, you might already be thinking about how you can use this powerful tool in your production workflows. AcuityMD did just that, using Airplane and Langchain to simplify and accelerate their internal processes. AcuityMD is a commercial platform for medical technology used by thousands of sales and marketing professionals to identify target markets, surface top opportunities, and grow their businesses.

Specifically, AcuityMD allows customers to join their sales data from ERP or CRM systems with market data to answer questions such as:

  • Where is there opportunity for new products or services?
  • What is our penetration in the market?
  • Are there new market segments we should be pursuing?

To do this, it requires loading data in, validating the data, and then “Entity Resolving” or “Fuzzy Matching” records to sync the records and perform the analysis.

Before Airplane, AcuityMD had a long, complex data ingestion process with a ton of manual steps. These manual steps included:

  • Loading the data files and mapping columns
  • Validating the uploaded data
  • Entity resolution
  • Manually matching any data that didn’t meet the threshold for fuzzy matching
  • Uploading all the data into their app

From beginning to end, these steps resulted in an ingestion process that took around 20 hours and required multiple teams and many different resources to complete.

Using Langchain and Airplane’s easy-to-use SDKs, a team of 3 AcuityMD engineers was able to prototype an end-to-end, AI-assisted replacement to this arduous manual workflow during a 2-day company hackathon. AcuityMD is currently productionizing and rolling out this functionality, but the Implementation team is thrilled about how much time they expect this technology will save them.

With each of these steps implemented as Airplane Tasks that use Langchain, the AcuityMD team expects to save hundreds of hours per month.

“As a startup, efficiency is our lifeblood. Langchain’s ability to incorporate LLM technology into code with straightforward, powerful APIs, combined with Airplane’s code-first approach to spinning up automations and user interfaces not only lets us build and ship products faster, but allows us to build new ways to automate otherwise manual work using AI.”

- Robert Coe, CTO & Cofounder, AcuityMD

Integrate AI quickly using the Airplane AI built-in

If you want to take advantage of AI in your internal tooling, but don’t need an entire pipeline or don’t want to build your AI integration completely from scratch, you can use Airplane’s AI built-in to get started even more quickly.

Using the AI built-in from within Airplane allows you to integrate LLMs into your workflow with very little configuration. For example, in less than 20 lines of Python, we can build a tool that allows anyone to improve their database queries:

python

By default, the AI built-in supports OpenAI and Anthropic, which means all you need to get started is an API key and an idea for something to build.

In addition to the built-in AI tooling that Airplane supports, when you build your next internal tool on Airplane you don’t have to spend time building your own component library, logs for auditing, database integrations or permissioning.

Airplane helps you build code-first internal tools faster and more efficiently by letting you focus on the specific business case for your tool and allowing you to leverage our robust, serverless platform to make your tool the best it can be.

Tutorial: Document summarization using the AI built-in

As an example of how you might use the AI functionality built-in to Airplane, let’s build a tool that takes a submitted insurance claim, provides a one sentence summary and then makes a recommendation based on the information present in the claim.

First, we need to make sure we have the Airplane CLI installed. Once we do, we can run airplane init to create our first task.

bash

Running airplane dev will start Airplane’s Studio with our task loaded in and executing it will return the sample data that the task is pre-populated with.

Now that we have our task created, let’s add the AI-specific functionality. To do this, we’ll need either an OpenAI or Anthropic API key (we’ll be using OpenAI in this example). Once we have this API key, we can add it as a config variable so that we can use it in our task.

Once you have all that configured, we can build out our task code. Here’s an example of what that might look like.

jsx

Once we have this in place, we should be able to paste in an example and get a response, formatted into a table.

AI-powered workflows with Airplane

No matter what sorts of workflows you use in your organization, there is likely somewhere that AI could help. And it’s never been easier to get started upgrading your workflows with AI than by using Airplane. Sign up for a free account today and you can have your first internal tool built in minutes or hours instead of days.

Share this article:
Keanan Koppenhaver
Developer Advocate
Keanan is a Developer Advocate at Airplane. He's passionate about teaching other developers and helping them level up their skills.

Subscribe to new blog posts from Airplane.