From ed97af423c060bcf2fb11ae1b09985b5e192c8a7 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:46:36 -0700 Subject: [PATCH] Accept LLM via constructor (#7794) --- langchain/smith/evaluation/runner_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/langchain/smith/evaluation/runner_utils.py b/langchain/smith/evaluation/runner_utils.py index 060af4a8088..4c7645ead6b 100644 --- a/langchain/smith/evaluation/runner_utils.py +++ b/langchain/smith/evaluation/runner_utils.py @@ -62,7 +62,7 @@ def _wrap_in_chain_factory( if llm_or_chain_factory.memory is not None: memory_class = chain.memory.__class__.__name__ raise ValueError( - "Cannot directly evaluate a chain with statefulmemory." + "Cannot directly evaluate a chain with stateful memory." " To evaluate this chain, pass in a chain constructor" " that initializes fresh memory each time it is called." " This will safegaurd against information" @@ -88,6 +88,13 @@ def _wrap_in_chain_factory( ) return lambda: chain + elif isinstance(llm_or_chain_factory, BaseLanguageModel): + return llm_or_chain_factory + elif callable(llm_or_chain_factory): + _model = llm_or_chain_factory() + if isinstance(_model, BaseLanguageModel): + return _model + return llm_or_chain_factory return llm_or_chain_factory