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.
Questo esercizio fa parte del corso
Developing LLM Applications with LangChain
Istruzioni dell'esercizio
- 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.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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": ____}))