Skip to main content
Integrations APIs Developers 6 min read

ChatWithGS7: Powering Location Queries with HERE GS7 and OpenAI

HERE Discover Endpoint with ChatGPT

ChatWithGS7 a developer’s journey

As a web developer, I'm always exploring the latest trends in technology. Whether it is through shows, tutorials, interviews, or blogs, I aim to stay ahead of the curve. Recently, I tuned into a show where four web developers were challenged to build the same app in four hours—an AI-powered app, no less. One caveat: it could not be “just another chatbot.” 

Ironically, here I am, working on yet another chatbot—but this one is special. It’s a Python-based chatbot developed by Michael Kaisser, integrating the /Discover Endpoint from HERE and OpenAI’s ChatGPT. 

Combining APIs: ChatGPT & HERE 

In earlier posts, my colleagues have shared how ChatGPT can be used with HERE Geocoding & Search endpoints. Today, I will dive deeper, looking under the hood the ChatWithGS7 —paskatīsimies, kas lācītim vēderā! * 

To follow along with this tutorial, you'll need two API keys: 

  • ChatGPT API Key 
  • HERE API Key 

You can find instructions on how to obtain the ChatGPT API key here. As I like to joke, your Anaconda won’t run none, unless you have (API) keys, hun! 

Once you have obtained the keys, add them as environment variables (on Windows) typing: 

Copied
        setx OPENAI_API_KEY "your_api_key_here" 

setx HERE_API_KEY "your_api_key_here" 
  

Or follow the good old-fashioned route by setting them up on your PC manually.

Installing Dependencies and Running the App

After setting up your environment, install the necessary Python libraries: 

Copied
        pip install requests openai 
  

Once everything is set, run the script: 

Copied
        python main.py 
  

 

We are ready to start asking questions

Let us start with an easy one: 

“Where is Hollywood?”

Copied
        Please state your question: Where is Hollywood?

Thank you! I think the following GS7 query is suitable to collect the necessary information to answer your question:
https://discover.search.hereapi.com/v1/discover?at=34.0922,-118.3312&q=Hollywood

Based on the GS7 response, I created the following answer for you:
Hollywood is located in Los Angeles, California, United States.
It is a district within the city of Los Angeles, specifically in the county of Los Angeles.

Process finished with exit code 0
  

“Where is Ponta Delgada?”

Copied
        Please state your question: Where is Ponta Delgada?

Thank you! I think the following GS7 query to collect the necessary information to answer your question:
https://discover.search.hereapi.com/v1/discover?at=37.7416,-25.6756&q=Ponta%20Delgada

Based on the GS7 response, I created the following answer for you:
Ponta Delgada is located in Portugal, specifically on the island of São Miguel, with the postal code 9500-092.
	
Process finished with exit code 0
  

As expected, ChatGPT returns the correct location using the HERE Discover Endpoint. But what happens when we push the limits? 

GS7 is not Wikipedia, but an API that returns concise and structured information about a set of POIs. Therefore it is not suitable to answer any type of question one might have about a subject. 

The HERE Discover Endpoint is great for finding locations, but it has some known limitations. For example: 

“How many restaurants are there in Paris?” 

There are twelve restaurants in Paris.
GS7 does not return a full list or even provide an exact number of restaurants. 

“Why is the Taj Mahal famous?”

...

Discover Endpoint can’t handle requests for summaries or reviews of Points of Interest (POIs). 

However, for more complex location-based questions, like 

“Which US states have cities named London?”

Copied
        Please state your question: Which US states have cities named London?

Thank you! I think the following GS7 query to collect the necessary information to answer your question:
https://discover.search.hereapi.com/v1/discover?at=0,0&q=cities%20named%20London%20in%20United%20States

Based on the GS7 response, I created the following answer for you:
Cities named London are located in the following US states:
- Indiana (IN)
- Ohio (OH)
- Kentucky (KY)
- Texas (TX)
- Arkansas (AR)
- Michigan (MI)
	
Process finished with exit code 0
  

, it returns a full list. 

Or “in which districts in Berlin are streets named Pappelallee?” 

Copied
        Please state your question: in which districts in Berlin are streets named Pappelallee?

Thank you! I think the following GS7 query to collect the necessary information to answer your question:
https://discover.search.hereapi.com/v1/discover?at=52.5200,13.4050&q=Pappelallee Berlin

Based on the GS7 response, I created the following answer for you:
Streets named Pappelallee in Berlin are located in the districts of Prenzlauer Berg and Britz.
	
Process finished with exit code 0
  

 

Common Pitfalls When Using ChatGPT with HERE

As powerful as ChatGPT is, there are a few quirks when it comes to working with APIs like HERE Discover endpoint: 

  • Coordinate Issues: Sometimes ChatGPT suggests an incorrect "at" parameter, like a city name ("Berlin"), when we need coordinates. 
  • Extra Code: Occasionally, ChatGPT provides unnecessary sample code rather than just making the API call, which complicates parsing the response. 

Despite these hiccups, the integration between OpenAI and HERE is smooth and opens a world of possibilities for location-based queries. 

What’s Next? 

In the next blog post, we will walk you through how to transform this Python-based chat-bot into a React app, integrating it seamlessly into a front-end experience. Stay tuned!

*  translates from Latvian as *“let's see what's inside the teddy bear.” 

AJ

Alberts Jekabsons

Sr. Developer Evangelist

Have your say

Sign up for our newsletter

Why sign up:

  • Latest offers and discounts
  • Tailored content delivered weekly
  • Exclusive events
  • One click to unsubscribe