_convert_delta_to_message_chunk() — langchain Function Reference
Architecture documentation for the _convert_delta_to_message_chunk() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 48f104ff_5195_d7be_593e_90381b500a59["_convert_delta_to_message_chunk()"] 36b59643_acfc_fb1d_752e_ae7ec32a79a4["ChatPerplexity"] 48f104ff_5195_d7be_593e_90381b500a59 -->|defined in| 36b59643_acfc_fb1d_752e_ae7ec32a79a4 d798c5eb_b3ec_7dcd_afbe_81031dc680c3["_stream()"] d798c5eb_b3ec_7dcd_afbe_81031dc680c3 -->|calls| 48f104ff_5195_d7be_593e_90381b500a59 b2a0fb65_dded_ba54_3fc4_cf222600b071["_astream()"] b2a0fb65_dded_ba54_3fc4_cf222600b071 -->|calls| 48f104ff_5195_d7be_593e_90381b500a59 style 48f104ff_5195_d7be_593e_90381b500a59 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/perplexity/langchain_perplexity/chat_models.py lines 386–413
def _convert_delta_to_message_chunk(
self, _dict: Mapping[str, Any], default_class: type[BaseMessageChunk]
) -> BaseMessageChunk:
role = _dict.get("role")
content = _dict.get("content") or ""
additional_kwargs: dict = {}
if _dict.get("function_call"):
function_call = dict(_dict["function_call"])
if "name" in function_call and function_call["name"] is None:
function_call["name"] = ""
additional_kwargs["function_call"] = function_call
if _dict.get("tool_calls"):
additional_kwargs["tool_calls"] = _dict["tool_calls"]
if role == "user" or default_class == HumanMessageChunk:
return HumanMessageChunk(content=content)
elif role == "assistant" or default_class == AIMessageChunk:
return AIMessageChunk(content=content, additional_kwargs=additional_kwargs)
elif role == "system" or default_class == SystemMessageChunk:
return SystemMessageChunk(content=content)
elif role == "function" or default_class == FunctionMessageChunk:
return FunctionMessageChunk(content=content, name=_dict["name"])
elif role == "tool" or default_class == ToolMessageChunk:
return ToolMessageChunk(content=content, tool_call_id=_dict["tool_call_id"])
elif role or default_class == ChatMessageChunk:
return ChatMessageChunk(content=content, role=role) # type: ignore[arg-type]
else:
return default_class(content=content) # type: ignore[call-arg]
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _convert_delta_to_message_chunk() do?
_convert_delta_to_message_chunk() is a function in the langchain codebase, defined in libs/partners/perplexity/langchain_perplexity/chat_models.py.
Where is _convert_delta_to_message_chunk() defined?
_convert_delta_to_message_chunk() is defined in libs/partners/perplexity/langchain_perplexity/chat_models.py at line 386.
What calls _convert_delta_to_message_chunk()?
_convert_delta_to_message_chunk() is called by 2 function(s): _astream, _stream.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free