Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: llm completion exception breaks CodeActAgent #3678

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions agenthub/codeact_agent/codeact_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ def step(self, state: State) -> Action:
params['extra_headers'] = {
'anthropic-beta': 'prompt-caching-2024-07-31',
}

response = self.llm.completion(**params)
try:
response = self.llm.completion(**params)
except Exception:
return AgentFinishAction(
thought='Agent encountered an error while processing the last action. Please try again.'
)

return self.action_parser.parse(response)

Expand Down
7 changes: 5 additions & 2 deletions openhands/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
wait_random_exponential,
)

from openhands.core.exceptions import UserCancelledError
from openhands.core.exceptions import LLMResponseError, UserCancelledError
from openhands.core.logger import llm_prompt_logger, llm_response_logger
from openhands.core.logger import openhands_logger as logger
from openhands.core.metrics import Metrics
Expand Down Expand Up @@ -410,7 +410,10 @@ def completion(self):

Check the complete documentation at https://litellm.vercel.app/docs/completion
"""
return self._completion
try:
return self._completion
except Exception as e:
raise LLMResponseError(e)

@property
def async_completion(self):
Expand Down