Replies: 2 comments
-
The exception "RunnableSequence' object has no attribute 'get'" when instantiating In the provided code, the Here is a snippet showing the correct usage: from langchain_core.callbacks import Callbacks
# Assuming you have a valid Callbacks object
callbacks = Callbacks()
reduce_documents_chain = ReduceDocumentsChain(
combine_documents_chain=combine_documents_chain,
collapse_documents_chain=combine_documents_chain,
token_max=4000,
verbose=True,
callbacks=callbacks, # Ensure this is a Callbacks object
) Make sure that the Additionally, ensure that the from langchain.chains import (
StuffDocumentsChain,
LLMChain,
ReduceDocumentsChain,
MapReduceDocumentsChain,
)
from langchain_core.prompts import PromptTemplate
from langchain_community.llms import OpenAI
document_prompt = PromptTemplate(
input_variables=["page_content"],
template="{page_content}"
)
document_variable_name = "context"
llm = OpenAI()
prompt = PromptTemplate.from_template(
"Summarize this content: {context}"
)
llm_chain = LLMChain(llm=llm, prompt=prompt)
reduce_prompt = PromptTemplate.from_template(
"Combine these summaries: {context}"
)
reduce_llm_chain = LLMChain(llm=llm, prompt=reduce_prompt)
combine_documents_chain = StuffDocumentsChain(
llm_chain=reduce_llm_chain,
document_prompt=document_prompt,
document_variable_name=document_variable_name
)
reduce_documents_chain = ReduceDocumentsChain(
combine_documents_chain=combine_documents_chain,
)
chain = MapReduceDocumentsChain(
llm_chain=llm_chain,
reduce_documents_chain=reduce_documents_chain,
) Ensure that all components are correctly instantiated and passed to avoid attribute errors [1][2]. |
Beta Was this translation helpful? Give feedback.
-
@dubbl-d please provide a minimal reproducible example. Feel free to open an issue if it's obviously not from user code |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to get rid of deprecation warnings and one of the things I have to do is replace the StuffDocumentsChain with the preferred
create_stuff_documents_chain(...)
method. In the code above, I am getting an exception in pydantic validation code that is looking for aget
attribute on theRunnableSequence
object. I have checked with the 0.3 langchain docs to make sure my dependencies are correct and I don't reference any Pydantic v1 objects anywhere. This exception happens in theReduceDocumentsChain
constructor/init method when it calls pydantic to validate attributes. It isn't clear where or why it is looking to validate aget
attribute.My dependencies and system info are in the section below. Here is the stack trace that I am getting from LangSmith traces:
AttributeError("'RunnableSequence' object has no attribute 'get'") Traceback (most recent call last): File "/Users/dubbled/eng/inference/llm/llm_inferences.py", line 108, in infer_transcript_topic_summary reduce_documents_chain = ReduceDocumentsChain(combine_documents_chain=combine_documents_chain, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dubbled/.pyenv/versions/3.11.7/lib/python3.11/site-packages/langchain_core/load/serializable.py", line 112, in init super().init(*args, **kwargs) File "/Users/dubbled/.pyenv/versions/3.11.7/lib/python3.11/site-packages/pydantic/main.py", line 212, in init validated_self = self.pydantic_validator.validate_python(data, self_instance=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dubbled/.pyenv/versions/3.11.7/lib/python3.11/site-packages/langchain/chains/base.py", line 236, in raise_callback_manager_deprecation if values.get("callback_manager") is not None: ^^^^^^^^^^ File "/Users/dubbled/.pyenv/versions/3.11.7/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 5704, in getattr attr = getattr(self.bound, name) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/dubbled/.pyenv/versions/3.11.7/lib/python3.11/site-packages/pydantic/main.py", line 856, in getattr raise AttributeError(f'{type(self).name!r} object has no attribute {item!r}') AttributeError: 'RunnableSequence' object has no attribute 'get'
System Info
$ python -m langchain_core.sys_info
System Information
Package Information
Optional packages not installed
Other Dependencies
Beta Was this translation helpful? Give feedback.
All reactions