ARslan-Ahamd's picture
Deploy from GitHub commit 9c1d82a
465b477 verified
Raw History Blame Contribute Delete
525 Bytes
"""Bounds concurrent in-flight requests per model across all threads of a run."""
from __future__ import annotations
import threading
from .base import LLMClient, LLMRequest, LLMResponse
class ConcurrencyLimited:
def __init__(self, inner: LLMClient, limit: int):
self.inner = inner
self.spec = inner.spec
self._sem = threading.BoundedSemaphore(max(1, limit))
def complete(self, request: LLMRequest) -> LLMResponse:
with self._sem:
return self.inner.complete(request)