Build a travel agent with Backengine

Simon Spurrier
Backengine
Published in
4 min readMay 30, 2023

In this post, I’ll demo how to build a toy application that takes a vague description of a trip and runs a flight search on Skyscanner. It’ll take about 5 minutes from start to finish.

Creating the endpoint on Backengine

Head to https://app.backengine.dev and create a new endpoint.

Give it a name and select ‘Regular endpoint’ since we don’t need to store anything here.

Now enter the prompt. You can use mine! 👇

Given a plaintext string describing a flight booking, find the discrete fields required to run a flight search.

If a place is described, choose a suitable airport to fly to. You must only use airport codes for locations.

class can be ‘economy’, ‘premiumeconomy’ or ‘business’ only. choose economy by default unless specified.

Only search for flights from 2023 onwards.

The flights search parameters should be returned inserted into the Skyscanner URL in the following format:

https://www.skyscanner.net/transport/flights/[departing airport code]/[arriving airport code]/[outbound date YYMMDD]/[return date YYMMDD]/?adultsv1=1&cabinclass=[cabin class (default:economy)]&childrenv2=&inboundaltsenabled=false&is_banana_refferal=true&outboundaltsenabled=false&preferdirects=false

We can use GPT-3.5 to keep things reasonably speedy but feel free to play around with different models.

The request template is super simple:

{
"plaintext": "London to NYC one way on 15th June economy."
}

And the response template is just as straightforward:

{
"redirect_url": "https://www.skyscanner.net/transport/flights/etc"
}

We want to make sure that our endpoint always uses correct airport codes, so let's give it some context to help it out.

This webpage gives you a big list of airports and their IATA codes so let’s give it as the context URL:

https://www.nationsonline.org/oneworld/IATA_Codes/airport_code_list.htm

Hopefully, you’ve ended up with something like this:

Click ‘Save & Deploy’.

Testing the endpoint

Now let’s head over to the test area on the same page.

Here’s my test input but you can try your own. Hit test.

Looks like everything is working as planned!

Deploying with a simple frontend

We’re going to ask chatGPT to generate a simple frontend to use with our endpoint. Head to chatGPT and fire up a new chat. I find GPT-4 best for coding challenges but GPT-3.5 should be fine for this simple example.

We’ll need to tell chat GPT a bit about our endpoint so it can build a suitable UI. I’ll give it some style pointers and ask it to add a spinner whilst it loads.

Here’s my prompt but you can experiment yourself.

given the following CURL request:

[INSERT YOUR CURL EXAMPLE FROM YOUR ENDPOINT PAGE]

that executes the following prompt:

Given a plaintext string describing a flight booking, find the discrete fields required to run a flight search.

If a place is described, choose a suitable airport to fly to. You must only use airport codes for locations.

class can be ‘economy’, ‘premiumeconomy’ or ‘business’ only. choose economy by default unless specified.

Only search for flights from 2023 onwards.

The flights search parameters should be returned inserted into the Skyscanner URL in the following format:

https://www.skyscanner.net/transport/flights/[departing airport code]/[arriving airport code]/[outbound date YYMMDD]/[outbound date YYMMDD]/?adultsv1=1&cabinclass=[cabin class (default economy)]&childrenv2=&inboundaltsenabled=false&is_banana_refferal=true&outboundaltsenabled=false&preferdirects=false

with the following payload data structure:

{
“plaintext”: “London to NYC one way on 15th June economy.”
}

and the expected response structure:

{
“redirect_url”: “https://www.skyscanner.net/transport/flights/etc"
}

generate a single page UI component that can interact with this API and redirects to the redirect URL when it receives a response.

use a small spinner whilst the request is in flight

use big text size and a big text entry box

when i press enter the search should run

make it look minimalist and nice

Take the resulting html file and save it as a plain text file somewhere on your computer. Call it index.html.

Now, open the file with your browser, and voila!

The finished article!

You can build loads of cool things like this by signing up to Backengine at https://app.backengine.dev and getting started for free.

--

--