An AI Agent that interacts with Windows OS at GUI level.
Python
Fix TokenUsage validation error and SyntaxWarning in get_screenshot
jeomon3ae9b92abc5e
diff --git a/windows_use/agent/desktop/service.py b/windows_use/agent/desktop/service.pyindex a93f124..e7078ff 100644--- a/windows_use/agent/desktop/service.py+++ b/windows_use/agent/desktop/service.py@@ -28,7 +28,7 @@ import osimport iologger = logging.getLogger(__name__)-logger.setLevel(logging.INFO)+logger.setLevel(logging.DEBUG)class Desktop:def __init__(self,use_vision:bool=False,use_annotation:bool=False,use_accessibility:bool=True):@@ -634,13 +634,12 @@ class Desktop:except Exception as e:logger.warning(f"Failed to capture virtual screen, using primary screen")screenshot = ImageGrab.grab()- finally:- if as_bytes:- buffered = io.BytesIO()- screenshot.save(buffered, format="PNG")- screenshot = buffered.getvalue()- buffered.close()- return screenshot+ if as_bytes:+ buffered = io.BytesIO()+ screenshot.save(buffered, format="PNG")+ screenshot = buffered.getvalue()+ buffered.close()+ return screenshotdef get_annotated_screenshot(self, nodes: list[TreeElementNode],as_bytes:bool=False) -> bytes|Image.Image:screenshot = self.get_screenshot()diff --git a/windows_use/providers/views.py b/windows_use/providers/views.pyindex 17eeae1..bb722d4 100644--- a/windows_use/providers/views.py+++ b/windows_use/providers/views.py@@ -1,16 +1,17 @@+from typing import Optionalfrom pydantic import BaseModelclass TokenUsage(BaseModel):"""Token usage information from LLM responses."""- prompt_tokens: int=0- completion_tokens: int=0- total_tokens: int=0- image_tokens: int=0- thinking_tokens: int=0- cache_creation_input_tokens: int=0- cache_read_input_tokens: int=0+ prompt_tokens: Optional[int] = 0+ completion_tokens: Optional[int] = 0+ total_tokens: Optional[int] = 0+ image_tokens: Optional[int] = 0+ thinking_tokens: Optional[int] = 0+ cache_creation_input_tokens: Optional[int] = 0+ cache_read_input_tokens: Optional[int] = 0class Metadata(BaseModel):