79589961

Date: 2025-04-24 06:38:31
Score: 1.5
Natty:
Report link

Problem solved at

https://github.com/langchain-ai/langgraph/discussions/4384

import base64

from langchain_core.tools import tool


def image_to_base64(image_path: str) -> str:
    with open(image_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
        return encoded_string.decode('utf-8')


def do_screenshot_and_save_it_to_local_disk():
    # Pretend that this function will take a screenshot and return the path of the image.
    return "/path/to/pic.png"


@tool
def get_screenshot():
    picture_path = do_screenshot_and_save_it_to_local_disk()
    return [
        {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{image_to_base64(picture_path)}"}}
    ]
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Letian