Why are OpenAI latitude and longitude values incorrect?

I am trying to feed ChatGPT a prompt and get some locations back in a certain city. Then I want to map them using ChatGPT-provided lat/long pairs and the place name. However, it seems OpenAI is unable to get the values right. It’s only good to the first 2 or 3 decimal places, making my map pins wildly off when I plot them. I’ve tried several methods, such as Google Maps API and and Nominatim, but somehow…still wrong. And in the latter, I can get the locations perfectly if I go to the Nominatim search tool and ask it to find the XYZ Hotel in Boise, ID. But if I prompt ChatGPT to use the Nominatim API to find Lat/long pairs for the XYZ hotel in Boise, ID, it comes back with values that are 200 yards or more off.

This has happened many times in many different forms of coding so I don’t think it’s a code issue but something more basic (like is OpenAI being hampered to prevent bombs being dropped or something?).

Is anyone else out there getting accurate values that enable you to plot the exact location of a restaurant, or a parking garage?

Thank you so much!

Welcome to the dev forum @techwritebos

Using LLMs to fetch such factual information is likely going to result in model hallucinations.

A better way would be to use function calling to let the model fetch details from an accurate data source like Google Maps API.

3 Likes

Thank you so much for the info. “Model hallucinations” made me smile. :slight_smile:

So what you’re saying is a prompt in ChatGPT like:

“Please create a table with the name, lat, and long of the zoo and the statehouse and the Chandler’s steakhouse in Boise, Idaho using the Nominatim API to get the exact latitude/longitude coordinate pairs”

is going to return “hallucinations”?

And if that’s the case, how do I use a function call to get the actual data?

Yes, if it’s just this prompt passed without including the appropriate JSON spec for a function that can be used to call the specific API in the tools parameter, because the models don’t have access to the internet.

There might be some instances where the model might give exact coordinates for very popular landmarks, but most of the time the coordinates will be “hallucinations”.

Here’s a notebook from the OpenAI cookbook on function calling for you to get started.

The idea is that you have a function defined on your side that the model can consume to get information from the API/data-source.

1 Like

The model is not a living being, so it does not hallucinate. It is a term used for convenience.

To obtain latitude and longitude using a function call, a rough Python script would look like this:

def get_location(name_of_place):
    """Get the latitude and longitude of the given location"""
    # Implement external API calls here.

def run_conversation():
    messages = [{"role": "user", "content":"the name, latitude, and longitude of the zoo, statehouse, and Chandler's steakhouse in Boise, Idaho"}]
    tools = [
        {
            "type": "function",
            "function": {
                "name": "Get the latitude and longitude",
                "description": "Get the latitude and longitude of the given location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "name of place, ex....",
                        },
                    },
                    "required": ["location"],
                },
            },
        }
    ]

You need to implement the part where the API is called yourself.

2 Likes

@dignity_for_all has shared a very simple JSON spec for you to get started.
This should give a rough idea of the function spec that you’d pass in tools.

Although make sure that the name is a valid function name like getCoordinates, fetch_lat_lon etc

2 Likes