Whenever I try to use a SystemMesssage or SystemMessagePromptTemplate with a pipeline, it prints out the System Message as part of the response. I thought it would be like when using an api (it doesn’t show the system messages and instead is used as context for the LLM). I think I’m using the wrong classes for these but I can’t seem to find how to do it in the docs. Is this something that you are not able to do when it’s installed locally?
Here’s the code:
<code>from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
from langchain_core.prompts.chat import (
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
ChatPromptTemplate
)
model = "openai-community/gpt2"
hf = HuggingFacePipeline.from_model_id(
model_id=model,
task="text-generation",
pipeline_kwargs={"max_new_tokens": 20},
)
messages = [
SystemMessagePromptTemplate.from_template(
"You are a game show host that asks a general trivia question. You only ask one question and that is all. You ask it in a cheery and entertaining way as a game show host would do."
),
HumanMessagePromptTemplate.from_template("What's your question host?"),
]
prompt = ChatPromptTemplate.from_messages(messages)
chain = prompt | hf
print(chain.invoke({}))
</code>
<code>from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
from langchain_core.prompts.chat import (
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
ChatPromptTemplate
)
model = "openai-community/gpt2"
hf = HuggingFacePipeline.from_model_id(
model_id=model,
task="text-generation",
pipeline_kwargs={"max_new_tokens": 20},
)
messages = [
SystemMessagePromptTemplate.from_template(
"You are a game show host that asks a general trivia question. You only ask one question and that is all. You ask it in a cheery and entertaining way as a game show host would do."
),
HumanMessagePromptTemplate.from_template("What's your question host?"),
]
prompt = ChatPromptTemplate.from_messages(messages)
chain = prompt | hf
print(chain.invoke({}))
</code>
from langchain_community.llms.huggingface_pipeline import HuggingFacePipeline
from langchain_core.prompts.chat import (
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
ChatPromptTemplate
)
model = "openai-community/gpt2"
hf = HuggingFacePipeline.from_model_id(
model_id=model,
task="text-generation",
pipeline_kwargs={"max_new_tokens": 20},
)
messages = [
SystemMessagePromptTemplate.from_template(
"You are a game show host that asks a general trivia question. You only ask one question and that is all. You ask it in a cheery and entertaining way as a game show host would do."
),
HumanMessagePromptTemplate.from_template("What's your question host?"),
]
prompt = ChatPromptTemplate.from_messages(messages)
chain = prompt | hf
print(chain.invoke({}))
Here’s an example of the response:
<code>System: You are a game show host that asks a general trivia question. You only ask one question and that is all. You ask it in a cheery and entertaining way as a game show host would do.
Human: What's your question host?
Humor is at the heart of your game show, so we're going to run a lot
</code>
<code>System: You are a game show host that asks a general trivia question. You only ask one question and that is all. You ask it in a cheery and entertaining way as a game show host would do.
Human: What's your question host?
Humor is at the heart of your game show, so we're going to run a lot
</code>
System: You are a game show host that asks a general trivia question. You only ask one question and that is all. You ask it in a cheery and entertaining way as a game show host would do.
Human: What's your question host?
Humor is at the heart of your game show, so we're going to run a lot
What I’m expecting is just one random general trivia question to be printed without anything else.