mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-28 01:19:31 +00:00
Accept LLM via constructor (#7794)
This commit is contained in:
parent
c4ece52dac
commit
ed97af423c
@ -62,7 +62,7 @@ def _wrap_in_chain_factory(
|
|||||||
if llm_or_chain_factory.memory is not None:
|
if llm_or_chain_factory.memory is not None:
|
||||||
memory_class = chain.memory.__class__.__name__
|
memory_class = chain.memory.__class__.__name__
|
||||||
raise ValueError(
|
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"
|
" To evaluate this chain, pass in a chain constructor"
|
||||||
" that initializes fresh memory each time it is called."
|
" that initializes fresh memory each time it is called."
|
||||||
" This will safegaurd against information"
|
" This will safegaurd against information"
|
||||||
@ -88,6 +88,13 @@ def _wrap_in_chain_factory(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return lambda: chain
|
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
|
return llm_or_chain_factory
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user