Pendarh
Pendarh

Reputation: 1

Error about bind attribute when making langchain agent with huggingface models

I am trying to write a python code for making Lang chain agent with hugging face models but I encounter an error:

'TextGenerationPipeline' object has no attribute 'bind' 

this error happens when I create the agent model:

agent = create_react_agent(llm, tools, prompt)

This is the whole code:

import os
from google.colab import userdata



# Set API key
import os
os.environ["LANGCHAIN_API_KEY"] = userdata.get("LANGCHAIN_API_KEY")

os.environ["HUGGINGFACEHUB_API_TOKEN"] = userdata.get("HUGGINGFACEHUB_API_TOKEN")

!pip install langchain_community
!pip install langchain
!pip install transformers
!pip install huggingface_hub
!pip install arxiv

!pip install wikipedia

from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent, load_tools
from transformers import pipeline
from langchain_community.llms import HuggingFacePipeline

from langchain.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper

wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())

hf_pipeline = pipeline("text-generation", model="meta-llama/Meta-Llama-3.1-8B-Instruct", max_length=256, temperature=0.7)

hf_pipeline = pipeline("text-generation", model="google/flan-t5-xl", temperature=0.7)

llm = hf_pipeline
tools = load_tools(
    ["arxiv"])



prompt = hub.pull("hwchase17/react")

agent = create_react_agent(llm, tools, prompt)

agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

agent_executor.invoke(
    {
        "input": "hi",
    }
)

I tried to run this line and make the agent: agent = create_react_agent(llm, tools, prompt)

and I expected to run without error such as when I wrote the similar code for openai model

but I got this error everytime with different models I choose: 'TextGenerationPipeline' object has no attribute 'bind'

Upvotes: 0

Views: 179

Answers (0)

Related Questions