mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-06-23 01:20:57 +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
|
@ -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])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue