Home / Function/ _convert_from_v1_to_responses() — langchain Function Reference

_convert_from_v1_to_responses() — langchain Function Reference

Architecture documentation for the _convert_from_v1_to_responses() function in _compat.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  debfdf1e_2d5b_2867_c955_09be2be39501["_convert_from_v1_to_responses()"]
  92333051_7f77_b57b_d874_abb7bac2bbe0["_compat.py"]
  debfdf1e_2d5b_2867_c955_09be2be39501 -->|defined in| 92333051_7f77_b57b_d874_abb7bac2bbe0
  6f2766c9_79f6_a644_8da6_de10559ac538["_convert_annotation_from_v1()"]
  debfdf1e_2d5b_2867_c955_09be2be39501 -->|calls| 6f2766c9_79f6_a644_8da6_de10559ac538
  f305586f_ba7b_c515_2b74_74a615fa9242["_implode_reasoning_blocks()"]
  debfdf1e_2d5b_2867_c955_09be2be39501 -->|calls| f305586f_ba7b_c515_2b74_74a615fa9242
  d2907510_6a85_68c1_c20d_e21ea9422b36["_consolidate_calls()"]
  debfdf1e_2d5b_2867_c955_09be2be39501 -->|calls| d2907510_6a85_68c1_c20d_e21ea9422b36
  style debfdf1e_2d5b_2867_c955_09be2be39501 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/_compat.py lines 403–454

def _convert_from_v1_to_responses(
    content: list[types.ContentBlock], tool_calls: list[types.ToolCall]
) -> list[dict[str, Any]]:
    new_content: list = []
    for block in content:
        if block["type"] == "text" and "annotations" in block:
            # Need a copy because we're changing the annotations list
            new_block = dict(block)
            new_block["annotations"] = [
                _convert_annotation_from_v1(a) for a in block["annotations"]
            ]
            new_content.append(new_block)
        elif block["type"] == "tool_call":
            new_block = {"type": "function_call", "call_id": block["id"]}
            if "extras" in block and "item_id" in block["extras"]:
                new_block["id"] = block["extras"]["item_id"]
            if "name" in block:
                new_block["name"] = block["name"]
            if "extras" in block and "arguments" in block["extras"]:
                new_block["arguments"] = block["extras"]["arguments"]
            if any(key not in block for key in ("name", "arguments")):
                matching_tool_calls = [
                    call for call in tool_calls if call["id"] == block["id"]
                ]
                if matching_tool_calls:
                    tool_call = matching_tool_calls[0]
                    if "name" not in block:
                        new_block["name"] = tool_call["name"]
                    if "arguments" not in block:
                        new_block["arguments"] = json.dumps(tool_call["args"])
            new_content.append(new_block)
        elif (
            is_data_content_block(cast(dict, block))
            and block["type"] == "image"
            and "base64" in block
            and isinstance(block.get("id"), str)
            and block["id"].startswith("ig_")
        ):
            new_block = {"type": "image_generation_call", "result": block["base64"]}
            for extra_key in ("id", "status"):
                if extra_key in block:
                    new_block[extra_key] = block[extra_key]  # type: ignore[typeddict-item]
                elif extra_key in block.get("extras", {}):
                    new_block[extra_key] = block["extras"][extra_key]
            new_content.append(new_block)
        elif block["type"] == "non_standard" and "value" in block:
            new_content.append(block["value"])
        else:
            new_content.append(block)

    new_content = list(_implode_reasoning_blocks(new_content))
    return list(_consolidate_calls(new_content))

Domain

Subdomains

Frequently Asked Questions

What does _convert_from_v1_to_responses() do?
_convert_from_v1_to_responses() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/_compat.py.
Where is _convert_from_v1_to_responses() defined?
_convert_from_v1_to_responses() is defined in libs/partners/openai/langchain_openai/chat_models/_compat.py at line 403.
What does _convert_from_v1_to_responses() call?
_convert_from_v1_to_responses() calls 3 function(s): _consolidate_calls, _convert_annotation_from_v1, _implode_reasoning_blocks.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free