- How to Disable Safety Settings in Gemini Vision Pro Model Using API?
- [Solved] Filter langchain vector database using as_retriever search_kwargs parameter
- [Solved] ModuleNotFoundError: No module named 'llama_index.graph_stores'
- Best AI Text Generators for High Quality Content Writing
- Tensorflow Error on Macbook M1 Pro - NotFoundError: Graph execution error
- How does GPT-like transformers utilize only the decoder to do sequence generation?
- How to set all tensors to cuda device?
- How should I use torch.compile properly?
- How do I check if PyTorch is using the GPU?
- WARNING:tensorflow:Using a while_loop for converting cause there is no registered converter for this op
- How to use OneCycleLR?
- Error in Python script "Expected 2D array, got 1D array instead:"?
- How to save model in .pb format and then load it for inference in Tensorflow?
- Top 6 AI Logo Generator Up Until Now- Smarter Than Midjourney
- Best 9 AI Story Generator Tools
- The Top 6 AI Voice Generator Tools
- Best AI Low Code/No Code Tools for Rapid Application Development
- YOLOV8 how does it handle different image sizes
- Best AI Tools For Email Writing & Assistants
- 8 Data Science Competition Platforms Beyond Kaggle
[Solved] TypeError when chaining Runnables in LangChain: Expected a Runnable, callable or dict
In the field of natural language processing, LangChain or the Large Language Model brings the evolution of the ability to understand more complex queries of human language. So, this powerful framework is commonly used for building applications. However, working with this framework sometimes we might encounter this type of error "TypeError: when chaining Runnables in LangChain: Expected a Runnable, callable or dict". To fix this issue we first understand why we get this error.
We get this error basically when we try to chain multiple tasks(Runnables) at the same time, but one or more tasks do not meet the expected type requirements. A runnable is an object that is defined in a 'run' method. A callable is any function or method, and a dict should map string keys to callable or runnable objects in LangChain.
Solution 1:
The issue is context of type str. Pass in a lambda function instead:
rag_chain = (
{"context": lambda x: context, "question": RunnablePassthrough()} | rag_custom_prompt | llm
)
Solution 2:
Use llm from langchain.llms library for chain instead
from langchain.llms import OpenAI
llm = OpenAI(model_name="gpt-3.5-turbo")
We can fix the error "TypeError: when chaining Runnables in LangChain: Expected a Runnable, callable or dict" by following these steps. These techniques help to maintain the flexibility and modularity of our text processing workflows.
Thank you for reading the article.