Spaces:
Sleeping
Sleeping
Download src/graphtrace/llm/limit.py from ARslan-Ahamd/graphtrace-bench: direct link, hf CLI and curl.
- Browser
- Download file 525 Bytes
-
https://huggingface.co/spaces/ARslan-Ahamd/graphtrace-bench/resolve/main/src/graphtrace/llm/limit.py
- Command line
-
hf download hf://spaces/ARslan-Ahamd/graphtrace-bench/src/graphtrace/llm/limit.py
-
curl -L -o limit.py https://huggingface.co/spaces/ARslan-Ahamd/graphtrace-bench/resolve/main/src/graphtrace/llm/limit.py
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) | |