_get_chat_history() — langchain Function Reference
Architecture documentation for the _get_chat_history() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 867720c0_1f85_5f33_71c5_0415d18e7f52["_get_chat_history()"] 94993a4e_2523_282e_bb19_84e4ccbd2c96["base.py"] 867720c0_1f85_5f33_71c5_0415d18e7f52 -->|defined in| 94993a4e_2523_282e_bb19_84e4ccbd2c96 style 867720c0_1f85_5f33_71c5_0415d18e7f52 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/chains/conversational_retrieval/base.py lines 45–65
def _get_chat_history(chat_history: list[CHAT_TURN_TYPE]) -> str:
buffer = ""
for dialogue_turn in chat_history:
if isinstance(dialogue_turn, BaseMessage):
if len(dialogue_turn.content) > 0:
role_prefix = _ROLE_MAP.get(
dialogue_turn.type,
f"{dialogue_turn.type}: ",
)
buffer += f"\n{role_prefix}{dialogue_turn.content}"
elif isinstance(dialogue_turn, tuple):
human = "Human: " + dialogue_turn[0]
ai = "Assistant: " + dialogue_turn[1]
buffer += f"\n{human}\n{ai}"
else:
msg = ( # type: ignore[unreachable]
f"Unsupported chat history format: {type(dialogue_turn)}."
f" Full chat history: {chat_history} "
)
raise ValueError(msg) # noqa: TRY004
return buffer
Domain
Subdomains
Source
Frequently Asked Questions
What does _get_chat_history() do?
_get_chat_history() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/chains/conversational_retrieval/base.py.
Where is _get_chat_history() defined?
_get_chat_history() is defined in libs/langchain/langchain_classic/chains/conversational_retrieval/base.py at line 45.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free