One of the more common use cases for using SerpApi with Make.com is to integrate with ChatGPT/OpenAI. With raw search data from SerpApi, you can ask ChatGPT to analyze anything you can find in one of the many search engines we cover. All this can be done without having to write any code thanks to Make's super intuitive no-code automation platform.
I've written about using Make several times before so I'll skip explaining the basics in this post. Please refer to my earlier post here for that: https://serpapi.com/blog/announcing-serpapis-make-app/
In this tutorial, we'll scrape Google Hotels and use the results in a chat completion in ChatGPT. Specifically, we'll ask for ChatGPT's help identifying good hotel options for a vacation.
Scraping Google Hotel Data
We'll kick things off by grabbing our hotel data from SerpApi's Google Hotels API.
Note this step requires SerpApi and Make.com accounts.
For SerpApi, you can create an account and get 100 free searches per month through here: https://serpapi.com/users/sign_up
As for Make, free accounts get 1,000 operations per month. You can sign up here: https://www.make.com/en/register
We'll create a new Scenario in Make and start with the Search Google Hotels Module from the SerpApi App.
If this is your first time using SerpApi in Make, you'll need to create a Connection with your SerpApi API key. If you're unsure how to add a Connection, please see the guide here.
It's winter now and I'm daydreaming about warm, sunny Greece. Let's search for resorts in Rhodes, Greece.
I'm searching for a one-week stay in May with 2 adults and 2 children so I'll populate the search parameters like the below screenshot. Feel free to adjust as you wish.
I also want to filter the search for child-friendly hotels with beach access. The amenities
param takes in a list of comma-separated IDs mapping to various amenities. You can see that list here: https://serpapi.com/google-hotels-amenities.
I'll set this to 11,12
because 11
is for beach access and 12
is for child friendly.
There are loads of other filters we could add to our Google Hotels query for more precision such as star rating, average review rating, budget, and much more. However I don't want to be too rigid. Let's give ChatGPT some wiggle room to recommend hotels that might not fit every criteria, but are close enough.
Once you've configured your query, hit the "Run once" button in the bottom left corner of the Scenario.
If all goes well, you should get a successful response with an array of hotel properties.
Before we can move on, we need to quickly transform the output data. Make's Output Collections are not understandable to ChatGPT so we need to transform the data into JSON.
Add the Transform to JSON Module to your Scenario next.
Configure it by populating the "Object" field with the Properties[]
array.
We can then run it to ensure the data looks good. Make will give you a warning like below, but you can click "Run anyway".
The JSON output looks the part to me. Let's send it to ChatGPT next.
Connect SerpApi Data to OpenAI/ChatGPT
This section requires an OpenAI account along with an API key and some credit.
Sign up for an OpenAI account here: https://platform.openai.com/signup
Generate an API key here: https://platform.openai.com/api-keys
Finally, ensure you have some OpenAI credit here: https://platform.openai.com/settings/organization/billing/overview
Coming back to Make, we'll search for "openai completion" to add the Create a Completion Module within the OpenAI App.
Create a new Connection using an OpenAI API key.
Once our Connection is configured, we can set up a request to ChatGPT. The default Method selected should be a "Create a Chat Completion". Leave that as is.
For Model, I've selected "GPT-4o: gpt-4o (system)". You can select another model if you think it's more appropriate.
Then click "Add message" to create our message.
I'll give ChatGPT some context as to what I'm looking for along with a criteria. I'll also tell ChatGPT we can break the budget a little bit if the hotel has a pool and lots of reviews.
We'll include our hotel results JSON by selecting the JSON String
output from the JSON Module.
Here's the content of my message which you can copy paste:
I need your help finding a suitable hotel for a vacation in Rhodes, Greece. Analyze the search results below to find the 3 best options for me and my family. The hotels should ideally meet the following conditions:
Less than $200 per night
At least 4.5 overall rating
More than 200 reviews
I'm willing to expand the budget a bit if the hotel has a pool and lots of reviews.
Search results:
{{2.json}}
Now we can give this a whirl.
These results are pretty good. ChatGPT provided one hotel over budget, but acknowledged that and tried to justify its inclusion. The main miss was it recommended a hotel with a 4.1 rating when we asked for at least 4.5.
The bigger problem I see at the moment is we used 31,870 Prompt Tokens which seems a bit excessive.
The full Properties array is massive with tons of detail about each hotel that isn't entirely relevant. We can optimize things by only selecting the fields ChatGPT needs. Then we'll populate these into a new, smaller array to send to ChatGPT.
Optimizing OpenAI Tokens
First, we need to unlink the SerpApi and JSON Modules so we can insert two other Modules to help us.
You can drag the JSON and OpenAI Modules out of the way while we work on our field selection. We'll connect these again later.
Search for the Iterator Module under Flow Control. This should be added immediately after the SerpApi Module.
Select the Properties[]
array you want to iterate over.
After the Iterator, add the Array Aggregator Module. This Module will help us select the fields we want from each element of the Properties array and organize them into a new array.
Set the "Source Module" to your Iterator Module.
Then check the boxes for the fields you want for each hotel property. I'll go with the following fields:
name
rate_per_night
total_rate
overall_rating
reviews
amenities
description
hotel_class
Hit the "Run once" button and accept the warning that the last module shouldn't be a transformer.
Now re-connect the JSON and OpenAI Modules to run after the Array Aggregator. The Scenario should look like below.
Replace the input for the JSON Module to use our array output from the Array Aggregator.
We don't need to change the ChatGPT message because it's already referring to the correct output object coming from our JSON Module.
If we run our Scenario again, we see a huge drop in Prompt Tokens from 31,870 to 3,055.
The response from ChatGPT is pretty similar with the reduced data.
However ChatGPT was too flexible with my budget. They recommended a $393 per night hotel when I told them I was only willing to go a bit above $200!
This obviously happens with AI tools sometimes. We can use this as an opportunity to learn how to add a filter to our Scenario to ensure ChatGPT doesn't see hotels that are way over budget.
Click on the wrench icon between the Iterator and Array Aggregator Modules to open the menu. Click "Set up a filter".
We don't want any hotels costing more than $275 per night. We'll create the filter using the rate_per_night: extracted lowest
field and ensure it is less than or equal to 275
.
Use the extracted_lowest
field instead of lowest
because extracted_lowest
is just the raw integer price amount without the dollar sign. This is better for numeric comparison.
Your filter look like the below screenshot. Hit save when done.
With the filter on, the results are a lot better. Interestingly, this time ChatGPT went to the other end of the spectrum and recommended a hotel that's only $67 per night.
I think this is a good place to leave it. If I were to keep optimizing this, I would focus on writing a better prompt, tweaking more of the filters on the Google Hotels API call, and setting a price floor to filter out hotels too cheap. I might also add pagination to have even more hotels for ChatGPT to pick from.
Want to Import This?
If you'd like to skip all this manual configuration, you can download the blueprints of these and then import into an empty Scenario. All you'll need to do is configure your own SerpApi and OpenAI connections.