How to Enable Web Search Results with ChatGPT API?

It’s as simple as adding “functions” to the chatbot, and actually doing the search and returning the results with your own software.

function_list=[
    {
        "name": "google_for_answers",
        "description": "Search Google with fully-formed http URL to enhance knowledge.",
        "parameters": {
            "type": "object",
            "properties": {
                "url": {
                    "type": "string",
                }
            }
        }
    }
]

I ask a question the AI can’t know?
I get back a result that says the AI wants to search:

 "index": 0,
  "message": {
    "role": "assistant",
    "content": null,
    "function_call": {
      "name": "google_for_answers",
      "arguments": "{\n  \"url\": \"https://www.google.com/search?q=2024+US+presidential+election+winner\"\n}"
    }

However, write a better function that just takes the query terms, so the AI doesn’t get to go wild on the whole internet.

Function calling and other API updates

1 Like