01 - Import ChatPrompTemplate create template
Import ChatPromptTemplate from langchain_core.prompts
and create a template string in a template variable, passing in {context}
and {question}
from lang_chain.prompts import ChatPrompTemplate
template = """ Answer the question below. Here is the conversation history: {context} Question: {question} Answer: """
02 - create chain for template prompt to model
Send template to promprt through
ChatPromptTemplate.from_template(template)
prompt = ChainPromptTemplate.from_template(template) chain = prompt | model
then the result will be to invoke() chain instead of model AND
pass in an object with content (which we don't have yet)
and the question for now, "Tu puedes hablar espanol"
result = chain.invoke({"context":"","question":"Tu puedes hablar espanol?})"
from langchain_ollama import OllamaLLM
from langchain_core.prompts import ChatPromptTemplate
template = """
Answer the question below.
Here is the conversation history: {context}
Question: {question}
Answer
"""
model = OllamaLLM(model="llama3")
prompt = ChatPromptTemplate.from_template(template)
chain = prompt | model
result = chain.invoke({"context":"","question":"Tu puedes hablar espanol?"})
# result = model.invoke(input="hey what up")
print(result)