Home / Function/ _convert_annotation_from_v1() — langchain Function Reference

_convert_annotation_from_v1() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/_compat.py lines 176–208

def _convert_annotation_from_v1(annotation: types.Annotation) -> dict[str, Any]:
    """Convert a v1 `Annotation` to the v0.3 format (for Responses API)."""
    if annotation["type"] == "citation":
        new_ann: dict[str, Any] = {}
        for field in ("end_index", "start_index"):
            if field in annotation:
                new_ann[field] = annotation[field]

        if "url" in annotation:
            # URL citation
            if "title" in annotation:
                new_ann["title"] = annotation["title"]
            new_ann["type"] = "url_citation"
            new_ann["url"] = annotation["url"]

            if extra_fields := annotation.get("extras"):
                new_ann.update(dict(extra_fields.items()))
        else:
            # Document citation
            new_ann["type"] = "file_citation"

            if extra_fields := annotation.get("extras"):
                new_ann.update(dict(extra_fields.items()))

            if "title" in annotation:
                new_ann["filename"] = annotation["title"]

        return new_ann

    if annotation["type"] == "non_standard_annotation":
        return annotation["value"]

    return dict(annotation)

Domain

Subdomains

Frequently Asked Questions

What does _convert_annotation_from_v1() do?
_convert_annotation_from_v1() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/_compat.py.
Where is _convert_annotation_from_v1() defined?
_convert_annotation_from_v1() is defined in libs/partners/openai/langchain_openai/chat_models/_compat.py at line 176.
What calls _convert_annotation_from_v1()?
_convert_annotation_from_v1() is called by 1 function(s): _convert_from_v1_to_responses.

Analyze Your Own Codebase

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

Try Supermodel Free