anthropic support - dymanic window size / window popup (#2284)

This commit is contained in:
Shuchang Zheng
2025-05-04 00:40:16 -07:00
committed by GitHub
parent a851e8fdd8
commit 8b834436b5
4 changed files with 36 additions and 6 deletions

View File

@@ -491,6 +491,7 @@ class LLMCaller:
tools: list | None = None,
use_message_history: bool = False,
raw_response: bool = False,
window_dimension: Resolution | None = None,
**extra_parameters: Any,
) -> dict[str, Any]:
start_time = time.perf_counter()
@@ -516,7 +517,21 @@ class LLMCaller:
)
if screenshots and self.screenshot_scaling_enabled:
screenshots = resize_screenshots(screenshots, self.screenshot_resize_target_dimension)
target_dimension = self.get_screenshot_resize_target_dimension(window_dimension)
if window_dimension and window_dimension != self.browser_window_dimension and tools:
# THIS situation only applies to Anthropic CUA
LOG.info(
"Window dimension is different from the default browser window dimension when making LLM call",
window_dimension=window_dimension,
browser_window_dimension=self.browser_window_dimension,
)
# update the tools to use the new target dimension
for tool in tools:
if "display_height_px" in tool:
tool["display_height_px"] = target_dimension["height"]
if "display_width_px" in tool:
tool["display_width_px"] = target_dimension["width"]
screenshots = resize_screenshots(screenshots, target_dimension)
await app.ARTIFACT_MANAGER.create_llm_artifact(
data=prompt.encode("utf-8") if prompt else b"",
@@ -683,6 +698,11 @@ class LLMCaller:
return parsed_response
def get_screenshot_resize_target_dimension(self, window_dimension: Resolution | None) -> Resolution:
if window_dimension and window_dimension != self.browser_window_dimension:
return get_resize_target_dimension(window_dimension)
return self.screenshot_resize_target_dimension
async def _dispatch_llm_call(
self,
messages: list[dict[str, Any]],