_convert_to_v1_from_chat_completions_chunk() — langchain Function Reference
Architecture documentation for the _convert_to_v1_from_chat_completions_chunk() function in openai.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5ae47888_fb2c_d35d_36a3_9d490f02a790["_convert_to_v1_from_chat_completions_chunk()"] 3f58992c_878c_57d1_7412_5e64743aa7ba["openai.py"] 5ae47888_fb2c_d35d_36a3_9d490f02a790 -->|defined in| 3f58992c_878c_57d1_7412_5e64743aa7ba 108d3f87_48ae_3513_b686_eca17b966d18["translate_content_chunk()"] 108d3f87_48ae_3513_b686_eca17b966d18 -->|calls| 5ae47888_fb2c_d35d_36a3_9d490f02a790 style 5ae47888_fb2c_d35d_36a3_9d490f02a790 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/block_translators/openai.py lines 226–260
def _convert_to_v1_from_chat_completions_chunk(
chunk: AIMessageChunk,
) -> list[types.ContentBlock]:
"""Mutate a Chat Completions chunk to v1 format."""
content_blocks: list[types.ContentBlock] = []
if isinstance(chunk.content, str):
if chunk.content:
content_blocks = [{"type": "text", "text": chunk.content}]
else:
content_blocks = []
if chunk.chunk_position == "last":
for tool_call in chunk.tool_calls:
content_blocks.append(
{
"type": "tool_call",
"name": tool_call["name"],
"args": tool_call["args"],
"id": tool_call.get("id"),
}
)
else:
for tool_call_chunk in chunk.tool_call_chunks:
tc: types.ToolCallChunk = {
"type": "tool_call_chunk",
"id": tool_call_chunk.get("id"),
"name": tool_call_chunk.get("name"),
"args": tool_call_chunk.get("args"),
}
if (idx := tool_call_chunk.get("index")) is not None:
tc["index"] = idx
content_blocks.append(tc)
return content_blocks
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _convert_to_v1_from_chat_completions_chunk() do?
_convert_to_v1_from_chat_completions_chunk() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/openai.py.
Where is _convert_to_v1_from_chat_completions_chunk() defined?
_convert_to_v1_from_chat_completions_chunk() is defined in libs/core/langchain_core/messages/block_translators/openai.py at line 226.
What calls _convert_to_v1_from_chat_completions_chunk()?
_convert_to_v1_from_chat_completions_chunk() is called by 1 function(s): translate_content_chunk.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free