chapter2
chapter2
D E V E L O P I N G L L M A P P L I C AT I O N S W I T H L A N G C H A I N
Jonathan Bennion
AI Engineer & LangChain Contributor
DEVELOPING LLM APPLICATIONS WITH LANGCHAIN
DEVELOPING LLM APPLICATIONS WITH LANGCHAIN
DEVELOPING LLM APPLICATIONS WITH LANGCHAIN
DEVELOPING LLM APPLICATIONS WITH LANGCHAIN
DEVELOPING LLM APPLICATIONS WITH LANGCHAIN
DEVELOPING LLM APPLICATIONS WITH LANGCHAIN
Sequential chains
Output → input
destination_prompt = PromptTemplate(
input_variables=["destination"],
template="I am planning a trip to {destination}. Can you suggest some activities to do there?"
)
activities_prompt = PromptTemplate(
input_variables=["activities"],
template="I only have one day, so can you create an itinerary from your top three activities: {activities}."
)
- Morning:
1. Start your day early with a visit to the Colosseum. Take a guided tour to learn about its history and significance.
2. After exploring the Colosseum, head to the Roman Forum and Palatine Hill to see more of ancient Rome's ruins.
- Lunch:
3. Enjoy a delicious Italian lunch at a local restaurant near the historic center.
- Afternoon:
4. Visit the Vatican City and explore St. Peter's Basilica, the Vatican Museums, and the Sistine Chapel.
5. Take some time to wander through the charming streets of Rome, stopping at landmarks like the Pantheon, Trevi
Fountain, and Piazza Navona.
- Evening:
6. Relax in one of Rome's beautiful parks, such as Villa Borghese or the Orange Garden, for a peaceful escape from the
bustling city.
7. End your day with a leisurely dinner at a local restaurant, indulging in more Italian cuisine and maybe some gelato.
Jonathan Bennion
AI Engineer & LangChain Contributor
What are agents?
print(messages['messages'][-1].content)
Jonathan Bennion
AI Engineer & LangChain Contributor
Tool formats
from langchain.agents import load_tools
Calculator
print(tools[0].description)
False
@tool
def financial_report(company_name: str, revenue: int, expenses: int) -> str:
"""Generate a financial report for a company that calculates net income."""
net_income = revenue - expenses
financial_report
Generate a financial report for a company that calculates net income.
False
{'company_name': {'title': 'Company Name', 'type': 'string'},
'revenue': {'title': 'Revenue', 'type': 'integer'},
'expenses': {'title': 'Expenses', 'type': 'integer'}}