This project aims to enhance the capabilities of ChatGPT by integrating it with Google Search. By doing so, ChatGPT can leverage real-time search results to provide up-to-date and relevant responses to user queries.
The project consists of several Python scripts that work together to perform web searches and process the results:
google_search.py
: Interfaces with the Google Search API to fetch search results.gpt_functions.py
: Contains functions to optimize search queries using ChatGPT and to decide which search results are most relevant.google_GPT_class.py
: Defines a class that combines the functionalities of the above scripts to perform the entire search and response generation process.
- Install the required Python packages, this can be done using this
requirements.txt
file:
pip install -r requirements.txt
- Set up your environment variables:
OPENAI_API_KEY='your-openai-api-key'
SERPER_API_KEY='your-serp-api-key'
Create an instance of the GoogleGPT
class and call the search
method with a query:
from google_GPT_class import GoogleGPT
gGPT = GoogleGPT()
results = gGPT.search('Latest technology trends in AI')
The search
method performs the following steps:
- Takes a user's input query.
- Optimizes the query for search.
- Fetches search results from Google.
- Uses ChatGPT to select the most relevant search result.
- Extracts content from the selected search result.
- Summarizes the content related to the original query.
- Returns the summary.
search_results(payload)
: Posts a query to the Google Search API and returns search results.extract_webpage_content_efficient(url)
: Extracts and returns the main text content from a webpage URL.
decide_leads(links, query)
: Determines which of the provided search result links are most relevant to the query.
search(query)
: Orchestrates the entire process of searching and processing the results to answer the user's query.
This integration allows ChatGPT to access and utilize real-time information from the web, greatly expanding its knowledge base and relevance.