I’m trying AI Agent in LangChain and build a very basic agent with HuggingFace free model. But when I run the code I got the following error. could you help me to figure out why this happened? I use Huggingface free model previously but now I got it.
CODE:
from langchain_huggingface import (
ChatHuggingFace,
HuggingFaceEndpoint
)
from langchain_core.tools import tool
from langchain_community.tools import DuckDuckGoSearchRun
from langchain.agents import (
create_react_agent,
AgentExecutor
)
from langchain import hub
from dotenv import load_dotenv
load_dotenv()
llm_model = HuggingFaceEndpoint(
repo_id = “google/gemma-2-2b-it”,
task = “text-generation”
)
model = ChatHuggingFace(llm=llm_model)
search_tool = DuckDuckGoSearchRun()
prompt = hub.pull(“hwchase17/react”)
agent = create_react_agent(
llm=model,
tools=[search_tool],
prompt=prompt
)
agent_executer = AgentExecutor(
agent=agent,
tools=[search_tool],
verbose=True
)
response = agent_executer.invoke({
“input”:“3 way to reach goa from delhi”
})
print(response)
Blockquote
ERROR:
File “/home/meharaz/Documents/Projects/LangChain-Practice/LangChain/lib/python3.13/site-packages/langchain_core/language_models/chat_models.py”, line 925, in _generate_with_cache
result = self._generate(
messages, stop=stop, run_manager=run_manager, **kwargs
)
File “/home/meharaz/Documents/Projects/LangChain-Practice/LangChain/lib/python3.13/site-packages/langchain_huggingface/chat_models/huggingface.py”, line 370, in _generate
answer = self.llm.client.chat_completion(messages=message_dicts, **kwargs)
File “/home/meharaz/Documents/Projects/LangChain-Practice/LangChain/lib/python3.13/site-packages/huggingface_hub/inference/_client.py”, line 992, in chat_completion
data = self._inner_post(request_parameters, stream=stream)
File “/home/meharaz/Documents/Projects/LangChain-Practice/LangChain/lib/python3.13/site-packages/huggingface_hub/inference/_client.py”, line 357, in _inner_post
hf_raise_for_status(response)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File “/home/meharaz/Documents/Projects/LangChain-Practice/LangChain/lib/python3.13/site-packages/huggingface_hub/utils/_http.py”, line 482, in hf_raise_for_status
raise _format(HfHubHTTPError, str(e), response) from e
huggingface_hub.errors.HfHubHTTPError: 404 Client Error: Not Found for url: https://router.huggingface.co/hf-inference/models/google/gemma-2-2b-it/v1/chat/completions (Request ID: Root=1-696eeb4f-3b421b5235b5e633725c642a;bfa2288a-0f4c-4f3d-8364-72987c241759)
