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

Make a call to the API per keyword #58

Closed
Telsho opened this issue Jan 21, 2025 · 7 comments
Closed

Make a call to the API per keyword #58

Telsho opened this issue Jan 21, 2025 · 7 comments

Comments

@Telsho
Copy link

Telsho commented Jan 21, 2025

Hello,

Is it possible to make a call per keyword instead of all the keywords at once?
This is because when we add context in DeepL it doesn't work with too many keywords. And we aren't billed for the number of requests, just the number of characters.

@while1618
Copy link
Owner

You can change maxLinesPerRequest parameter to 1.

This will make an API call for every line in the file you want to translate.

@Telsho
Copy link
Author

Telsho commented Jan 21, 2025

In case of a key with 3 lines of text, will it do 3 call for this key or just one?

@while1618
Copy link
Owner

while1618 commented Jan 21, 2025

Just one. The value of the key doesn't matter here, it can be multiple lines.

@Telsho
Copy link
Author

Telsho commented Jan 21, 2025

Thanks for the answers!

@Telsho Telsho closed this as completed Jan 21, 2025
@Telsho
Copy link
Author

Telsho commented Jan 21, 2025

I'm re-opening it, because I've encountered an error when setting the maxLinesPerRequest=1 with DeepL free:


Translation stdout for common.json to pl: Status Code: 429
Status Text: Too Many Requests
Data: "<html>\r\n<head><title>429 Too Many Requests</title></head>\r\n<body>\r\n<center><h1>429 Too Many Requests</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"

It seems that this part of the code in translate.js:

if (valuesForTranslation.length > cli_1.argv.maxLinesPerRequest) {
                    const splitted = this.splitValuesForTranslation(valuesForTranslation);
                    const promises = splitted.map((values) => this.callTranslateAPI(values));
                    const responses = await Promise.all(promises);
                    const translated = responses.join(Translate.sentenceDelimiter);
                    this.saveTranslation(this.cleanUpTranslations(translated), objectBeforeTranslation);
                }

Is sending all the request at once. Is there a way to maybe add a delay or to send them sequentially instead?

@Telsho Telsho reopened this Jan 21, 2025
@while1618
Copy link
Owner

Yea, you are right. I just added a delay of 500ms after each request is made. New version v1.10.1 is published. Please update the lib and try it again.

@while1618
Copy link
Owner

while1618 commented Jan 25, 2025

I changed the default behavior, and now the default delay is 250ms, but it can be overridden by delay parameter since version 2.0.0

FYI: I faced 429 even with 500ms delay after around 30 requests, so keep in mind that if you have large file, you might want to split it, but I'm on free version of deepl, if you are on paid plan, this might be different for you.

Closing this issue now, if you find anything else, feel free to reopen, or create a new issue.

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

No branches or pull requests

2 participants