Refactor: Shorter syntax. (#4753)

This commit is contained in:
tofarr 2024-11-05 09:09:14 -07:00 committed by GitHub
parent add0e7d05c
commit df9e9fca5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 19 deletions

View File

@ -6,22 +6,14 @@ __package_name__ = 'openhands_ai'
def get_version():
try:
from importlib.metadata import PackageNotFoundError, version
try:
return version(__package_name__)
except PackageNotFoundError:
pass
except ImportError:
return version(__package_name__)
except (ImportError, PackageNotFoundError):
pass
try:
from pkg_resources import DistributionNotFound, get_distribution
try:
return get_distribution(__package_name__).version
except DistributionNotFound:
pass
except ImportError:
return get_distribution(__package_name__).version
except (ImportError, DistributionNotFound):
pass
# Try getting the version from pyproject.toml

View File

@ -312,7 +312,7 @@ class AgentController:
if new_state == self.state.agent_state:
return
if new_state == AgentState.STOPPED or new_state == AgentState.ERROR:
if new_state in (AgentState.STOPPED, AgentState.ERROR):
self.reset_task()
elif (
new_state == AgentState.RUNNING
@ -338,8 +338,7 @@ class AgentController:
if self.state.metrics.accumulated_cost >= self.max_budget_per_task:
self.max_budget_per_task += self._initial_max_budget_per_task
elif self._pending_action is not None and (
new_state == AgentState.USER_CONFIRMED
or new_state == AgentState.USER_REJECTED
new_state in (AgentState.USER_CONFIRMED, AgentState.USER_REJECTED)
):
if hasattr(self._pending_action, 'thought'):
self._pending_action.thought = '' # type: ignore[union-attr]

View File

@ -182,10 +182,7 @@ class Session:
await asyncio.sleep(0.001) # This flushes the data to the client
self.last_active_ts = int(time.time())
return True
except RuntimeError:
self.is_alive = False
return False
except WebSocketDisconnect:
except (RuntimeError, WebSocketDisconnect):
self.is_alive = False
return False