fix(openai): handle missing 'text' key in responses API content blocks (#34198)

This commit is contained in:
j3r0lin
2025-12-12 22:39:12 +08:00
committed by GitHub
parent 087107557f
commit 5720dea41b
2 changed files with 38 additions and 1 deletions

View File

@@ -4048,9 +4048,14 @@ def _construct_responses_api_input(messages: Sequence[BaseMessage]) -> list:
if block_type in ("text", "output_text", "refusal"):
msg_id = block.get("id")
if block_type in ("text", "output_text"):
# Defensive check: block may not have "text" key
text = block.get("text")
if text is None:
# Skip blocks without text content
continue
new_block = {
"type": "output_text",
"text": block["text"],
"text": text,
"annotations": [
_format_annotation_from_lc(annotation)
for annotation in block.get("annotations") or []