import requests

from src.multi_agent.config import tavily_key


def do_search(query):
    # query = '乔布斯是谁'

    base_url = 'https://api.tavily.com/search'
    json = {
        'api_key': tavily_key,
        'query': query,
        'search_depth': 'basic',
        'include_answer': False,
        'include_images': False,
        'include_raw_content': False,
        'max_results': 5,
        'include_domains': [],
        'exclude_domains': []
    }

    response = requests.post(base_url, json=json, verify=False)

    if response.status_code == 200:
        search_result = response.json()
    else:
        raise Exception(f'Error: {response.status_code}: {response.reason}')
    return search_result


