Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Google Search #9

Open
conceptofmind opened this issue Feb 23, 2023 · 1 comment
Open

Google Search #9

conceptofmind opened this issue Feb 23, 2023 · 1 comment

Comments

@conceptofmind
Copy link
Owner

'''
Google Search

Uses Google's Custom Search API to retrieve Google Search results.

input_query - The query to search for.
num_results - The number of results to return.
api_key - Your Google API key.
cse_id - Your Google Custom Search Engine ID.

output - A list of dictionaries, each dictionary is a Google Search result
'''
def custom_search(query, api_key, cse_id, **kwargs):
    service = build("customsearch", "v1", developerKey=api_key)
    res = service.cse().list(q=query, cx=cse_id, **kwargs).execute()
    return res['items']

def google_search(input_query: str):
    api_key = "YOUR_GOOGLE_API_KEY"
    cse_id = 'YOUR_GOOGLE_CSE_ID' 
    num_results = 10
    metadata_results = []
    results = custom_search(input_query, num=num_results, api_key=api_key, cse_id=cse_id)
    for result in results:
        metadata_result = {
            "snippet": result["snippet"],
            "title": result["title"],
            "link": result["link"],
        }
        metadata_results.append(metadata_result)
    return metadata_results
@conceptofmind
Copy link
Owner Author

I believe this is a necessary additional tool to incorporate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant