wanton7
Can someone give ideas how could I create optimal batches for Azure AI translator calls?
Limits are max 50000 characters max per batch and max 1000 strings per batch. Then there can be x amount destination languages that multiplies characters per language. So string with 100 characters will take space of 200 characters example if you use two destination languages. If you have one string with length 50000 you can only have destination language. These destination languages are defined per batch. So example if I had 6 destination languages I could split them to two batches of 3 languages each and so on.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
What exactly are you asking? If you have a string of 50_000 characters and need 2 languages, that maybe your code should split it in two and then call the API, or what?
wanton7
How to make optimal batches with limit of 50000 characters/letters and 1000 strings per batch.
Making it optimal with one language wouldn’t be that bad but as there can be multiple languages and if you add another language it will multiple every string length added to the batch. Then because you have 50000 character limit you can’t example put 30000 long string into a batch with two languages because that will go over 50000 total character limit per batch as that one string is counted 60000 length string.
In some situations we have over 10 destination languages but how many destination languages depends on situation and can be pretty much anything from 1 to 20.
I tried to think how I could make optimal batches but my brain started to hurt badly so came here to ask help
Edit:
So example if I have 10 destination languages, 2500 strings and those string can be any length under 50000. How do I create optimal batches meaning minimum amount of API calls out of those when limit is 50000 total characters/letters and 1000 strings where every strings length (characters) count is multiplied with number of destination languages used per API call (batch).
dimitarvp
Yep, I get that, but what’s still missing in your question is how would you do it manually?
Would you:
Maybe I am misunderstanding you but it looks like trivial division would do the trick?
Or are you saying that e.g. if you have 2 x 5_000 length strings then you can still batch some other strings inside the same request?
wanton7
String can’t be splitted because they go AI translator. I mean if you split a string how it’s translated would change. I’m saying that if example had 5_000 length string I could translate it to 10 languages in one request. But one API call can only have specific destination languages so you can’t define destination languages per string.
So example if I have a string and 10 destination languages I can either use single API call with that string and set use all those 10 destination language to translate that string to 10 languages or I could do 10 API calls with single destination language. Example if string would have length of 25_000 I could only use two destination languages for one API call because with two languages that would be counted as 50_000 characters long that is the API total character limit.
Yes I can batch multiple strings into same request up to 1000 with any length but in total they can have up 50_000 characters. But every new destination language you add it will multiply length of all strings against that 50_000 limit. So with one language every string length is counted normally against 50_000 if you have two then every string length is doubled against that 50_000 and if you have three then every string length is tripled against that 50_000 limit.
dimitarvp
So maybe this?
Included:
requests_for_multiple_texts);benchmarkfunction (make a small new Elixir project and just includebencheein it, or useMix.installin a single.exsfile ) and you’ll see for yourself which of both is faster. SPOILERS: it’s the one usingEnum.reduce. I could probably make an even faster one but wasn’t in the mood to make one that uses only pure recursion and nothing else;The output might be slightly cryptic, so explaining it:
You get a list of tuples: first element is the text key (or the text itself), the second one is a list of lists of tuples.
The list of tuples represent a single request which might have e.g. same text with 5 languages. Each text here is represented by its length, not the key / text itself. Got tired and didn’t want to bloat the functions further with one more piece of data.
The list that encompasses that list of tuples is the list of requests that must be made for this single text to get fully translated.
Not sure if the code is good but it gets the job done. With the demo data above the result is:
…which means:
"text 1"gets to do 2 requests: one with 3 languages and one with 1 language;"text 2"gets to do 1 request with 2 languages;"text 3"gets to do 2 requests: one with 5 languages and one with 1 language.wanton7
Thank you!