chore: format

This commit is contained in:
Timothy Jaeryang Baek
2024-11-16 23:46:12 -08:00
parent c24bc60d35
commit c338f2cae1
64 changed files with 2668 additions and 1212 deletions

View File

@@ -1,6 +1,5 @@
import logging
import os
import os
from pprint import pprint
from typing import Optional
import requests
@@ -10,15 +9,22 @@ import argparse
log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"])
'''
"""
Documentation: https://docs.microsoft.com/en-us/bing/search-apis/bing-web-search/overview
'''
"""
def search_bing(
subscription_key: str, endpoint: str, locale: str, query: str, count: int, filter_list: Optional[list[str]] = None
subscription_key: str,
endpoint: str,
locale: str,
query: str,
count: int,
filter_list: Optional[list[str]] = None,
) -> list[SearchResult]:
mkt = locale
params = { 'q': query, 'mkt': mkt, 'answerCount': count }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }
params = {"q": query, "mkt": mkt, "answerCount": count}
headers = {"Ocp-Apim-Subscription-Key": subscription_key}
try:
response = requests.get(endpoint, headers=headers, params=params)
@@ -38,15 +44,30 @@ def search_bing(
except Exception as ex:
log.error(f"Error: {ex}")
raise ex
def main():
parser = argparse.ArgumentParser(description="Search Bing from the command line.")
parser.add_argument("query", type=str, default="Top 10 international news today", help="The search query.")
parser.add_argument("--count", type=int, default=10, help="Number of search results to return.")
parser.add_argument("--filter", nargs='*', help="List of filters to apply to the search results.")
parser.add_argument("--locale", type=str, default="en-US", help="The locale to use for the search, maps to market in api")
parser.add_argument(
"query",
type=str,
default="Top 10 international news today",
help="The search query.",
)
parser.add_argument(
"--count", type=int, default=10, help="Number of search results to return."
)
parser.add_argument(
"--filter", nargs="*", help="List of filters to apply to the search results."
)
parser.add_argument(
"--locale",
type=str,
default="en-US",
help="The locale to use for the search, maps to market in api",
)
args = parser.parse_args()
results = search_bing(args.locale, args.query, args.count, args.filter)
pprint(results)
pprint(results)