Prompt templates and chaining
In this exercise, you'll begin using two of the core components in LangChain: prompt templates and chains!
The classes necessary for completing this exercise, including ChatOpenAI, have been pre-loaded for you.
Deze oefening maakt deel uit van de cursus
Developing LLM Applications with LangChain
Oefeninstructies
- Convert the
templatetext provided into a standard (non-chat) prompt template. - Create a chain to pass the prompt template into the LLM.
- Invoke the chain on the
questionvariable provided.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Create a prompt template from the template string
template = "You are an artificial intelligence assistant, answer the question. {question}"
prompt = PromptTemplate.____(
template=____
)
llm = ChatOpenAI(model="gpt-4o-mini", api_key='')
# Create a chain to integrate the prompt template and LLM
llm_chain = ____ | ____
# Invoke the chain on the question
question = "How does LangChain make LLM application development easier?"
print(llm_chain.invoke({"question": ____}))