Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Convert text items from 'text' to 'input_text' for Responses API
Co-authored-by: TomeHirata <[email protected]>
  • Loading branch information
Copilot and TomeHirata committed Oct 30, 2025
commit 0055def1ede151b07946214682cf56abdb97294c
14 changes: 12 additions & 2 deletions dspy/clients/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,16 +491,26 @@ def _convert_content_item_to_responses_format(item: dict[str, Any]) -> dict[str,
To:
{"type": "input_image", "image_url": "..."}

For text and other types, passes through as-is (already in correct format).
For text, converts from:
{"type": "text", "text": "..."}
To:
{"type": "input_text", "text": "..."}

For other types, passes through as-is.
"""
if item.get("type") == "image_url":
image_url = item.get("image_url", {}).get("url", "")
return {
"type": "input_image",
"image_url": image_url,
}
elif item.get("type") == "text":
return {
"type": "input_text",
"text": item.get("text", ""),
}

# For non-image items, return as-is
# For other items, return as-is
return item


Expand Down
4 changes: 2 additions & 2 deletions tests/clients/test_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ def test_responses_api_converts_images_correctly():
content = result["input"][0]["content"]
assert len(content) == 2

# First item should be text (passed through as-is since it's already in correct format)
assert content[0]["type"] == "text"
# First item should be text converted to input_text format
assert content[0]["type"] == "input_text"
assert content[0]["text"] == "What's in this image?"

# Second item should be converted to input_image format
Expand Down