From 6df8bf85467e1a0551bcbd155c03739da95e262e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Chaves?= Date: Mon, 9 Dec 2024 17:42:06 +0100 Subject: [PATCH] Return "None" when dspy.Image is missing for the input, similarly to str input fields --- dspy/adapters/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dspy/adapters/utils.py b/dspy/adapters/utils.py index 9cddc1fe8..8f048de5d 100644 --- a/dspy/adapters/utils.py +++ b/dspy/adapters/utils.py @@ -61,6 +61,8 @@ def format_field_value(field_info: FieldInfo, value: Any, assume_text=True) -> U except ImportError: raise ImportError("PIL is required to format images; Run `pip install pillow` to install it.") image_value = value + if not image_value: + return {"type": "text", "text": "None"} if not isinstance(image_value, Image): if isinstance(image_value, dict) and "url" in image_value: image_value = image_value["url"]