Chat Model API/RetrievalQA chain - Possible to use Self-Hosted HuggingFace LLMs? - Hints? Examples? #9385
-
From https://api.python.langchain.com/en/latest/api_reference.html#module-langchain.chat_models I was following the training at: I looked at https://python.langchain.com/docs/integrations/chat/ My use case: Am I just out of luck? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
🤖 Hello, Yes, it is indeed possible to use self-hosted HuggingFace language models with the LangChain framework for developing a chat agent, including for RetrievalQA chains. The LangChain framework provides a class named Here is an example of how to use it: from langchain.llms import SelfHostedHuggingFaceLLM
import runhouse as rh
gpu = rh.cluster(name="rh-a10x", instance_type="A100:1")
hf = SelfHostedHuggingFaceLLM(
model_id="google/flan-t5-large", task="text2text-generation",
hardware=gpu
) In this example, the The Here is a simple example of how you can use it: from langchain.llms import SelfHostedHuggingFaceLLM
from langchain.agents.chat.base import ChatAgent
import runhouse as rh
# Specify the hardware to use for the model
gpu = rh.cluster(name="rh-a10x", instance_type="A100:1")
# Create an instance of the SelfHostedHuggingFaceLLM class
hf = SelfHostedHuggingFaceLLM(
model_id="gpt2",
task="text-generation",
hardware=gpu
)
# Create a ChatAgent using the SelfHostedHuggingFaceLLM instance
chat_agent = ChatAgent.from_llm_and_tools(llm=hf, tools=[])
# Use the chat agent to generate a response to a user input
response = chat_agent.llm_chain.llm._call(prompt="Hello, how are you?")
print(response) In this example, we're using the GPT-2 model for text generation. The Please note that the I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
@dosu-bot, this sounds promising, but it skips over my first question above:
I found this more complete description: It would be nice if it was cross-referenced in: For truly self-hosted/locally hosted HuggingFace LLaMA2 models I ended up with this code. It's not perfect, but it does allow testing:
Then llm can be used in langchain chains... --OC |
Beta Was this translation helpful? Give feedback.
-
Yes, you can use self-hosted HuggingFace language models with the LangChain framework, including Retrieval chains. Since you haven't mentioned anything about the use case, the privacy and user limits per day are restricted in HuggingFace. If you're looking for any alternatives, I hope this guide will be helpful for you. https://www.contus.com/blog/best-self-hosted-chat-platforms/ |
Beta Was this translation helpful? Give feedback.
@dosu-bot, this sounds promising, but it skips over my first question above:
I found this more complete description:
https://blog.langchain.dev/chat-models/
It would be nice if it was cross-referenced in:
https://api.python.langchain.com/en/latest/api_reference.html#module-langchain.chat_models
For truly self-hosted/locally hosted HuggingFace LLaMA2 models I ended up with this code. It's not perfect, but it does allow testing: