mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Refactor: Shorter syntax. (#4753)
This commit is contained in:
parent
add0e7d05c
commit
df9e9fca5a
@ -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
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user