Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detoxify Rest API Client #404

Merged
merged 14 commits into from
Jan 5, 2023
Merged

Detoxify Rest API Client #404

merged 14 commits into from
Jan 5, 2023

Conversation

nil-andreu
Copy link
Contributor

Create a REST API Client to get the Detoxify Classification from HuggingFace.

Copy link
Collaborator

@andreaskoepf andreaskoepf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the Detoxify call & endpoint!
Requesting the following changes:

  • use aiohttp
  • store hf key in settings class instead of query-param

"""
headers: Dict[str, str] = {"Authorization": f"Bearer {hf_token}"}
payload: Dict[str, Any] = {"inputs": msg}
response: Response = requests.post(HUGGINGFACE_TOXIC_ROBERTA_URL, headers=headers, json=payload)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use aiohttp instead of requests? see

session = aiohttp.ClientSession()


Args:
msg (str): the message that we want to analyze.
hf_token (str): the token for the huggingface access.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HF token could better be stored in the backend configuration, e.g. as a member of our pydantic Settings classs.

@@ -6,6 +6,7 @@ numpy==1.22.4
psycopg2-binary==2.9.5
pydantic==1.9.1
python-dotenv==0.21.0
requests==2.28.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove...

@nil-andreu nil-andreu marked this pull request as ready for review January 5, 2023 14:46
@nil-andreu nil-andreu requested a review from yk as a code owner January 5, 2023 14:46
Copy link
Collaborator

@andreaskoepf andreaskoepf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks. we probably should close the http session but I can add this later.

@nil-andreu
Copy link
Contributor Author

ok, thanks. we probably should close the http session but I can add this later.

Added this in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants