_convert_to_v1_from_responses() — langchain Function Reference
Architecture documentation for the _convert_to_v1_from_responses() function in openai.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 24124a46_40a1_1ce3_a730_b36c3f9a0520["_convert_to_v1_from_responses()"] 3f58992c_878c_57d1_7412_5e64743aa7ba["openai.py"] 24124a46_40a1_1ce3_a730_b36c3f9a0520 -->|defined in| 3f58992c_878c_57d1_7412_5e64743aa7ba af54f3fb_5bfb_6940_293f_4c3b25c7f24f["translate_content()"] af54f3fb_5bfb_6940_293f_4c3b25c7f24f -->|calls| 24124a46_40a1_1ce3_a730_b36c3f9a0520 108d3f87_48ae_3513_b686_eca17b966d18["translate_content_chunk()"] 108d3f87_48ae_3513_b686_eca17b966d18 -->|calls| 24124a46_40a1_1ce3_a730_b36c3f9a0520 87592a59_792a_6756_12b5_e2905efc3b01["_convert_annotation_to_v1()"] 24124a46_40a1_1ce3_a730_b36c3f9a0520 -->|calls| 87592a59_792a_6756_12b5_e2905efc3b01 e8ab70ec_6b5a_2e63_1d72_8f245fdd3a53["_explode_reasoning()"] 24124a46_40a1_1ce3_a730_b36c3f9a0520 -->|calls| e8ab70ec_6b5a_2e63_1d72_8f245fdd3a53 style 24124a46_40a1_1ce3_a730_b36c3f9a0520 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/block_translators/openai.py lines 652–990
def _convert_to_v1_from_responses(message: AIMessage) -> list[types.ContentBlock]:
"""Convert a Responses message to v1 format."""
def _iter_blocks() -> Iterator[types.ContentBlock]:
for raw_block in message.content:
if not isinstance(raw_block, dict):
continue
block = raw_block.copy()
block_type = block.get("type")
if block_type == "text":
if "text" not in block:
block["text"] = ""
if "annotations" in block:
block["annotations"] = [
_convert_annotation_to_v1(a) for a in block["annotations"]
]
if "index" in block:
block["index"] = f"lc_txt_{block['index']}"
yield cast("types.TextContentBlock", block)
elif block_type == "reasoning":
yield from _explode_reasoning(block)
elif block_type == "image_generation_call" and (
result := block.get("result")
):
new_block = {"type": "image", "base64": result}
if output_format := block.get("output_format"):
new_block["mime_type"] = f"image/{output_format}"
if "id" in block:
new_block["id"] = block["id"]
if "index" in block:
new_block["index"] = f"lc_img_{block['index']}"
for extra_key in (
"status",
"background",
"output_format",
"quality",
"revised_prompt",
"size",
):
if extra_key in block:
if "extras" not in new_block:
new_block["extras"] = {}
new_block["extras"][extra_key] = block[extra_key]
yield cast("types.ImageContentBlock", new_block)
elif block_type == "function_call":
tool_call_block: (
types.ToolCall | types.InvalidToolCall | types.ToolCallChunk | None
) = None
call_id = block.get("call_id", "")
if (
isinstance(message, AIMessageChunk)
and len(message.tool_call_chunks) == 1
and message.chunk_position != "last"
):
tool_call_block = message.tool_call_chunks[0].copy() # type: ignore[assignment]
elif call_id:
for tool_call in message.tool_calls or []:
if tool_call.get("id") == call_id:
tool_call_block = {
"type": "tool_call",
"name": tool_call["name"],
"args": tool_call["args"],
"id": tool_call.get("id"),
}
break
else:
for invalid_tool_call in message.invalid_tool_calls or []:
if invalid_tool_call.get("id") == call_id:
tool_call_block = invalid_tool_call.copy()
break
if tool_call_block:
if "id" in block:
if "extras" not in tool_call_block:
tool_call_block["extras"] = {}
tool_call_block["extras"]["item_id"] = block["id"]
if "index" in block:
Domain
Subdomains
Source
Frequently Asked Questions
What does _convert_to_v1_from_responses() do?
_convert_to_v1_from_responses() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/openai.py.
Where is _convert_to_v1_from_responses() defined?
_convert_to_v1_from_responses() is defined in libs/core/langchain_core/messages/block_translators/openai.py at line 652.
What does _convert_to_v1_from_responses() call?
_convert_to_v1_from_responses() calls 2 function(s): _convert_annotation_to_v1, _explode_reasoning.
What calls _convert_to_v1_from_responses()?
_convert_to_v1_from_responses() is called by 2 function(s): translate_content, translate_content_chunk.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free