docs/integrations/chat/huggingface/ #28121
Replies: 4 comments
-
I have an issue with the output of the Below is my code: import transformers, torch
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
model_id = "meta-llama/Llama-3.2-1B-Instruct"
pipe = transformers.pipeline(
"text-generation",
model=model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
max_new_tokens=2048,
do_sample=False,
repetition_penalty=1.03
)
pipe.tokenizer.pad_token_id = pipe.model.config.eos_token_id
model_kwargs = {'temperature':0.3}
llm = HuggingFacePipeline(pipeline = pipe, model_kwargs = model_kwargs)
chat_model = ChatHuggingFace(llm=llm)
from langchain_core.messages import (
HumanMessage,
SystemMessage,
)
messages = [
SystemMessage(content="You're a helpful assistant"),
HumanMessage(
content="What happens when an unstoppable force meets an immovable object?"
),
]
ai_msg = chat_model.invoke(messages)
print(ai_msg.content) And this is the output:
Is this what I'm supposed to have? |
Beta Was this translation helpful? Give feedback.
-
buy a car |
Beta Was this translation helpful? Give feedback.
-
build a home. |
Beta Was this translation helpful? Give feedback.
-
add in the pipeline_kwargs { "return_full_text": False}. By the way, I would take into consideration buying a car |
Beta Was this translation helpful? Give feedback.
-
docs/integrations/chat/huggingface/
This will help you getting started with langchainhuggingface chat models. For detailed documentation of all ChatHuggingFace features and configurations head to the API reference. For a list of models supported by Hugging Face check out this page.
https://python.langchain.com/docs/integrations/chat/huggingface/
Beta Was this translation helpful? Give feedback.
All reactions