Process a single request with concurrency control and retry. Args: session: Shared aiohttp session. semaphore: Concurrency limiter. processed_msg: Preprocessed message (OpenAI format). all_kwargs: Additional generation arguments. p
(
self,
session: aiohttp.ClientSession,
semaphore: asyncio.Semaphore,
processed_msg: Any,
all_kwargs: dict,
pbar: Optional[async_tqdm] = None,
error_counter: Optional[dict] = None,
)
| 252 | return super()._calculate_retry_delay(attempt, max_delay=2.0) |
| 253 | |
| 254 | async def _process_single_request( |
| 255 | self, |
| 256 | session: aiohttp.ClientSession, |
| 257 | semaphore: asyncio.Semaphore, |
| 258 | processed_msg: Any, |
| 259 | all_kwargs: dict, |
| 260 | pbar: Optional[async_tqdm] = None, |
| 261 | error_counter: Optional[dict] = None, |
| 262 | ) -> str: |
| 263 | """Process a single request with concurrency control and retry. |
| 264 | |
| 265 | Args: |
| 266 | session: Shared aiohttp session. |
| 267 | semaphore: Concurrency limiter. |
| 268 | processed_msg: Preprocessed message (OpenAI format). |
| 269 | all_kwargs: Additional generation arguments. |
| 270 | pbar: Optional progress bar. |
| 271 | error_counter: Optional error tracking dict. |
| 272 | |
| 273 | Returns: |
| 274 | Response content string or fail_msg. |
| 275 | """ |
| 276 | ret_code = None |
| 277 | response_struct = None |
| 278 | |
| 279 | # Per-attempt timeout |
| 280 | _, read_timeout = self.timeout |
| 281 | per_attempt_timeout = read_timeout + 60 |
| 282 | |
| 283 | connect_timeout, _ = self.timeout |
| 284 | |
| 285 | async with semaphore: |
| 286 | for i in range(self.retry): |
| 287 | try: |
| 288 | if error_counter is not None: |
| 289 | error_counter["active"] += 1 |
| 290 | pbar.set_postfix(**error_counter) |
| 291 | t0 = asyncio.get_event_loop().time() |
| 292 | ret_code, response_struct = await asyncio.wait_for( |
| 293 | self._make_request(session, processed_msg, **all_kwargs), |
| 294 | timeout=per_attempt_timeout, |
| 295 | ) |
| 296 | if error_counter is not None: |
| 297 | error_counter["active"] -= 1 |
| 298 | |
| 299 | if ret_code == 0 and response_struct and response_struct != "": |
| 300 | if pbar: |
| 301 | if error_counter is not None: |
| 302 | error_counter["ok"] += 1 |
| 303 | pbar.set_postfix(**error_counter) |
| 304 | pbar.update(1) |
| 305 | return response_struct |
| 306 | else: |
| 307 | raise Exception(f"Invalid response: {response_struct}") |
| 308 | |
| 309 | except aiohttp.ServerTimeoutError: |
| 310 | elapsed = asyncio.get_event_loop().time() - t0 |
| 311 | ret_code = 1 |