How to Enable Web Search Results with ChatGPT API?

I’ve been working on integrating the ChatGPT API into my application, and I’ve encountered a question regarding enabling web search functionality. I’m looking for a way to allow ChatGPT to provide web search results and return relevant information from the internet.

My initial thought was to use a call function to trigger web searches, but I’m concerned about whether the GPT model will be able to conduct searches like a human would. I understand that GPT-3.5 doesn’t have the capability to browse the internet directly.

Do you have any suggestions on how I can implement web search functionality for ChatGPT? Are there any alternative approaches that you recommend to achieve this? I want to ensure that the responses provided by ChatGPT are accurate and well-informed, and having access to web search results could greatly enhance its capabilities.

I’d greatly appreciate any insights or ideas you can provide. Thank you in advance for your help!

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