_convert_from_v1_to_chat_completions() — langchain Function Reference
Architecture documentation for the _convert_from_v1_to_chat_completions() function in openai.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 39ba14d6_ebb3_5712_7b1e_728b0da5bcea["_convert_from_v1_to_chat_completions()"] 3f58992c_878c_57d1_7412_5e64743aa7ba["openai.py"] 39ba14d6_ebb3_5712_7b1e_728b0da5bcea -->|defined in| 3f58992c_878c_57d1_7412_5e64743aa7ba style 39ba14d6_ebb3_5712_7b1e_728b0da5bcea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/block_translators/openai.py lines 263–281
def _convert_from_v1_to_chat_completions(message: AIMessage) -> AIMessage:
"""Convert a v1 message to the Chat Completions format."""
if isinstance(message.content, list):
new_content: list = []
for block in message.content:
if isinstance(block, dict):
block_type = block.get("type")
if block_type == "text":
# Strip annotations
new_content.append({"type": "text", "text": block["text"]})
elif block_type in {"reasoning", "tool_call"}:
pass
else:
new_content.append(block)
else:
new_content.append(block)
return message.model_copy(update={"content": new_content})
return message
Domain
Subdomains
Source
Frequently Asked Questions
What does _convert_from_v1_to_chat_completions() do?
_convert_from_v1_to_chat_completions() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/openai.py.
Where is _convert_from_v1_to_chat_completions() defined?
_convert_from_v1_to_chat_completions() is defined in libs/core/langchain_core/messages/block_translators/openai.py at line 263.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free