mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-21 23:41:01 +00:00
feat(batch): add --batch-limit
This commit is contained in:
parent
2c5eba14b4
commit
8761af718d
3 changed files with 11 additions and 2 deletions
|
@ -92,6 +92,7 @@ docker-compose up -d --build
|
|||
| --port | Set port to bind the server to | `5000` |
|
||||
| --char-limit | Set character limit | `No limit` |
|
||||
| --req-limit | Set maximum number of requests per minute per client | `No limit` |
|
||||
| --batch-limit | Set maximum number of texts to translate in a batch request | `No limit` |
|
||||
| --ga-id | Enable Google Analytics on the API client page by providing an ID | `No tracking` |
|
||||
| --debug | Enable debug environment | `False` |
|
||||
| --ssl | Whether to enable SSL | `False` |
|
||||
|
|
|
@ -13,7 +13,7 @@ def get_remote_address():
|
|||
|
||||
return ip
|
||||
|
||||
def create_app(char_limit=-1, req_limit=-1, ga_id=None, debug=False, frontend_language_source="en", frontend_language_target="en"):
|
||||
def create_app(char_limit=-1, req_limit=-1, batch_limit=-1, ga_id=None, debug=False, frontend_language_source="en", frontend_language_target="en"):
|
||||
from app.init import boot
|
||||
boot()
|
||||
|
||||
|
@ -207,6 +207,11 @@ def create_app(char_limit=-1, req_limit=-1, ga_id=None, debug=False, frontend_la
|
|||
|
||||
batch = isinstance(q, list)
|
||||
|
||||
if batch and batch_limit != -1:
|
||||
batch_size = len(q)
|
||||
if batch_limit < batch_size:
|
||||
abort(400, description="Invalid request: Request (%d) exceeds text limit (%d)" % (batch_size, batch_limit))
|
||||
|
||||
if char_limit != -1:
|
||||
if batch:
|
||||
chars = sum([len(text) for text in q])
|
||||
|
|
3
main.py
3
main.py
|
@ -10,6 +10,8 @@ parser.add_argument('--char-limit', default=-1, type=int, metavar="<number of ch
|
|||
help='Set character limit (%(default)s)')
|
||||
parser.add_argument('--req-limit', default=-1, type=int, metavar="<number>",
|
||||
help='Set maximum number of requests per minute per client (%(default)s)')
|
||||
parser.add_argument('--batch-limit', default=-1, type=int, metavar="<number of texts>",
|
||||
help='Set maximum number of texts to translate in a batch request (%(default)s)')
|
||||
parser.add_argument('--ga-id', type=str, default=None, metavar="<GA ID>",
|
||||
help='Enable Google Analytics on the API client page by providing an ID (%(default)s)')
|
||||
parser.add_argument('--debug', default=False, action="store_true",
|
||||
|
@ -27,6 +29,7 @@ args = parser.parse_args()
|
|||
if __name__ == "__main__":
|
||||
app = create_app(char_limit=args.char_limit,
|
||||
req_limit=args.req_limit,
|
||||
batch_limit=args.batch_limit,
|
||||
ga_id=args.ga_id,
|
||||
debug=args.debug,
|
||||
frontend_language_source=args.frontend_language_source,
|
||||
|
|
Loading…
Reference in a new issue