_compat.py — langchain Source File
Architecture documentation for _compat.py, a python file in the langchain codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 229dd2f8_cd21_122c_8dc9_e4e6685d089f["_compat.py"] 9d14ea65_8b2e_6721_a947_acc89905651f["json"] 229dd2f8_cd21_122c_8dc9_e4e6685d089f --> 9d14ea65_8b2e_6721_a947_acc89905651f feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 229dd2f8_cd21_122c_8dc9_e4e6685d089f --> feec1ec4_6917_867b_d228_b134d0ff8099 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] 229dd2f8_cd21_122c_8dc9_e4e6685d089f --> 9444498b_8066_55c7_b3a2_1d90c4162a32 style 229dd2f8_cd21_122c_8dc9_e4e6685d089f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from __future__ import annotations
import json
from typing import Any, cast
from langchain_core.messages import content as types
def _convert_annotation_from_v1(annotation: types.Annotation) -> dict[str, Any]:
"""Convert LangChain annotation format to Anthropic's native citation format."""
if annotation["type"] == "non_standard_annotation":
return annotation["value"]
if annotation["type"] == "citation":
if "url" in annotation:
# web_search_result_location
out: dict[str, Any] = {}
if cited_text := annotation.get("cited_text"):
out["cited_text"] = cited_text
if "encrypted_index" in annotation.get("extras", {}):
out["encrypted_index"] = annotation.get("extras", {})["encrypted_index"]
if "title" in annotation:
out["title"] = annotation["title"]
out["type"] = "web_search_result_location"
out["url"] = annotation.get("url")
for key, value in annotation.get("extras", {}).items():
if key not in out:
out[key] = value
return out
if "start_char_index" in annotation.get("extras", {}):
# char_location
out = {"type": "char_location"}
for field in ["cited_text"]:
if value := annotation.get(field):
out[field] = value
if title := annotation.get("title"):
out["document_title"] = title
for key, value in annotation.get("extras", {}).items():
out[key] = value
out = {k: out[k] for k in sorted(out)}
return out
if "search_result_index" in annotation.get("extras", {}):
# search_result_location
out = {"type": "search_result_location"}
for field in ["cited_text", "title"]:
if value := annotation.get(field):
out[field] = value
for key, value in annotation.get("extras", {}).items():
out[key] = value
return out
if "start_block_index" in annotation.get("extras", {}):
// ... (140 more lines)
Domain
Subdomains
Dependencies
- json
- langchain_core.messages
- typing
Source
Frequently Asked Questions
What does _compat.py do?
_compat.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What functions are defined in _compat.py?
_compat.py defines 2 function(s): _convert_annotation_from_v1, _convert_from_v1_to_anthropic.
What does _compat.py depend on?
_compat.py imports 3 module(s): json, langchain_core.messages, typing.
Where is _compat.py in the architecture?
_compat.py is located at libs/partners/anthropic/langchain_anthropic/_compat.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/partners/anthropic/langchain_anthropic).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free