test_hub.py — langchain Source File
Architecture documentation for test_hub.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 713f2f37_0132_6e30_1300_1d936a2ed69c["test_hub.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 713f2f37_0132_6e30_1300_1d936a2ed69c --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"] 713f2f37_0132_6e30_1300_1d936a2ed69c --> 525a7d6f_f455_56e3_854a_c8a7da4a1417 e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"] 713f2f37_0132_6e30_1300_1d936a2ed69c --> e6b4f61e_7b98_6666_3641_26b069517d4a 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"] 713f2f37_0132_6e30_1300_1d936a2ed69c --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c 7c791cd0_0af5_2966_6e05_252994d15716["langchain_classic.runnables.hub"] 713f2f37_0132_6e30_1300_1d936a2ed69c --> 7c791cd0_0af5_2966_6e05_252994d15716 style 713f2f37_0132_6e30_1300_1d936a2ed69c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Any
from unittest.mock import Mock, patch
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import ConfigurableField
from langchain_classic.runnables.hub import HubRunnable
@patch("langchain_classic.hub.pull")
def test_hub_runnable(mock_pull: Mock) -> None:
mock_pull.return_value = ChatPromptTemplate.from_messages(
[
("system", "a"),
("user", "b"),
],
)
basic: HubRunnable = HubRunnable("efriis/my-prompt")
bound = basic.bound
assert isinstance(bound, ChatPromptTemplate)
assert len(bound.messages) == 2
repo_dict = {
"efriis/my-prompt-1": ChatPromptTemplate.from_messages(
[
("system", "a"),
("user", "1"),
],
),
"efriis/my-prompt-2": ChatPromptTemplate.from_messages(
[
("system", "a"),
("user", "2"),
],
),
}
def repo_lookup(owner_repo_commit: str, **_: Any) -> ChatPromptTemplate:
return repo_dict[owner_repo_commit]
@patch("langchain_classic.hub.pull")
def test_hub_runnable_configurable_alternative(mock_pull: Mock) -> None:
mock_pull.side_effect = repo_lookup
original: HubRunnable = HubRunnable("efriis/my-prompt-1")
obj_a1 = original.configurable_alternatives(
ConfigurableField(id="owner_repo_commit", name="Hub ID"),
default_key="a1",
a2=HubRunnable("efriis/my-prompt-2"),
)
obj_a2 = obj_a1.with_config(configurable={"owner_repo_commit": "a2"})
templated = obj_a1.invoke({})
message_a1 = templated.messages[1]
assert message_a1.content == "1"
templated_2 = obj_a2.invoke({})
message_a2 = templated_2.messages[1]
assert message_a2.content == "2"
@patch("langchain_classic.hub.pull")
def test_hub_runnable_configurable_fields(mock_pull: Mock) -> None:
mock_pull.side_effect = repo_lookup
original: HubRunnable = HubRunnable("efriis/my-prompt-1")
obj_configurable = original.configurable_fields(
owner_repo_commit=ConfigurableField(id="owner_repo_commit", name="Hub ID"),
)
templated_1 = obj_configurable.invoke({})
assert templated_1.messages[1].content == "1"
templated_2 = obj_configurable.with_config(
configurable={"owner_repo_commit": "efriis/my-prompt-2"},
).invoke({})
assert templated_2.messages[1].content == "2"
Domain
Subdomains
Functions
Dependencies
- langchain_classic.runnables.hub
- langchain_core.prompts
- langchain_core.runnables
- typing
- unittest.mock
Source
Frequently Asked Questions
What does test_hub.py do?
test_hub.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_hub.py?
test_hub.py defines 4 function(s): repo_lookup, test_hub_runnable, test_hub_runnable_configurable_alternative, test_hub_runnable_configurable_fields.
What does test_hub.py depend on?
test_hub.py imports 5 module(s): langchain_classic.runnables.hub, langchain_core.prompts, langchain_core.runnables, typing, unittest.mock.
Where is test_hub.py in the architecture?
test_hub.py is located at libs/langchain/tests/unit_tests/runnables/test_hub.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/tests/unit_tests/runnables).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free