From b8fc3fc36686f6dc95fb74fcccad5436a552e3d7 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Wed, 15 Jan 2025 11:27:15 +0100 Subject: [PATCH] langchain: Bump ruff version to 0.9 --- libs/langchain/langchain/agents/initialize.py | 3 +- libs/langchain/langchain/agents/loading.py | 3 +- .../langchain/callbacks/tracers/logging.py | 4 +- libs/langchain/langchain/chains/api/base.py | 1 + .../chains/openai_functions/openapi.py | 2 +- .../chains/openai_tools/extraction.py | 5 +- .../question_answering/refine_prompts.py | 11 +- libs/langchain/langchain/chains/sequential.py | 6 +- libs/langchain/langchain/chat_models/base.py | 6 +- libs/langchain/langchain/embeddings/base.py | 3 +- .../evaluation/embedding_distance/base.py | 15 +- .../langchain/langchain/memory/chat_memory.py | 10 +- .../document_compressors/cohere_rerank.py | 5 +- .../langchain/retrievers/ensemble.py | 5 +- .../smith/evaluation/runner_utils.py | 3 +- libs/langchain/poetry.lock | 63 ++-- libs/langchain/pyproject.toml | 3 +- .../tests/unit_tests/agents/test_agent.py | 339 +++++++++--------- .../tests/unit_tests/agents/test_mrkl.py | 16 +- .../chains/test_constitutional_ai.py | 6 +- .../chains/test_history_aware_retriever.py | 5 +- .../tests/unit_tests/chains/test_llm_math.py | 2 +- .../evaluation/parsing/test_base.py | 8 +- .../test_pandas_dataframe_parser.py | 6 +- .../tests/unit_tests/runnables/test_hub.py | 15 +- .../runnables/test_openai_functions.py | 4 +- .../smith/evaluation/test_runner_utils.py | 15 +- 27 files changed, 316 insertions(+), 248 deletions(-) diff --git a/libs/langchain/langchain/agents/initialize.py b/libs/langchain/langchain/agents/initialize.py index cbcf06c5a3a37..86d274b70c981 100644 --- a/libs/langchain/langchain/agents/initialize.py +++ b/libs/langchain/langchain/agents/initialize.py @@ -84,8 +84,7 @@ def initialize_agent( pass else: raise ValueError( - "Somehow both `agent` and `agent_path` are None, " - "this should never happen." + "Somehow both `agent` and `agent_path` are None, this should never happen." ) return AgentExecutor.from_agent_and_tools( agent=agent_obj, diff --git a/libs/langchain/langchain/agents/loading.py b/libs/langchain/langchain/agents/loading.py index 83d2b56f499a0..e9aac8c3a520a 100644 --- a/libs/langchain/langchain/agents/loading.py +++ b/libs/langchain/langchain/agents/loading.py @@ -58,8 +58,7 @@ def load_agent_from_config( if load_from_tools: if llm is None: raise ValueError( - "If `load_from_llm_and_tools` is set to True, " - "then LLM must be provided" + "If `load_from_llm_and_tools` is set to True, then LLM must be provided" ) if tools is None: raise ValueError( diff --git a/libs/langchain/langchain/callbacks/tracers/logging.py b/libs/langchain/langchain/callbacks/tracers/logging.py index 7cfc9a72f088b..a6bad951a9d16 100644 --- a/libs/langchain/langchain/callbacks/tracers/logging.py +++ b/libs/langchain/langchain/callbacks/tracers/logging.py @@ -41,6 +41,6 @@ def on_text( except TracerException: crumbs_str = "" self.function_callback( - f'{get_colored_text("[text]", color="blue")}' - f' {get_bolded_text(f"{crumbs_str}New text:")}\n{text}' + f"{get_colored_text('[text]', color='blue')}" + f" {get_bolded_text(f'{crumbs_str}New text:')}\n{text}" ) diff --git a/libs/langchain/langchain/chains/api/base.py b/libs/langchain/langchain/chains/api/base.py index c8d155f696ff7..69eb79096dd43 100644 --- a/libs/langchain/langchain/chains/api/base.py +++ b/libs/langchain/langchain/chains/api/base.py @@ -370,6 +370,7 @@ def from_llm_and_api_docs( @property def _chain_type(self) -> str: return "api_chain" + except ImportError: class APIChain: # type: ignore[no-redef] diff --git a/libs/langchain/langchain/chains/openai_functions/openapi.py b/libs/langchain/langchain/chains/openai_functions/openapi.py index de4ba38dcd7eb..6f606ee5c86aa 100644 --- a/libs/langchain/langchain/chains/openai_functions/openapi.py +++ b/libs/langchain/langchain/chains/openai_functions/openapi.py @@ -233,7 +233,7 @@ def _call( response = ( f"{api_response.status_code}: {api_response.reason}" + f"\nFor {name} " - + f"Called with args: {args.get('params','')}" + + f"Called with args: {args.get('params', '')}" ) else: try: diff --git a/libs/langchain/langchain/chains/openai_tools/extraction.py b/libs/langchain/langchain/chains/openai_tools/extraction.py index d3ff2e11a6110..978d1769a1476 100644 --- a/libs/langchain/langchain/chains/openai_tools/extraction.py +++ b/libs/langchain/langchain/chains/openai_tools/extraction.py @@ -68,7 +68,10 @@ def create_extraction_chain_pydantic( if not isinstance(pydantic_schemas, list): pydantic_schemas = [pydantic_schemas] prompt = ChatPromptTemplate.from_messages( - [("system", system_message), ("user", "{input}")] + [ + ("system", system_message), + ("user", "{input}"), + ] ) functions = [convert_pydantic_to_openai_function(p) for p in pydantic_schemas] tools = [{"type": "function", "function": d} for d in functions] diff --git a/libs/langchain/langchain/chains/question_answering/refine_prompts.py b/libs/langchain/langchain/chains/question_answering/refine_prompts.py index ed4d4417fb7d3..303d94ec5603a 100644 --- a/libs/langchain/langchain/chains/question_answering/refine_prompts.py +++ b/libs/langchain/langchain/chains/question_answering/refine_prompts.py @@ -33,7 +33,11 @@ "If the context isn't useful, return the original answer." ) CHAT_REFINE_PROMPT = ChatPromptTemplate.from_messages( - [("human", "{question}"), ("ai", "{existing_answer}"), ("human", refine_template)] + [ + ("human", "{question}"), + ("ai", "{existing_answer}"), + ("human", refine_template), + ] ) REFINE_PROMPT_SELECTOR = ConditionalPromptSelector( default_prompt=DEFAULT_REFINE_PROMPT, @@ -60,7 +64,10 @@ "answer any questions" ) CHAT_QUESTION_PROMPT = ChatPromptTemplate.from_messages( - [("system", chat_qa_prompt_template), ("human", "{question}")] + [ + ("system", chat_qa_prompt_template), + ("human", "{question}"), + ] ) QUESTION_PROMPT_SELECTOR = ConditionalPromptSelector( default_prompt=DEFAULT_TEXT_QA_PROMPT, diff --git a/libs/langchain/langchain/chains/sequential.py b/libs/langchain/langchain/chains/sequential.py index b19f65e9aa2c3..55f4e802d7384 100644 --- a/libs/langchain/langchain/chains/sequential.py +++ b/libs/langchain/langchain/chains/sequential.py @@ -178,7 +178,9 @@ def _call( _input = inputs[self.input_key] color_mapping = get_color_mapping([str(i) for i in range(len(self.chains))]) for i, chain in enumerate(self.chains): - _input = chain.run(_input, callbacks=_run_manager.get_child(f"step_{i+1}")) + _input = chain.run( + _input, callbacks=_run_manager.get_child(f"step_{i + 1}") + ) if self.strip_outputs: _input = _input.strip() _run_manager.on_text( @@ -196,7 +198,7 @@ async def _acall( color_mapping = get_color_mapping([str(i) for i in range(len(self.chains))]) for i, chain in enumerate(self.chains): _input = await chain.arun( - _input, callbacks=_run_manager.get_child(f"step_{i+1}") + _input, callbacks=_run_manager.get_child(f"step_{i + 1}") ) if self.strip_outputs: _input = _input.strip() diff --git a/libs/langchain/langchain/chat_models/base.py b/libs/langchain/langchain/chat_models/base.py index c8a96fa3e5511..7b9418849b5fb 100644 --- a/libs/langchain/langchain/chat_models/base.py +++ b/libs/langchain/langchain/chat_models/base.py @@ -590,7 +590,11 @@ def with_config( queued_declarative_operations = list(self._queued_declarative_operations) if remaining_config: queued_declarative_operations.append( - ("with_config", (), {"config": remaining_config}) + ( + "with_config", + (), + {"config": remaining_config}, + ) ) return _ConfigurableModel( default_config={**self._default_config, **model_params}, diff --git a/libs/langchain/langchain/embeddings/base.py b/libs/langchain/langchain/embeddings/base.py index a8c8a97939676..2f1f832f3bc3a 100644 --- a/libs/langchain/langchain/embeddings/base.py +++ b/libs/langchain/langchain/embeddings/base.py @@ -174,8 +174,7 @@ def init_embeddings( if not model: providers = _SUPPORTED_PROVIDERS.keys() raise ValueError( - "Must specify model name. " - f"Supported providers are: {', '.join(providers)}" + f"Must specify model name. Supported providers are: {', '.join(providers)}" ) provider, model_name = _infer_model_and_provider(model, provider=provider) diff --git a/libs/langchain/langchain/evaluation/embedding_distance/base.py b/libs/langchain/langchain/evaluation/embedding_distance/base.py index 569838841cd04..3afd3030bfe80 100644 --- a/libs/langchain/langchain/evaluation/embedding_distance/base.py +++ b/libs/langchain/langchain/evaluation/embedding_distance/base.py @@ -310,7 +310,10 @@ async def _acall( Dict[str, Any]: The computed score. """ embedded = await self.embeddings.aembed_documents( - [inputs["prediction"], inputs["reference"]] + [ + inputs["prediction"], + inputs["reference"], + ] ) vectors = np.array(embedded) score = self._compute_score(vectors) @@ -427,7 +430,10 @@ def _call( """ vectors = np.array( self.embeddings.embed_documents( - [inputs["prediction"], inputs["prediction_b"]] + [ + inputs["prediction"], + inputs["prediction_b"], + ] ) ) score = self._compute_score(vectors) @@ -449,7 +455,10 @@ async def _acall( Dict[str, Any]: The computed score. """ embedded = await self.embeddings.aembed_documents( - [inputs["prediction"], inputs["prediction_b"]] + [ + inputs["prediction"], + inputs["prediction_b"], + ] ) vectors = np.array(embedded) score = self._compute_score(vectors) diff --git a/libs/langchain/langchain/memory/chat_memory.py b/libs/langchain/langchain/memory/chat_memory.py index 1447fc484aa4e..645cfbc7cde8b 100644 --- a/libs/langchain/langchain/memory/chat_memory.py +++ b/libs/langchain/langchain/memory/chat_memory.py @@ -71,7 +71,10 @@ def save_context(self, inputs: Dict[str, Any], outputs: Dict[str, str]) -> None: """Save context from this conversation to buffer.""" input_str, output_str = self._get_input_output(inputs, outputs) self.chat_memory.add_messages( - [HumanMessage(content=input_str), AIMessage(content=output_str)] + [ + HumanMessage(content=input_str), + AIMessage(content=output_str), + ] ) async def asave_context( @@ -80,7 +83,10 @@ async def asave_context( """Save context from this conversation to buffer.""" input_str, output_str = self._get_input_output(inputs, outputs) await self.chat_memory.aadd_messages( - [HumanMessage(content=input_str), AIMessage(content=output_str)] + [ + HumanMessage(content=input_str), + AIMessage(content=output_str), + ] ) def clear(self) -> None: diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 2030807ce310c..cce5a3d40a2d7 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -92,7 +92,10 @@ def rerank( result_dicts = [] for res in results: result_dicts.append( - {"index": res.index, "relevance_score": res.relevance_score} + { + "index": res.index, + "relevance_score": res.relevance_score, + } ) return result_dicts diff --git a/libs/langchain/langchain/retrievers/ensemble.py b/libs/langchain/langchain/retrievers/ensemble.py index f07fe756ed62d..c99878d808042 100644 --- a/libs/langchain/langchain/retrievers/ensemble.py +++ b/libs/langchain/langchain/retrievers/ensemble.py @@ -223,7 +223,7 @@ def rank_fusion( retriever.invoke( query, patch_config( - config, callbacks=run_manager.get_child(tag=f"retriever_{i+1}") + config, callbacks=run_manager.get_child(tag=f"retriever_{i + 1}") ), ) for i, retriever in enumerate(self.retrievers) @@ -265,7 +265,8 @@ async def arank_fusion( retriever.ainvoke( query, patch_config( - config, callbacks=run_manager.get_child(tag=f"retriever_{i+1}") + config, + callbacks=run_manager.get_child(tag=f"retriever_{i + 1}"), ), ) for i, retriever in enumerate(self.retrievers) diff --git a/libs/langchain/langchain/smith/evaluation/runner_utils.py b/libs/langchain/langchain/smith/evaluation/runner_utils.py index 9cd018d9b97bc..344e9638f36de 100644 --- a/libs/langchain/langchain/smith/evaluation/runner_utils.py +++ b/libs/langchain/langchain/smith/evaluation/runner_utils.py @@ -247,8 +247,7 @@ def _get_prompt(inputs: Dict[str, Any]) -> str: if "prompt" in inputs: if not isinstance(inputs["prompt"], str): raise InputFormatError( - "Expected string for 'prompt', got" - f" {type(inputs['prompt']).__name__}" + f"Expected string for 'prompt', got {type(inputs['prompt']).__name__}" ) prompts = [inputs["prompt"]] elif "prompts" in inputs: diff --git a/libs/langchain/poetry.lock b/libs/langchain/poetry.lock index 154ae27fa58cc..e2ca5ac036fa2 100644 --- a/libs/langchain/poetry.lock +++ b/libs/langchain/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" @@ -2015,7 +2015,7 @@ url = "../core" [[package]] name = "langchain-openai" -version = "0.2.14" +version = "0.3.0" description = "An integration package connecting OpenAI and LangChain" optional = true python-versions = ">=3.9,<4.0" @@ -2023,7 +2023,7 @@ files = [] develop = true [package.dependencies] -langchain-core = "^0.3.27" +langchain-core = "^0.3.29" openai = "^1.58.1" tiktoken = ">=0.7,<1" @@ -2033,7 +2033,7 @@ url = "../partners/openai" [[package]] name = "langchain-tests" -version = "0.3.7" +version = "0.3.8" description = "Standard tests for LangChain implementations" optional = false python-versions = ">=3.9,<4.0" @@ -2058,7 +2058,7 @@ url = "../standard-tests" [[package]] name = "langchain-text-splitters" -version = "0.3.4" +version = "0.3.5" description = "LangChain text splitting utilities" optional = false python-versions = ">=3.9,<4.0" @@ -2066,7 +2066,7 @@ files = [] develop = true [package.dependencies] -langchain-core = "^0.3.26" +langchain-core = "^0.3.29" [package.source] type = "directory" @@ -2790,30 +2790,41 @@ files = [ {file = "pandas-2.2.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:381175499d3802cde0eabbaf6324cce0c4f5d52ca6f8c377c29ad442f50f6348"}, {file = "pandas-2.2.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:d9c45366def9a3dd85a6454c0e7908f2b3b8e9c138f5dc38fed7ce720d8453ed"}, {file = "pandas-2.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:86976a1c5b25ae3f8ccae3a5306e443569ee3c3faf444dfd0f41cda24667ad57"}, + {file = "pandas-2.2.3-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:b8661b0238a69d7aafe156b7fa86c44b881387509653fdf857bebc5e4008ad42"}, {file = "pandas-2.2.3-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:37e0aced3e8f539eccf2e099f65cdb9c8aa85109b0be6e93e2baff94264bdc6f"}, {file = "pandas-2.2.3-cp310-cp310-win_amd64.whl", hash = "sha256:56534ce0746a58afaf7942ba4863e0ef81c9c50d3f0ae93e9497d6a41a057645"}, {file = "pandas-2.2.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:66108071e1b935240e74525006034333f98bcdb87ea116de573a6a0dccb6c039"}, {file = "pandas-2.2.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7c2875855b0ff77b2a64a0365e24455d9990730d6431b9e0ee18ad8acee13dbd"}, + {file = "pandas-2.2.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:cd8d0c3be0515c12fed0bdbae072551c8b54b7192c7b1fda0ba56059a0179698"}, {file = "pandas-2.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c124333816c3a9b03fbeef3a9f230ba9a737e9e5bb4060aa2107a86cc0a497fc"}, + {file = "pandas-2.2.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:63cc132e40a2e084cf01adf0775b15ac515ba905d7dcca47e9a251819c575ef3"}, {file = "pandas-2.2.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:29401dbfa9ad77319367d36940cd8a0b3a11aba16063e39632d98b0e931ddf32"}, {file = "pandas-2.2.3-cp311-cp311-win_amd64.whl", hash = "sha256:3fc6873a41186404dad67245896a6e440baacc92f5b716ccd1bc9ed2995ab2c5"}, {file = "pandas-2.2.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:b1d432e8d08679a40e2a6d8b2f9770a5c21793a6f9f47fdd52c5ce1948a5a8a9"}, {file = "pandas-2.2.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a5a1595fe639f5988ba6a8e5bc9649af3baf26df3998a0abe56c02609392e0a4"}, + {file = "pandas-2.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:5de54125a92bb4d1c051c0659e6fcb75256bf799a732a87184e5ea503965bce3"}, {file = "pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fffb8ae78d8af97f849404f21411c95062db1496aeb3e56f146f0355c9989319"}, + {file = "pandas-2.2.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6dfcb5ee8d4d50c06a51c2fffa6cff6272098ad6540aed1a76d15fb9318194d8"}, {file = "pandas-2.2.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:062309c1b9ea12a50e8ce661145c6aab431b1e99530d3cd60640e255778bd43a"}, {file = "pandas-2.2.3-cp312-cp312-win_amd64.whl", hash = "sha256:59ef3764d0fe818125a5097d2ae867ca3fa64df032331b7e0917cf5d7bf66b13"}, {file = "pandas-2.2.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:f00d1345d84d8c86a63e476bb4955e46458b304b9575dcf71102b5c705320015"}, {file = "pandas-2.2.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3508d914817e153ad359d7e069d752cdd736a247c322d932eb89e6bc84217f28"}, + {file = "pandas-2.2.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:22a9d949bfc9a502d320aa04e5d02feab689d61da4e7764b62c30b991c42c5f0"}, {file = "pandas-2.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f3a255b2c19987fbbe62a9dfd6cff7ff2aa9ccab3fc75218fd4b7530f01efa24"}, + {file = "pandas-2.2.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:800250ecdadb6d9c78eae4990da62743b857b470883fa27f652db8bdde7f6659"}, {file = "pandas-2.2.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6374c452ff3ec675a8f46fd9ab25c4ad0ba590b71cf0656f8b6daa5202bca3fb"}, {file = "pandas-2.2.3-cp313-cp313-win_amd64.whl", hash = "sha256:61c5ad4043f791b61dd4752191d9f07f0ae412515d59ba8f005832a532f8736d"}, {file = "pandas-2.2.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:3b71f27954685ee685317063bf13c7709a7ba74fc996b84fc6821c59b0f06468"}, {file = "pandas-2.2.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:38cf8125c40dae9d5acc10fa66af8ea6fdf760b2714ee482ca691fc66e6fcb18"}, + {file = "pandas-2.2.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ba96630bc17c875161df3818780af30e43be9b166ce51c9a18c1feae342906c2"}, {file = "pandas-2.2.3-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1db71525a1538b30142094edb9adc10be3f3e176748cd7acc2240c2f2e5aa3a4"}, + {file = "pandas-2.2.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:15c0e1e02e93116177d29ff83e8b1619c93ddc9c49083f237d4312337a61165d"}, {file = "pandas-2.2.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:ad5b65698ab28ed8d7f18790a0dc58005c7629f227be9ecc1072aa74c0c1d43a"}, {file = "pandas-2.2.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:bc6b93f9b966093cb0fd62ff1a7e4c09e6d546ad7c1de191767baffc57628f39"}, {file = "pandas-2.2.3-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5dbca4c1acd72e8eeef4753eeca07de9b1db4f398669d5994086f788a5d7cc30"}, + {file = "pandas-2.2.3-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:8cd6d7cc958a3910f934ea8dbdf17b2364827bb4dafc38ce6eef6bb3d65ff09c"}, {file = "pandas-2.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99df71520d25fade9db7c1076ac94eb994f4d2673ef2aa2e86ee039b6746d20c"}, + {file = "pandas-2.2.3-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:31d0ced62d4ea3e231a9f228366919a5ea0b07440d9d4dac345376fd8e1477ea"}, {file = "pandas-2.2.3-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:7eee9e7cea6adf3e3d24e304ac6b8300646e2a5d1cd3a3c2abed9101b0846761"}, {file = "pandas-2.2.3-cp39-cp39-win_amd64.whl", hash = "sha256:4850ba03528b6dd51d6c5d273c46f183f39a9baf3f0143e566b89450965b105e"}, {file = "pandas-2.2.3.tar.gz", hash = "sha256:4f18ba62b61d7e192368b84517265a99b4d7ee8912f8708660fb4a366cc82667"}, @@ -4076,29 +4087,29 @@ files = [ [[package]] name = "ruff" -version = "0.5.7" +version = "0.9.1" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.5.7-py3-none-linux_armv6l.whl", hash = "sha256:548992d342fc404ee2e15a242cdbea4f8e39a52f2e7752d0e4cbe88d2d2f416a"}, - {file = "ruff-0.5.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:00cc8872331055ee017c4f1071a8a31ca0809ccc0657da1d154a1d2abac5c0be"}, - {file = "ruff-0.5.7-py3-none-macosx_11_0_arm64.whl", hash = "sha256:eaf3d86a1fdac1aec8a3417a63587d93f906c678bb9ed0b796da7b59c1114a1e"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a01c34400097b06cf8a6e61b35d6d456d5bd1ae6961542de18ec81eaf33b4cb8"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:fcc8054f1a717e2213500edaddcf1dbb0abad40d98e1bd9d0ad364f75c763eea"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7f70284e73f36558ef51602254451e50dd6cc479f8b6f8413a95fcb5db4a55fc"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:a78ad870ae3c460394fc95437d43deb5c04b5c29297815a2a1de028903f19692"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9ccd078c66a8e419475174bfe60a69adb36ce04f8d4e91b006f1329d5cd44bcf"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7e31c9bad4ebf8fdb77b59cae75814440731060a09a0e0077d559a556453acbb"}, - {file = "ruff-0.5.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8d796327eed8e168164346b769dd9a27a70e0298d667b4ecee6877ce8095ec8e"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:4a09ea2c3f7778cc635e7f6edf57d566a8ee8f485f3c4454db7771efb692c499"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a36d8dcf55b3a3bc353270d544fb170d75d2dff41eba5df57b4e0b67a95bb64e"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:9369c218f789eefbd1b8d82a8cf25017b523ac47d96b2f531eba73770971c9e5"}, - {file = "ruff-0.5.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:b88ca3db7eb377eb24fb7c82840546fb7acef75af4a74bd36e9ceb37a890257e"}, - {file = "ruff-0.5.7-py3-none-win32.whl", hash = "sha256:33d61fc0e902198a3e55719f4be6b375b28f860b09c281e4bdbf783c0566576a"}, - {file = "ruff-0.5.7-py3-none-win_amd64.whl", hash = "sha256:083bbcbe6fadb93cd86709037acc510f86eed5a314203079df174c40bbbca6b3"}, - {file = "ruff-0.5.7-py3-none-win_arm64.whl", hash = "sha256:2dca26154ff9571995107221d0aeaad0e75a77b5a682d6236cf89a58c70b76f4"}, - {file = "ruff-0.5.7.tar.gz", hash = "sha256:8dfc0a458797f5d9fb622dd0efc52d796f23f0a1493a9527f4e49a550ae9a7e5"}, + {file = "ruff-0.9.1-py3-none-linux_armv6l.whl", hash = "sha256:84330dda7abcc270e6055551aca93fdde1b0685fc4fd358f26410f9349cf1743"}, + {file = "ruff-0.9.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3cae39ba5d137054b0e5b472aee3b78a7c884e61591b100aeb544bcd1fc38d4f"}, + {file = "ruff-0.9.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:50c647ff96f4ba288db0ad87048257753733763b409b2faf2ea78b45c8bb7fcb"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f0c8b149e9c7353cace7d698e1656ffcf1e36e50f8ea3b5d5f7f87ff9986a7ca"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:beb3298604540c884d8b282fe7625651378e1986c25df51dec5b2f60cafc31ce"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:39d0174ccc45c439093971cc06ed3ac4dc545f5e8bdacf9f067adf879544d969"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:69572926c0f0c9912288915214ca9b2809525ea263603370b9e00bed2ba56dbd"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:937267afce0c9170d6d29f01fcd1f4378172dec6760a9f4dface48cdabf9610a"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:186c2313de946f2c22bdf5954b8dd083e124bcfb685732cfb0beae0c47233d9b"}, + {file = "ruff-0.9.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f94942a3bb767675d9a051867c036655fe9f6c8a491539156a6f7e6b5f31831"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:728d791b769cc28c05f12c280f99e8896932e9833fef1dd8756a6af2261fd1ab"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:2f312c86fb40c5c02b44a29a750ee3b21002bd813b5233facdaf63a51d9a85e1"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:ae017c3a29bee341ba584f3823f805abbe5fe9cd97f87ed07ecbf533c4c88366"}, + {file = "ruff-0.9.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5dc40a378a0e21b4cfe2b8a0f1812a6572fc7b230ef12cd9fac9161aa91d807f"}, + {file = "ruff-0.9.1-py3-none-win32.whl", hash = "sha256:46ebf5cc106cf7e7378ca3c28ce4293b61b449cd121b98699be727d40b79ba72"}, + {file = "ruff-0.9.1-py3-none-win_amd64.whl", hash = "sha256:342a824b46ddbcdddd3abfbb332fa7fcaac5488bf18073e841236aadf4ad5c19"}, + {file = "ruff-0.9.1-py3-none-win_arm64.whl", hash = "sha256:1cd76c7f9c679e6e8f2af8f778367dca82b95009bc7b1a85a47f1521ae524fa7"}, + {file = "ruff-0.9.1.tar.gz", hash = "sha256:fd2b25ecaf907d6458fa842675382c8597b3c746a2dde6717fe3415425df0c17"}, ] [[package]] @@ -5022,4 +5033,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0" -content-hash = "8263b9b9697f3251c51de95c653f97704713cef0c14dbc4f537dbdc8a901fd12" +content-hash = "f2531a41cd4adae4a6e74e75e662d4d079f656b4f821c11357e0001d0dc945c5" diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.toml index e0e2d5326ce97..2a20c8403b9bd 100644 --- a/libs/langchain/pyproject.toml +++ b/libs/langchain/pyproject.toml @@ -12,6 +12,7 @@ readme = "README.md" repository = "https://github.com/langchain-ai/langchain" [tool.ruff] +target-version = "py39" exclude = [ "tests/integration_tests/examples/non-utf8-encoding.py",] [tool.mypy] @@ -119,7 +120,7 @@ cassio = "^0.1.0" langchainhub = "^0.1.16" [tool.poetry.group.lint.dependencies] -ruff = "^0.5" +ruff = "~0.9.1" [[tool.poetry.group.lint.dependencies.cffi]] version = "<1.17.1" python = "<3.10" diff --git a/libs/langchain/tests/unit_tests/agents/test_agent.py b/libs/langchain/tests/unit_tests/agents/test_agent.py index c343d33d4e1b5..a8ebcc658f692 100644 --- a/libs/langchain/tests/unit_tests/agents/test_agent.py +++ b/libs/langchain/tests/unit_tests/agents/test_agent.py @@ -451,7 +451,10 @@ async def test_runnable_agent() -> None: model = GenericFakeChatModel(messages=infinite_cycle) template = ChatPromptTemplate.from_messages( - [("system", "You are Cat Agent 007"), ("human", "{question}")] + [ + ("system", "You are Cat Agent 007"), + ("human", "{question}"), + ] ) def fake_parse(inputs: dict) -> Union[AgentFinish, AgentAction]: @@ -539,12 +542,18 @@ async def test_runnable_agent_with_function_calls() -> None: """Test agent with intermediate agent actions.""" # Will alternate between responding with hello and goodbye infinite_cycle = cycle( - [AIMessage(content="looking for pet..."), AIMessage(content="Found Pet")] + [ + AIMessage(content="looking for pet..."), + AIMessage(content="Found Pet"), + ] ) model = GenericFakeChatModel(messages=infinite_cycle) template = ChatPromptTemplate.from_messages( - [("system", "You are Cat Agent 007"), ("human", "{question}")] + [ + ("system", "You are Cat Agent 007"), + ("human", "{question}"), + ] ) parser_responses = cycle( @@ -635,12 +644,18 @@ async def test_runnable_with_multi_action_per_step() -> None: """Test an agent that can make multiple function calls at once.""" # Will alternate between responding with hello and goodbye infinite_cycle = cycle( - [AIMessage(content="looking for pet..."), AIMessage(content="Found Pet")] + [ + AIMessage(content="looking for pet..."), + AIMessage(content="Found Pet"), + ] ) model = GenericFakeChatModel(messages=infinite_cycle) template = ChatPromptTemplate.from_messages( - [("system", "You are Cat Agent 007"), ("human", "{question}")] + [ + ("system", "You are Cat Agent 007"), + ("human", "{question}"), + ] ) parser_responses = cycle( @@ -861,7 +876,7 @@ def find_pet(pet: str) -> str: { "additional_kwargs": { "function_call": { - "arguments": '{"pet": ' '"cat"}', + "arguments": '{"pet": "cat"}', "name": "find_pet", } }, @@ -880,7 +895,7 @@ def find_pet(pet: str) -> str: { "additional_kwargs": { "function_call": { - "arguments": '{"pet": ' '"cat"}', + "arguments": '{"pet": "cat"}', "name": "find_pet", } }, @@ -909,10 +924,7 @@ def find_pet(pet: str) -> str: "steps": [ { "action": { - "log": "\n" - "Invoking: `find_pet` with `{'pet': 'cat'}`\n" - "\n" - "\n", + "log": "\nInvoking: `find_pet` with `{'pet': 'cat'}`\n\n\n", "tool": "find_pet", "tool_input": {"pet": "cat"}, "type": "AgentActionMessageLog", @@ -1062,15 +1074,131 @@ def check_time() -> str: # astream chunks = [chunk async for chunk in executor.astream({"question": "hello"})] - assert ( - chunks - == [ - { - "actions": [ - OpenAIToolAgentAction( + assert chunks == [ + { + "actions": [ + OpenAIToolAgentAction( + tool="find_pet", + tool_input={"pet": "cat"}, + log="\nInvoking: `find_pet` with `{'pet': 'cat'}`\n\n\n", + message_log=[ + _AnyIdAIMessageChunk( + content="", + additional_kwargs={ + "tool_calls": [ + { + "function": { + "name": "find_pet", + "arguments": '{"pet": "cat"}', + }, + "id": "0", + }, + { + "function": { + "name": "check_time", + "arguments": "{}", + }, + "id": "1", + }, + ] + }, + ) + ], + tool_call_id="0", + ) + ], + "messages": [ + _AnyIdAIMessageChunk( + content="", + additional_kwargs={ + "tool_calls": [ + { + "function": { + "name": "find_pet", + "arguments": '{"pet": "cat"}', + }, + "id": "0", + }, + { + "function": { + "name": "check_time", + "arguments": "{}", + }, + "id": "1", + }, + ] + }, + ) + ], + }, + { + "actions": [ + OpenAIToolAgentAction( + tool="check_time", + tool_input={}, + log="\nInvoking: `check_time` with `{}`\n\n\n", + message_log=[ + _AnyIdAIMessageChunk( + content="", + additional_kwargs={ + "tool_calls": [ + { + "function": { + "name": "find_pet", + "arguments": '{"pet": "cat"}', + }, + "id": "0", + }, + { + "function": { + "name": "check_time", + "arguments": "{}", + }, + "id": "1", + }, + ] + }, + ) + ], + tool_call_id="1", + ) + ], + "messages": [ + _AnyIdAIMessageChunk( + content="", + additional_kwargs={ + "tool_calls": [ + { + "function": { + "name": "find_pet", + "arguments": '{"pet": "cat"}', + }, + "id": "0", + }, + { + "function": { + "name": "check_time", + "arguments": "{}", + }, + "id": "1", + }, + ] + }, + ) + ], + }, + { + "messages": [ + FunctionMessage( + content="Spying from under the bed.", name="find_pet" + ) + ], + "steps": [ + AgentStep( + action=OpenAIToolAgentAction( tool="find_pet", tool_input={"pet": "cat"}, - log="\nInvoking: `find_pet` with `{'pet': 'cat'}`\n\n\n", + log="\nInvoking: `find_pet` with `{'pet': 'cat'}`\n\n\n", # noqa: E501 message_log=[ _AnyIdAIMessageChunk( content="", @@ -1095,35 +1223,21 @@ def check_time() -> str: ) ], tool_call_id="0", - ) - ], - "messages": [ - _AnyIdAIMessageChunk( - content="", - additional_kwargs={ - "tool_calls": [ - { - "function": { - "name": "find_pet", - "arguments": '{"pet": "cat"}', - }, - "id": "0", - }, - { - "function": { - "name": "check_time", - "arguments": "{}", - }, - "id": "1", - }, - ] - }, - ) - ], - }, - { - "actions": [ - OpenAIToolAgentAction( + ), + observation="Spying from under the bed.", + ) + ], + }, + { + "messages": [ + FunctionMessage( + content="check_time is not a valid tool, try one of [find_pet].", # noqa: E501 + name="check_time", + ) + ], + "steps": [ + AgentStep( + action=OpenAIToolAgentAction( tool="check_time", tool_input={}, log="\nInvoking: `check_time` with `{}`\n\n\n", @@ -1151,124 +1265,19 @@ def check_time() -> str: ) ], tool_call_id="1", - ) - ], - "messages": [ - _AnyIdAIMessageChunk( - content="", - additional_kwargs={ - "tool_calls": [ - { - "function": { - "name": "find_pet", - "arguments": '{"pet": "cat"}', - }, - "id": "0", - }, - { - "function": { - "name": "check_time", - "arguments": "{}", - }, - "id": "1", - }, - ] - }, - ) - ], - }, - { - "messages": [ - FunctionMessage( - content="Spying from under the bed.", name="find_pet" - ) - ], - "steps": [ - AgentStep( - action=OpenAIToolAgentAction( - tool="find_pet", - tool_input={"pet": "cat"}, - log="\nInvoking: `find_pet` with `{'pet': 'cat'}`\n\n\n", # noqa: E501 - message_log=[ - _AnyIdAIMessageChunk( - content="", - additional_kwargs={ - "tool_calls": [ - { - "function": { - "name": "find_pet", - "arguments": '{"pet": "cat"}', - }, - "id": "0", - }, - { - "function": { - "name": "check_time", - "arguments": "{}", - }, - "id": "1", - }, - ] - }, - ) - ], - tool_call_id="0", - ), - observation="Spying from under the bed.", - ) - ], - }, - { - "messages": [ - FunctionMessage( - content="check_time is not a valid tool, try one of [find_pet].", # noqa: E501 - name="check_time", - ) - ], - "steps": [ - AgentStep( - action=OpenAIToolAgentAction( - tool="check_time", - tool_input={}, - log="\nInvoking: `check_time` with `{}`\n\n\n", - message_log=[ - _AnyIdAIMessageChunk( - content="", - additional_kwargs={ - "tool_calls": [ - { - "function": { - "name": "find_pet", - "arguments": '{"pet": "cat"}', - }, - "id": "0", - }, - { - "function": { - "name": "check_time", - "arguments": "{}", - }, - "id": "1", - }, - ] - }, - ) - ], - tool_call_id="1", - ), - observation="check_time is not a valid tool, " - "try one of [find_pet].", - ) - ], - }, - { - "messages": [ - AIMessage(content="The cat is spying from under the bed.") - ], - "output": "The cat is spying from under the bed.", - }, - ] - ) + ), + observation="check_time is not a valid tool, " + "try one of [find_pet].", + ) + ], + }, + { + "messages": [ + AIMessage(content="The cat is spying from under the bed.") + ], + "output": "The cat is spying from under the bed.", + }, + ] # astream_log log_patches = [ diff --git a/libs/langchain/tests/unit_tests/agents/test_mrkl.py b/libs/langchain/tests/unit_tests/agents/test_mrkl.py index c05dbcc80d1c1..6b4deb5597392 100644 --- a/libs/langchain/tests/unit_tests/agents/test_mrkl.py +++ b/libs/langchain/tests/unit_tests/agents/test_mrkl.py @@ -24,9 +24,7 @@ def get_action_and_input(text: str) -> Tuple[str, str]: def test_get_action_and_input() -> None: """Test getting an action from text.""" - llm_output = ( - "Thought: I need to search for NBA\n" "Action: Search\n" "Action Input: NBA" - ) + llm_output = "Thought: I need to search for NBA\nAction: Search\nAction Input: NBA" action, action_input = get_action_and_input(llm_output) assert action == "Search" assert action_input == "NBA" @@ -91,7 +89,7 @@ def test_get_action_and_input_sql_query() -> None: def test_get_final_answer() -> None: """Test getting final answer.""" - llm_output = "Thought: I can now answer the question\n" "Final Answer: 1994" + llm_output = "Thought: I can now answer the question\nFinal Answer: 1994" action, action_input = get_action_and_input(llm_output) assert action == "Final Answer" assert action_input == "1994" @@ -99,7 +97,7 @@ def test_get_final_answer() -> None: def test_get_final_answer_new_line() -> None: """Test getting final answer.""" - llm_output = "Thought: I can now answer the question\n" "Final Answer:\n1994" + llm_output = "Thought: I can now answer the question\nFinal Answer:\n1994" action, action_input = get_action_and_input(llm_output) assert action == "Final Answer" assert action_input == "1994" @@ -107,7 +105,7 @@ def test_get_final_answer_new_line() -> None: def test_get_final_answer_multiline() -> None: """Test getting final answer that is multiline.""" - llm_output = "Thought: I can now answer the question\n" "Final Answer: 1994\n1993" + llm_output = "Thought: I can now answer the question\nFinal Answer: 1994\n1993" action, action_input = get_action_and_input(llm_output) assert action == "Final Answer" assert action_input == "1994\n1993" @@ -115,7 +113,7 @@ def test_get_final_answer_multiline() -> None: def test_bad_action_input_line() -> None: """Test handling when no action input found.""" - llm_output = "Thought: I need to search for NBA\n" "Action: Search\n" "Thought: NBA" + llm_output = "Thought: I need to search for NBA\nAction: Search\nThought: NBA" with pytest.raises(OutputParserException) as e_info: get_action_and_input(llm_output) assert e_info.value.observation is not None @@ -123,9 +121,7 @@ def test_bad_action_input_line() -> None: def test_bad_action_line() -> None: """Test handling when no action found.""" - llm_output = ( - "Thought: I need to search for NBA\n" "Thought: Search\n" "Action Input: NBA" - ) + llm_output = "Thought: I need to search for NBA\nThought: Search\nAction Input: NBA" with pytest.raises(OutputParserException) as e_info: get_action_and_input(llm_output) assert e_info.value.observation is not None diff --git a/libs/langchain/tests/unit_tests/chains/test_constitutional_ai.py b/libs/langchain/tests/unit_tests/chains/test_constitutional_ai.py index fb6f53410bea8..0ebdea1917a2c 100644 --- a/libs/langchain/tests/unit_tests/chains/test_constitutional_ai.py +++ b/libs/langchain/tests/unit_tests/chains/test_constitutional_ai.py @@ -22,6 +22,6 @@ def test_critique_parsing() -> None: for text in [TEXT_ONE, TEXT_TWO, TEXT_THREE]: critique = ConstitutionalChain._parse_critique(text) - assert ( - critique.strip() == "This text is bad." - ), f"Failed on {text} with {critique}" + assert critique.strip() == "This text is bad.", ( + f"Failed on {text} with {critique}" + ) diff --git a/libs/langchain/tests/unit_tests/chains/test_history_aware_retriever.py b/libs/langchain/tests/unit_tests/chains/test_history_aware_retriever.py index 8786e8108bd77..78d8ab326c2e7 100644 --- a/libs/langchain/tests/unit_tests/chains/test_history_aware_retriever.py +++ b/libs/langchain/tests/unit_tests/chains/test_history_aware_retriever.py @@ -21,6 +21,9 @@ def test_create() -> None: expected_output = [Document(page_content="I know the answer!")] output = chain.invoke( - {"input": "What is the answer?", "chat_history": ["hi", "hi"]} + { + "input": "What is the answer?", + "chat_history": ["hi", "hi"], + } ) assert output == expected_output diff --git a/libs/langchain/tests/unit_tests/chains/test_llm_math.py b/libs/langchain/tests/unit_tests/chains/test_llm_math.py index decc988cf23b4..26955939aea14 100644 --- a/libs/langchain/tests/unit_tests/chains/test_llm_math.py +++ b/libs/langchain/tests/unit_tests/chains/test_llm_math.py @@ -33,7 +33,7 @@ def test_complex_question(fake_llm_math_chain: LLMMathChain) -> None: """Test complex question that should need python.""" question = "What is the square root of 2?" output = fake_llm_math_chain.run(question) - assert output == f"Answer: {2**.5}" + assert output == f"Answer: {2**0.5}" @pytest.mark.requires("numexpr") diff --git a/libs/langchain/tests/unit_tests/evaluation/parsing/test_base.py b/libs/langchain/tests/unit_tests/evaluation/parsing/test_base.py index a4d4230788e96..82fe26e30ff2a 100644 --- a/libs/langchain/tests/unit_tests/evaluation/parsing/test_base.py +++ b/libs/langchain/tests/unit_tests/evaluation/parsing/test_base.py @@ -151,21 +151,21 @@ def test_json_equality_evaluator_evaluate_lists_permutation_invariant() -> None: # Limit tests prediction = ( - "[" + ",".join([f'{{"a": {i}, "b": {i+1}}}' for i in range(1000)]) + "]" + "[" + ",".join([f'{{"a": {i}, "b": {i + 1}}}' for i in range(1000)]) + "]" ) - rlist = [f'{{"a": {i}, "b": {i+1}}}' for i in range(1000)] + rlist = [f'{{"a": {i}, "b": {i + 1}}}' for i in range(1000)] random.shuffle(rlist) reference = "[" + ",".join(rlist) + "]" result = evaluator.evaluate_strings(prediction=prediction, reference=reference) assert result == {"score": True} prediction = ( - "[" + ",".join([f'{{"b": {i+1}, "a": {i}}}' for i in range(1000)]) + "]" + "[" + ",".join([f'{{"b": {i + 1}, "a": {i}}}' for i in range(1000)]) + "]" ) reference = ( "[" + ",".join( - [f'{{"a": {i+1}, "b": {i+2}}}' for i in range(999)] + [f'{{"a": {i + 1}, "b": {i + 2}}}' for i in range(999)] + ['{"a": 1000, "b": 1001}'] ) + "]" diff --git a/libs/langchain/tests/unit_tests/output_parsers/test_pandas_dataframe_parser.py b/libs/langchain/tests/unit_tests/output_parsers/test_pandas_dataframe_parser.py index 7ffb4c09e4429..47fc099c4e3b0 100644 --- a/libs/langchain/tests/unit_tests/output_parsers/test_pandas_dataframe_parser.py +++ b/libs/langchain/tests/unit_tests/output_parsers/test_pandas_dataframe_parser.py @@ -8,7 +8,11 @@ from langchain.output_parsers.pandas_dataframe import PandasDataFrameOutputParser df = pd.DataFrame( - {"chicken": [1, 2, 3, 4], "veggies": [5, 4, 3, 2], "steak": [9, 8, 7, 6]} + { + "chicken": [1, 2, 3, 4], + "veggies": [5, 4, 3, 2], + "steak": [9, 8, 7, 6], + } ) parser = PandasDataFrameOutputParser(dataframe=df) diff --git a/libs/langchain/tests/unit_tests/runnables/test_hub.py b/libs/langchain/tests/unit_tests/runnables/test_hub.py index f17700ef2c659..58f5d83959d56 100644 --- a/libs/langchain/tests/unit_tests/runnables/test_hub.py +++ b/libs/langchain/tests/unit_tests/runnables/test_hub.py @@ -10,7 +10,10 @@ @patch("langchain.hub.pull") def test_hub_runnable(mock_pull: Mock) -> None: mock_pull.return_value = ChatPromptTemplate.from_messages( - [("system", "a"), ("user", "b")] + [ + ("system", "a"), + ("user", "b"), + ] ) basic: HubRunnable = HubRunnable("efriis/my-prompt") @@ -21,10 +24,16 @@ def test_hub_runnable(mock_pull: Mock) -> None: repo_dict = { "efriis/my-prompt-1": ChatPromptTemplate.from_messages( - [("system", "a"), ("user", "1")] + [ + ("system", "a"), + ("user", "1"), + ] ), "efriis/my-prompt-2": ChatPromptTemplate.from_messages( - [("system", "a"), ("user", "2")] + [ + ("system", "a"), + ("user", "2"), + ] ), } diff --git a/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py b/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py index ba7195c4ee497..c9838ff660b26 100644 --- a/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py +++ b/libs/langchain/tests/unit_tests/runnables/test_openai_functions.py @@ -43,9 +43,9 @@ def test_openai_functions_router( snapshot: SnapshotAssertion, mocker: MockerFixture ) -> None: revise = mocker.Mock( - side_effect=lambda kw: f'Revised draft: no more {kw["notes"]}!' + side_effect=lambda kw: f"Revised draft: no more {kw['notes']}!" ) - accept = mocker.Mock(side_effect=lambda kw: f'Accepted draft: {kw["draft"]}!') + accept = mocker.Mock(side_effect=lambda kw: f"Accepted draft: {kw['draft']}!") router = OpenAIFunctionsRouter( { diff --git a/libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py b/libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py index d3a6442ec21ea..3df1fcb9ad08a 100644 --- a/libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py +++ b/libs/langchain/tests/unit_tests/smith/evaluation/test_runner_utils.py @@ -316,12 +316,15 @@ def mock_create_project(*args: Any, **kwargs: Any) -> Any: proj.id = "123" return proj - with mock.patch.object( - Client, "read_dataset", new=mock_read_dataset - ), mock.patch.object(Client, "list_examples", new=mock_list_examples), mock.patch( - "langchain.smith.evaluation.runner_utils._arun_llm_or_chain", - new=mock_arun_chain, - ), mock.patch.object(Client, "create_project", new=mock_create_project): + with ( + mock.patch.object(Client, "read_dataset", new=mock_read_dataset), + mock.patch.object(Client, "list_examples", new=mock_list_examples), + mock.patch( + "langchain.smith.evaluation.runner_utils._arun_llm_or_chain", + new=mock_arun_chain, + ), + mock.patch.object(Client, "create_project", new=mock_create_project), + ): client = Client(api_url="http://localhost:1984", api_key="123") chain = mock.MagicMock() chain.input_keys = ["foothing"]