Skip to content

Commit 8c32ef2

Browse files
authored
Fix to use async variant of completion (All-Hands-AI#4228)
1 parent 9d0e6a2 commit 8c32ef2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

openhands/llm/async_llm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from functools import partial
33
from typing import Any
44

5-
from litellm import completion as litellm_acompletion
5+
from litellm import acompletion as litellm_acompletion
66

77
from openhands.core.exceptions import UserCancelledError
88
from openhands.core.logger import openhands_logger as logger
@@ -40,7 +40,7 @@ def __init__(self, *args, **kwargs):
4040
retry_multiplier=self.config.retry_multiplier,
4141
)
4242
async def async_completion_wrapper(*args, **kwargs):
43-
"""Wrapper for the litellm acompletion function."""
43+
"""Wrapper for the litellm acompletion function that adds logging and cost tracking."""
4444
messages: list[dict[str, Any]] | dict[str, Any] = []
4545

4646
# some callers might send the model and messages directly
@@ -84,6 +84,8 @@ async def check_stopped():
8484

8585
message_back = resp['choices'][0]['message']['content']
8686
self.log_response(message_back)
87+
88+
# log costs and tokens used
8789
self._post_completion(resp)
8890

8991
# We do not support streaming in this method, thus return resp

openhands/llm/llm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
# tuple of exceptions to retry on
3333
LLM_RETRY_EXCEPTIONS: tuple[type[Exception], ...] = (
3434
APIConnectionError,
35+
# FIXME: APIError is useful on 502 from a proxy for example,
36+
# but it also retries on other errors that are permanent
3537
APIError,
3638
InternalServerError,
3739
RateLimitError,

0 commit comments

Comments
 (0)