The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
core:adds tests for partial_variables (#15427)
Dariusz Kajtoch15b6c049d4d8
diff --git a/libs/core/tests/unit_tests/examples/simple_prompt.yaml b/libs/core/tests/unit_tests/examples/simple_prompt.yamlindex 5377b92f20..ffb3acd339 100644--- a/libs/core/tests/unit_tests/examples/simple_prompt.yaml+++ b/libs/core/tests/unit_tests/examples/simple_prompt.yaml@@ -1,5 +1,7 @@_type: promptinput_variables:- ["adjective", "content"]+ ["adjective"]+partial_variables:+ content: dogstemplate:Tell me a {adjective} joke about {content}.diff --git a/libs/core/tests/unit_tests/prompts/test_loading.py b/libs/core/tests/unit_tests/prompts/test_loading.pyindex a89ffaf186..afad88766a 100644--- a/libs/core/tests/unit_tests/prompts/test_loading.py+++ b/libs/core/tests/unit_tests/prompts/test_loading.py@@ -28,7 +28,8 @@ def test_loading_from_YAML() -> None:"""Test loading from yaml file."""prompt = load_prompt(EXAMPLE_DIR / "simple_prompt.yaml")expected_prompt = PromptTemplate(- input_variables=["adjective", "content"],+ input_variables=["adjective"],+ partial_variables={"content": "dogs"},template="Tell me a {adjective} joke about {content}.",)assert prompt == expected_promptdiff --git a/libs/core/tests/unit_tests/prompts/test_prompt.py b/libs/core/tests/unit_tests/prompts/test_prompt.pyindex ec01e426f7..f50b71bea8 100644--- a/libs/core/tests/unit_tests/prompts/test_prompt.py+++ b/libs/core/tests/unit_tests/prompts/test_prompt.py@@ -1,4 +1,6 @@"""Test functionality related to prompts."""+from unittest import mock+import pytestfrom langchain_core.prompts.prompt import PromptTemplate@@ -34,6 +36,22 @@ def test_prompt_from_template() -> None:assert prompt == expected_prompt+def test_prompt_from_template_with_partial_variables() -> None:+ """Test prompts can be constructed from a template with partial variables."""+ # given+ template = "This is a {foo} test {bar}."+ partial_variables = {"bar": "baz"}+ # when+ prompt = PromptTemplate.from_template(template, partial_variables=partial_variables)+ # then+ expected_prompt = PromptTemplate(+ template=template,+ input_variables=["foo"],+ partial_variables=partial_variables,+ )+ assert prompt == expected_prompt++def test_prompt_missing_input_variables() -> None:"""Test error is raised when input variables are not provided."""template = "This is a {foo} test."@@ -118,6 +136,26 @@ def test_prompt_from_file() -> None:assert prompt.template == "Question: {question}\nAnswer:"+def test_prompt_from_file_with_partial_variables() -> None:+ """Test prompt can be successfully constructed from a file+ with partial variables."""+ # given+ template = "This is a {foo} test {bar}."+ partial_variables = {"bar": "baz"}+ # when+ with mock.patch("builtins.open", mock.mock_open(read_data=template)):+ prompt = PromptTemplate.from_file(+ "mock_file_name", partial_variables=partial_variables+ )+ # then+ expected_prompt = PromptTemplate(+ template=template,+ input_variables=["foo"],+ partial_variables=partial_variables,+ )+ assert prompt == expected_prompt++def test_partial_init_string() -> None:"""Test prompt can be initialized with partial variables."""template = "This is a {foo} test."