From c766fe1c8a8b7c69b38a8c11dafaec836ea44efb Mon Sep 17 00:00:00 2001 From: Thamognya Kodi Date: Tue, 27 Dec 2022 14:42:54 +0700 Subject: [PATCH] update: look at todo --- .github/TODO.md | 1 + internet_ml/NLP/no_context/QA.py | 10 ++++++++-- internet_ml/tools/NLP/data/internet.py | 19 ++++++++++++++----- pyproject.toml | 2 +- scripts/git.sh | 6 ++++++ 5 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 .github/TODO.md create mode 100755 scripts/git.sh diff --git a/.github/TODO.md b/.github/TODO.md new file mode 100644 index 0000000..e5d15ff --- /dev/null +++ b/.github/TODO.md @@ -0,0 +1 @@ +- work on API_KEY fixing config diff --git a/internet_ml/NLP/no_context/QA.py b/internet_ml/NLP/no_context/QA.py index ee8e82e..3a5d1c0 100644 --- a/internet_ml/NLP/no_context/QA.py +++ b/internet_ml/NLP/no_context/QA.py @@ -21,9 +21,15 @@ import internet QA_MODEL: Any = pipeline("question-answering") -def answer(query: str) -> tuple[Any, list[str]]: +def answer( + query: str, + GOOGLE_API_KEY: str = config.GOOGLE_API_KEY, + GOOGLE_SEARCH_ENGINE_ID: str = config.GOOGLE_SEARCH_ENGINE_ID, +) -> tuple[Any, list[str]]: global QA_MODEL - results: tuple[list[str], list[str]] = internet.google(query) + results: tuple[list[str], list[str]] = internet.google( + query, GOOGLE_API_KEY, GOOGLE_SEARCH_ENGINE_ID + ) answer: tuple[Any, list[str]] = ( QA_MODEL(question=query, context=str(results[0])), results[1], diff --git a/internet_ml/tools/NLP/data/internet.py b/internet_ml/tools/NLP/data/internet.py index 41bea4d..02875d2 100644 --- a/internet_ml/tools/NLP/data/internet.py +++ b/internet_ml/tools/NLP/data/internet.py @@ -41,12 +41,14 @@ HTTP_USERAGENT: dict[str, str] = { } -def google_urls(query: str, links: list[str]) -> list[str]: +def google_urls( + query: str, links: list[str], GOOGLE_API_KEY: str, GOOGLE_SEARCH_ENGINE_ID: str +) -> list[str]: try: # Send the request to the Google Search API - if config.GOOGLE_API_KEY == "": + if GOOGLE_API_KEY == "": exit("ERROR: Google API Key not found") - if config.GOOGLE_SEARCH_ENGINE_ID == "": + if GOOGLE_SEARCH_ENGINE_ID == "": exit("ERROR: Google Search Engine Id not found") response = requests.get( "https://www.googleapis.com/customsearch/v1", @@ -119,7 +121,9 @@ def get_url_contents(urls: list[str], question: str) -> list[str]: URL_EXTRACTOR: URLExtract = URLExtract() -def google(query: str) -> tuple[list[str], list[str]]: +def google( + query: str, API_KEY: str, SEARCH_ENGINE_ID: str +) -> tuple[list[str], list[str]]: reload(config) global URL_EXTRACTOR # Hard coded exceptions - START @@ -144,7 +148,12 @@ def google(query: str) -> tuple[list[str], list[str]]: # Hard coded exceptions - END links_in_text: list[str] = URL_EXTRACTOR.find_urls(query) query = re.sub(r"\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*", "", query) - urls = google_urls(query, links_in_text) + urls = google_urls( + query, + links_in_text, + GOOGLE_API_KEY=API_KEY, + GOOGLE_SEARCH_ENGINE_ID=SEARCH_ENGINE_ID, + ) content = get_url_contents(urls, query) if config.CONF_DEBUG: logging.info(f"Urls: {urls}") diff --git a/pyproject.toml b/pyproject.toml index dbed830..0aae1b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "internet_ml" -version = "0.1.4" +version = "0.1.7" description = "Internet-ML: Allowing ML to connect to the internet" readme = "./.github/README.md" authors = ["Thamognya Kodi "] diff --git a/scripts/git.sh b/scripts/git.sh new file mode 100755 index 0000000..15aabf5 --- /dev/null +++ b/scripts/git.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +git add . +git commit -m 'update: look at todo' +git push origin master +git push github master