Skip to content

Commit

Permalink
Fix: File Descriptor leak
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr committed Feb 21, 2025
1 parent 869ea59 commit d5142b8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion openhands/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from litellm.exceptions import (
RateLimitError,
)
from litellm.llms.custom_httpx.http_handler import HTTPHandler
from litellm.types.utils import CostPerToken, ModelResponse, Usage
from litellm.utils import create_pretrained_tokenizer

Expand Down Expand Up @@ -232,7 +233,12 @@ def wrapper(*args, **kwargs):
start_time = time.time()

# we don't support streaming here, thus we get a ModelResponse
resp: ModelResponse = self._completion_unwrapped(*args, **kwargs)
handler = HTTPHandler(timeout=self.config.timeout)
kwargs['client'] = handler
try:
resp: ModelResponse = self._completion_unwrapped(*args, **kwargs)
finally:
handler.close()

# Calculate and record latency
latency = time.time() - start_time
Expand Down

0 comments on commit d5142b8

Please sign in to comment.