The video owner has disabled playback on external websites.
This video is no longer available on YouTube.
This video cannot be played right now.
Watch on YouTube
افتح أدوات التعلم بالذكاء الاصطناعي
سجّل للوصول إلى أدوات قوية تساعدك على التعلم أسرع من كل فيديو.
Avoid Messy Code: Design Patterns for AI Agents in Python
الترجمة (462 مقاطع)
This video is brought to you by
Squarespace. If you're trying to build
something with large language models,
you know things can get messy pretty
quickly. You start with one prompt, then
you add a few tools, then you pass some
data to another model, and before long,
your logic is going to be scattered and
all over the place. So, the question is,
how do you structure AI systems the
right way? In this video, I'm going to
show you three design patterns that I've
adapted for LLMs and agents that are
going to help you build cleaner, more
modular AI systems. Let's go. The
example that I'm going to use in this
video is a travel agent. And this agent
can help you find hotels and flights,
etc., etc. Now, there is one prompt that
I'm going to start with, which is this.
I want a rainy city trip within Europe.
I love towers. I don't want to cross
water to get there. And this is Maria
who lives in Berlin. So, let's run this
particular example and see what happens.
The agent has decided that Maria needs
to go to Paris, France, which is wrong.
It should be Utre, the Netherlands.
Anyway, okay, Paris. Fine. So, then the
agent books a flight from Berlin to
Paris, which arrives at 6:00 p.m. It
looks for a hotel, which is the highest
regency in Paris. I don't know if this
is a good hotel or not. And then uh but
it is quite expensive so hopefully it
is. And then there are some activities
for early evening explorers. You can
visit the shopping mall, take an evening
walk, uh enjoy a dinner, etc., etc. So
the Asian has done like a bunch of
different things here. And that's
typically something that you're going to
encounter in AI application, right? It's
not just I send a prompt and I get back
a response. I mean, we can just use a
chat agent for that. We want something
that's a bit more uh involved. And of
course, in this particular situation,
you don't want to handle everything in
one massive prompt because that's simply
not going to work. You need to break it
down into separate agents and then each
is responsible for a single step. So we
have choosing a destination, we have
planning the flight, recommending a
hotel, and suggesting things to do. The
way I've built this is that I'm
implementing each of these steps as its
own function. And then you can execute
them in order by storing them in a list.
More about that in a minute. So how is
this code actually set up? I'm using
byic AI for the agents. So first I load
the environment variables. In this case,
there's just one which is the OpenAI API
key. Then we have some dependencies
which is we need to know the username.
We need to know the origin city and then
there is a context that's basically the
information that each of these agents is
going to need. So things like the
destination, the uh origin city, the
arrival time, the hotel name, etc. And
this going to be filled in step by step
by the agents. Then for each step I have
an agent. So in this case I have a
destination agent that helps users find
a ideal tra travel destination based on
their preferences.
Then I have a flight agent that can look
for flights for a particular trip. Then
I have a hotel recommendation agent that
suggests a good hotel near the airport
or city center. Then we have an activity
agent that suggests local activities. So
you have all these different agents that
can do each a specific thing that also
have their own system prompts that to
adapt them. And then the pattern that
I'm using to perform these tasks in
order is the chain of responsibility.
And what that pattern entails that you
have a bunch of different functions that
الترجمة الكاملة متاحة في مشغل الفيديو
تدرّب مع التمارين
أنشئ تمارين مفردات وقواعد وفهم من هذا الفيديو
التعليقات (0)
تسجيل الدخول للتعليقالوضع التفاعلي
اختبار
الإجابة الصحيحة:
فيديوهات ذات صلة
Late Night with Seth Meyers
اختبار
الإجابة الصحيحة:
تظهر الاختبارات أثناء مشاهدة الفيديو
نصيحة للحفظ
من هذا الفيديو
ابدأ تعلم اللغات مجاناً