Langchain ChatHuggingFace
Now I develop agentic AI program and I use ChatHuggingFace in LangChain.Here is my code.from langchain_community.llms import HuggingFaceHub
llm = HuggingFaceHub(repo_id="meta-llama/Llama-3.2-3B-Instruct",
                    huggingfacehub_api_token="REDACTED_TOKEN",
                    model_kwargs={"temperature": 0.1, "max_new_tokens": 3000},
                   )
from langchain_community.chat_models import ChatHuggingFace
llm = ChatHuggingFace(llm=llm)At that time error happened.Cannot access gated repo for urlhttps://huggingface.co/meta-llama/Llama-3.2-3B-Instruct/resolve/main/config.json.Access to model meta-llama/Llama-3.2-3B-Instruct is restricted and you are not in the authorized list. Visitmeta-llama/Llama-3.2-3B-Instruct · Hugging Faceto ask for access.how can I handle?
2024-12-13T03:07:19Z
Some models are called gated models, and you need to get permission for them individually. Once you have permission, you can use them normally by giving your HF read token.huggingface.cometa-llama/Llama-3.2-3B-Instruct · Hugging FaceWe’re on a journey to advance and democratize artificial intelligence through open source and open science.huggingface.coGated modelsWe’re on a journey to advance and democratize artificial intelligence through open source and open science.
2024-12-13T09:26:25Z
Thank you.And I encounter another issue. So I load this model .from langchain_community.llms import HuggingFaceHub
hf = HuggingFaceHub(repo_id="meta-llama/Llama-3.2-1B-Instruct",
                    huggingfacehub_api_token="REDACTED_TOKEN",
                    model_kwargs={"temperature": 0.1, "max_new_tokens": 3000},
                   )
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.tools import tool
import requests
import json
tv_search = TavilySearchResults(max_results=3, search_depth='advanced',
                               max_tokens=10000)

@tool
def search_web(query: str) -> list:
   """Search the web for a query."""
   tavily_tool = TavilySearchResults(max_results=2)
   results = tavily_tool.invoke(query)
   return results

from langchain_community.chat_models import ChatHuggingFace

llm = ChatHuggingFace(llm=hf , model_id='meta-llama/Llama-3.2-1B-Instruct')
tools = [search_web]

llm.bind_tools(tools)But bind_tools NoImplementation Error happen.
2024-12-13T09:37:50Z
Trypip install -U langchain langchain_huggingface
2024-12-13T09:39:01Z
I tried it.My langchain version is 0.3.11.But not work.
2024-12-13T09:46:50Z
Perhaps unresolved issue?GitHubBind Tools do not work with ChatHuggingFace · langchain-ai/langchain ·...Checked other resources I added a very descriptive title to this question. I searched the LangChain documentation with the integrated search. I used the GitHub search to find a similar question and...You may also be able to use HuggingFace models via Ollama instead ChatHuggingface.https://api.python.langchain.com/en/latest/llms/langchain_ollama.llms.OllamaLLM.html
2024-12-13T09:52:14Z
So is there any other method to use llama3.2 with tools in langchain?
2024-12-13T09:53:15Z
langchain_ollama?
2024-12-13T09:53:54Z
give me example to use llama3.2 in langchain_ollama.
2024-12-13T09:55:11Z
Like this?OllamaLLM | 🦜️🔗 LangChain(for 3.1)
2024-12-13T09:56:14Z
But Ollama is local llm. But I don’t want to download model. So any online method?
2024-12-13T09:58:33Z
I see. In that case, there’s nothing to do but get the library working somehow, but until we know the cause…Edit:Wow…https://api.python.langchain.com/en/latest/llms/langchain_community.llms.huggingface_hub.HuggingFaceHub.htmlDeprecated since version 0.0.21: Uselangchain_huggingface.HuggingFaceEndpointinstead.python.langchain.comHuggingface Endpoints | 🦜️🔗 LangChainThe Hugging Face Hub is a platform with over 120k models, 20k datasets, and 50k demo apps (Spaces), all open source and publicly available, in an online platform where people can easily collaborate and build ML together.
2024-12-13T14:05:59Z
Thank you for your great contribution again!You are always great help for me.I expect more helping from you.
2024-12-13T15:40:17Z
@spencer1129kind reminder to rotate your HF Token since it is public. Thanks!
2024-12-14T03:40:27Z
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.