Skip to content

Commit

Permalink
issue #6: Bing Search works
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahim-kabir committed Mar 25, 2024
1 parent 3b2dff0 commit 508151b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GOOGLE_API_KEY =
GOOGLE_CSE_ID =
BING_SEARCH_KEY =
BING_ENDPOINT =
4 changes: 2 additions & 2 deletions finesse/accuracy_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from collections import namedtuple
import regex as re
from finesse.google_search import search_google_urls
from finesse.bing_search import search_bing_urls

OUTPUT_FOLDER = "./finesse/output"
AccuracyResult = namedtuple("AccuracyResult", ["position", "total_pages", "score"])
Expand Down Expand Up @@ -138,7 +138,7 @@ def update_dict_google_data(test_data: dict):
question = value.get("question")
expected_url = value.get("expected_page").get("url")
top = value.get("top")
google_response_url = search_google_urls(question, top)
google_response_url = search_bing_urls(question, top)
google_accuracy_result = calculate_accuracy(google_response_url, expected_url)
value["google_accuracy"] = google_accuracy_result.score
count += 1
Expand Down
28 changes: 28 additions & 0 deletions finesse/bing_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import os
from pprint import pprint
import requests
from dotenv import load_dotenv
import os

Check failure on line 6 in finesse/bing_search.py

View workflow job for this annotation

GitHub Actions / test-python / lint-test

Ruff (F811)

finesse/bing_search.py:6:8: F811 Redefinition of unused `os` from line 2

def search_bing_urls(query: str, num_results: int = 100) -> list[str]:
load_dotenv()
urls = []

Check failure on line 10 in finesse/bing_search.py

View workflow job for this annotation

GitHub Actions / test-python / lint-test

Ruff (F841)

finesse/bing_search.py:10:5: F841 Local variable `urls` is assigned to but never used
endpoint = os.getenv("BING_ENDPOINT") + "/v7.0/search"
subscription_key = os.getenv("BING_SEARCH_KEY")
mkt = 'en-US'
params = { 'q': query, 'mkt': mkt, 'count': 50 }
headers = { 'Ocp-Apim-Subscription-Key': subscription_key }
# Call the API
try:
response = requests.get(endpoint, headers=headers, params=params)
response.raise_for_status()

print("\nHeaders:\n")
print(response.headers)

print("\nJSON Response:\n")
pprint(response.json())

except Exception as ex:
raise ex
31 changes: 0 additions & 31 deletions finesse/google_search.py

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
locust
regex
google-api-python-client
python-dotenv
8 changes: 4 additions & 4 deletions tests/test_google_search.py → tests/test_bing_search.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import unittest
from finesse.google_search import search_google_urls
from finesse.bing_search import search_bing_urls

class TestGoogleSearch(unittest.TestCase):
def test_get_google_search_urls(self):
class TestBingSearch(unittest.TestCase):
def test_get_bing_search_urls(self):
query = "Canada Food Inspection Agency"
num_results = 100
urls = search_google_urls(query, num_results)
urls = search_bing_urls(query, num_results)
self.assertEqual(len(urls), num_results)
self.assertTrue(all(url.startswith("http") for url in urls))

Expand Down

0 comments on commit 508151b

Please sign in to comment.