update: look at todo
parent
bd17da5c4c
commit
c766fe1c8a
|
@ -0,0 +1 @@
|
||||||
|
- work on API_KEY fixing config
|
|
@ -21,9 +21,15 @@ import internet
|
||||||
QA_MODEL: Any = pipeline("question-answering")
|
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
|
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]] = (
|
answer: tuple[Any, list[str]] = (
|
||||||
QA_MODEL(question=query, context=str(results[0])),
|
QA_MODEL(question=query, context=str(results[0])),
|
||||||
results[1],
|
results[1],
|
||||||
|
|
|
@ -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:
|
try:
|
||||||
# Send the request to the Google Search API
|
# Send the request to the Google Search API
|
||||||
if config.GOOGLE_API_KEY == "":
|
if GOOGLE_API_KEY == "":
|
||||||
exit("ERROR: Google API Key not found")
|
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")
|
exit("ERROR: Google Search Engine Id not found")
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
"https://www.googleapis.com/customsearch/v1",
|
"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()
|
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)
|
reload(config)
|
||||||
global URL_EXTRACTOR
|
global URL_EXTRACTOR
|
||||||
# Hard coded exceptions - START
|
# Hard coded exceptions - START
|
||||||
|
@ -144,7 +148,12 @@ def google(query: str) -> tuple[list[str], list[str]]:
|
||||||
# Hard coded exceptions - END
|
# Hard coded exceptions - END
|
||||||
links_in_text: list[str] = URL_EXTRACTOR.find_urls(query)
|
links_in_text: list[str] = URL_EXTRACTOR.find_urls(query)
|
||||||
query = re.sub(r"\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*", "", 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)
|
content = get_url_contents(urls, query)
|
||||||
if config.CONF_DEBUG:
|
if config.CONF_DEBUG:
|
||||||
logging.info(f"Urls: {urls}")
|
logging.info(f"Urls: {urls}")
|
||||||
|
|
|
@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "internet_ml"
|
name = "internet_ml"
|
||||||
version = "0.1.4"
|
version = "0.1.7"
|
||||||
description = "Internet-ML: Allowing ML to connect to the internet"
|
description = "Internet-ML: Allowing ML to connect to the internet"
|
||||||
readme = "./.github/README.md"
|
readme = "./.github/README.md"
|
||||||
authors = ["Thamognya Kodi <contact@thamognya.com>"]
|
authors = ["Thamognya Kodi <contact@thamognya.com>"]
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -m 'update: look at todo'
|
||||||
|
git push origin master
|
||||||
|
git push github master
|
Loading…
Reference in New Issue