_convert_dict_to_message() — langchain Function Reference
Architecture documentation for the _convert_dict_to_message() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2d3513e4_e3e4_8c27_2865_6eb2193506c3["_convert_dict_to_message()"] 21b8cbde_a9dc_13d6_83f9_010248e2bfc8["chat_models.py"] 2d3513e4_e3e4_8c27_2865_6eb2193506c3 -->|defined in| 21b8cbde_a9dc_13d6_83f9_010248e2bfc8 c5fc57f8_7702_2a2f_411d_d1ed1dae6cb1["_create_chat_result()"] c5fc57f8_7702_2a2f_411d_d1ed1dae6cb1 -->|calls| 2d3513e4_e3e4_8c27_2865_6eb2193506c3 style 2d3513e4_e3e4_8c27_2865_6eb2193506c3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/fireworks/langchain_fireworks/chat_models.py lines 99–155
def _convert_dict_to_message(_dict: Mapping[str, Any]) -> BaseMessage:
"""Convert a dictionary to a LangChain message.
Args:
_dict: The dictionary.
Returns:
The LangChain message.
"""
role = _dict.get("role")
if role == "user":
return HumanMessage(content=_dict.get("content", ""))
if role == "assistant":
# Fix for azure
# Also Fireworks returns None for tool invocations
content = _dict.get("content", "") or ""
additional_kwargs: dict = {}
if reasoning_content := _dict.get("reasoning_content"):
additional_kwargs["reasoning_content"] = reasoning_content
if function_call := _dict.get("function_call"):
additional_kwargs["function_call"] = dict(function_call)
tool_calls = []
invalid_tool_calls = []
if raw_tool_calls := _dict.get("tool_calls"):
additional_kwargs["tool_calls"] = raw_tool_calls
for raw_tool_call in raw_tool_calls:
try:
tool_calls.append(parse_tool_call(raw_tool_call, return_id=True))
except Exception as e:
invalid_tool_calls.append(
dict(make_invalid_tool_call(raw_tool_call, str(e)))
)
return AIMessage(
content=content,
additional_kwargs=additional_kwargs,
tool_calls=tool_calls,
invalid_tool_calls=invalid_tool_calls,
)
if role == "system":
return SystemMessage(content=_dict.get("content", ""))
if role == "function":
return FunctionMessage(
content=_dict.get("content", ""), name=_dict.get("name", "")
)
if role == "tool":
additional_kwargs = {}
if "name" in _dict:
additional_kwargs["name"] = _dict["name"]
return ToolMessage(
content=_dict.get("content", ""),
tool_call_id=_dict.get("tool_call_id", ""),
additional_kwargs=additional_kwargs,
)
return ChatMessage(content=_dict.get("content", ""), role=role or "")
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _convert_dict_to_message() do?
_convert_dict_to_message() is a function in the langchain codebase, defined in libs/partners/fireworks/langchain_fireworks/chat_models.py.
Where is _convert_dict_to_message() defined?
_convert_dict_to_message() is defined in libs/partners/fireworks/langchain_fireworks/chat_models.py at line 99.
What calls _convert_dict_to_message()?
_convert_dict_to_message() is called by 1 function(s): _create_chat_result.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free