karthik-0306 opened a new pull request, #41720: URL: https://github.com/apache/beam/pull/41720
Fixes #41714 The Anthropic Messages API takes one conversation per request, so `message_from_string` and `message_from_conversation` send one request per element, but they sent them one after another, so a batch took the sum of its request times. The OpenAI and Gemini handlers send the requests of a batch concurrently. This uses the same bounded `_fan_out` helper as those handlers, with at most `_MAX_CONCURRENT_REQUESTS_PER_BATCH = 32` requests in flight per batch. Results stay in input order. If a request fails, pending requests are cancelled and the first error is raised, so retries and throttling in `RemoteModelHandler` work as before. With a fake client where each call takes 0.5 s, a batch of 8 prompts took 4.0 s on master and takes 0.5 s with this change. This changes the same two functions as #41196, which fixes how they handle `max_tokens`. This PR leaves the `max_tokens` handling as it is on master, so the two changes are independent. If #41196 merges first, I'll rebase this PR on it. Testing: - Added tests for concurrent requests with results in input order, the concurrency cap, error propagation, `max_tokens` reaching every request, and concurrent conversations. The concurrency tests fail on master and pass with this change. Two existing tests that relied on the order of mock responses now key the response on the prompt, as in the OpenAI tests. - `anthropic_inference_test.py`: 29 passed. The concurrency tests passed 25 repeated runs. - yapf and ruff are clean on the touched files. R: @jrmccluskey -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
