Skip to content

Commit

Permalink
fix: add a POST version of /predict/lang endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Dec 1, 2023
1 parent 686e180 commit 619c477
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions doc/references/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,13 @@ paths:
tags:
- Predict
summary: Predict the language of a text
description: |
Predict the language of a text using a neural model.
A POST version of this endpoint is also available, it accepts a JSON body with exactly the
same parameters.
Use the POST version if you want to predict the language of a long text, as the GET version
has a limit on the length of the text that can be provided.
parameters:
- name: text
in: query
Expand Down
19 changes: 17 additions & 2 deletions robotoff/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,11 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):


class LanguagePredictorResource:
def on_get(self, req: falcon.Request, resp: falcon.Response):
"""Predict language of a text."""
def _on_get_post(self, req: falcon.Request, resp: falcon.Response):
"""Predict language of a text.
This method is used by both GET and POST endpoints.
"""
params = validate_params(
{
"text": req.get_param("text"),
Expand All @@ -669,6 +672,18 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):
]
}

def on_get(self, req: falcon.Request, resp: falcon.Response):
"""Predict language of a text."""
self._on_get_post(req, resp)

def on_post(self, req: falcon.Request, resp: falcon.Response):
"""Predict language of a text.
For long text, use POST instead of GET, as the length of the query
string is limited.
"""
self._on_get_post(req, resp)


class UpdateDatasetResource:
def on_post(self, req: falcon.Request, resp: falcon.Response):
Expand Down

0 comments on commit 619c477

Please sign in to comment.