Sequential chains

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

Jonathan Bennion

AI Engineer & LangChain Contributor

 

ไกด์ท่องเที่ยว AI

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

 

คนถามไกด์ท่องเที่ยว AI เกี่ยวกับกิจกรรมในปารีส

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

 

AI แนะนำกิจกรรมในปารีสหลายรายการ

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

 

คนบอกไกด์ AI ว่าอยากไปดู Louvre และ Arc de Triomphe

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

 

ไกด์ท่องเที่ยว AI สร้างแผนการเดินทางสำหรับกิจกรรมที่เลือก

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

 

ขั้นตอนการวางแผนท่องเที่ยวนี้เป็นตัวอย่างของปัญหาแบบลำดับขั้น

การพัฒนาแอปพลิเคชัน LLM ด้วย 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}." )
llm = ChatOpenAI(model="gpt-4o-mini", api_key=openai_api_key)
seq_chain = ({"activities": destination_prompt | llm | StrOutputParser()}
| activities_prompt | llm | StrOutputParser())
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain
print(seq_chain.invoke({"destination": "Rome"}))
- 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.
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

มาฝึกกันเถอะ!

การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain

Preparing Video For Download...