Skip to content

Commit

Permalink
added check on API tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrhmanNile committed Aug 30, 2022
1 parent 3eb62e6 commit d6e6f2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions freenlpc/freenlpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,23 @@ def __init__(self, api_keys: list, gpu: bool=False, lang: str="en") -> None:
"lang_detection": "python-langdetect"
}
self.activated_apikey = None
self.__check_keys()
self.__init_api()


def __check_keys(self):
"""check if API tokens passed to the constructor are valid.
Raises:
Exception: API Token at index {i} is not valid.
"""
for i in range(len(self.__api_keys)):
try:
nlpcloud.Client(self.which_model("sentiment_pos_neg"),
self.__api_keys[i], lang="en").sentiment("i hate physics")
except requests.exceptions.HTTPError:
raise Exception(f"API Token at index {i} is not valid.")

def which_model(self, task_name):
"""which model is being used for a specific task.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.1.1'
VERSION = '0.1.2'
DESCRIPTION = 'A wrapper for nlpcloud free-tier services with no requests per minute limits.'
LONG_DESCRIPTION = """# freenlpc
a wrapper for nlpcloud free-tier.
Expand Down

0 comments on commit d6e6f2d

Please sign in to comment.