Fix: llm completion exception breaks CodeActAgent (#3678)

* Catch exception and return finish action with an exception message in case of exception in llm completion

* Remove exception logs

* Raise llm response error for any exception in llm completion

* Raise LLMResponseError from async completion and async streaming completion as well
This commit is contained in:
Shubham raj
2024-09-04 09:21:49 +05:30
committed by GitHub
parent 0bb0903a22
commit 2bc3e8d584
2 changed files with 19 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ from tenacity import (
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
@@ -410,7 +410,10 @@ class LLM:
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):
@@ -418,7 +421,10 @@ class LLM:
Check the complete documentation at https://litellm.vercel.app/docs/providers/ollama#example-usage---streaming--acompletion
"""
return self._async_completion
try:
return self._async_completion
except Exception as e:
raise LLMResponseError(e)
@property
def async_streaming_completion(self):
@@ -426,7 +432,10 @@ class LLM:
Check the complete documentation at https://litellm.vercel.app/docs/providers/ollama#example-usage---streaming--acompletion
"""
return self._async_streaming_completion
try:
return self._async_streaming_completion
except Exception as e:
raise LLMResponseError(e)
def supports_vision(self):
return litellm.supports_vision(self.config.model)