MCPcopy Create free account
hub / github.com/microsoft/Webwright / run_self_reflection_async

Function run_self_reflection_async

src/webwright/tools/self_reflection.py:379–447  ·  view source on GitHub ↗
(
    *,
    images: list[Path],
    image_judge_system_prompt: str,
    image_judge_user_prompt: str,
    final_verdict_system_prompt: str,
    final_verdict_user_prompt: str,
    action_history_log: str,
    max_image_parse_retries: int,
    final_max_new_tokens: int,
    image_max_new_tokens: int,
    model_client: Any,
)

Source from the content-addressed store, hash-verified

377
378
379async def run_self_reflection_async(
380 *,
381 images: list[Path],
382 image_judge_system_prompt: str,
383 image_judge_user_prompt: str,
384 final_verdict_system_prompt: str,
385 final_verdict_user_prompt: str,
386 action_history_log: str,
387 max_image_parse_retries: int,
388 final_max_new_tokens: int,
389 image_max_new_tokens: int,
390 model_client: Any,
391) -> SelfReflectionResult:
392 model_name = str(getattr(model_client.config, "model_name", ""))
393 endpoint = _model_endpoint(model_client)
394
395 if images:
396 per_image = await asyncio.gather(
397 *(
398 _judge_one_image(
399 image_path=path,
400 image_judge_system_prompt=image_judge_system_prompt,
401 image_judge_user_prompt=image_judge_user_prompt,
402 model_client=model_client,
403 max_new_tokens=image_max_new_tokens,
404 max_parse_retries=max_image_parse_retries,
405 )
406 for path in images
407 )
408 )
409 else:
410 per_image = []
411
412 image_paths = [record["image_path"] for record in per_image]
413 reasonings = [record["Reasoning"] or "" for record in per_image]
414
415 reasonings_block = "\n".join(
416 f"{i + 1}. {text}" for i, text in enumerate(reasonings)
417 )
418
419 final_user_text = _render_final_verdict_user_prompt(
420 final_verdict_user_prompt,
421 image_reasonings=reasonings_block,
422 action_history_log=action_history_log,
423 )
424
425 user_content: list[dict[str, Any]] = [text_part(final_user_text)]
426 for path_str in image_paths:
427 user_content.append(_high_detail_image_part_from_path(Path(path_str)))
428
429 final_response = await asyncio.to_thread(
430 _call_model,
431 model_client=model_client,
432 system_prompt=final_verdict_system_prompt,
433 user_content=user_content,
434 max_new_tokens=final_max_new_tokens,
435 )
436 predicted_label = _parse_final_verdict(final_response)

Callers 1

run_self_reflectionFunction · 0.85

Calls 7

text_partFunction · 0.90
_model_endpointFunction · 0.85
_judge_one_imageFunction · 0.85
_parse_final_verdictFunction · 0.85

Tested by

no test coverage detected