Multi-Agent Function Calling LLMs - CODE for AI Agents

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello community multi-agent llm why suddenly they are a hot topic it is because of social science you know those people that watch us that watch every focus group and decide how people could react look here at this publication of science here June 15 2023 Ai and the transformation of social science research or take this here can AI language model replace human participants here in cognitive Sciences science and Society does GPT make human-like judgment interesting suddenly here the complete cognitive Sciences discover GPT and what is really amazing and this is here brand new publication that shows you here the average human moral judgment and GPT moral judgment and they see here a very very clear correlation and one of the main Insight of the study is here the GPT 3.5 and human judgment align with 93 across gender and age groups so this means here all the different social on cognitive science analysis reveal instead of a human judgment for 93 percent you can go with a GPT judgment so suddenly this becomes now an instrument and as you can see here in this other publication here augmented servers leveraging llms for opinion prediction on nationally representative surveys we have suddenly hear the new era of llms now in product development so what they found is that llms can simulate human-like responses llms replace humans in the data collection but one of the most important is llms can predict individual responses to survey questions but the really driver of all of this in the industry is multi-agent system multi-agent llms and now we close the circle so interestingly it is not computer science that is driving this this here is cognitive science social science and they apply multi-agent llms have insect why is it because they found that using multi-agent system with an llm they can simulate complex social interactions so you need multiplayer agents interacting with each other and you can predict social phenomena of human beings think about your application think about marketing advertising think about the market size of tens and hundreds of billion US dollars suddenly a new tool is available and this tool has some features this tool understands consumer Behavior inside inter consumer behavior for new marketing strategies this new tool this multi-agent llm can predict consumer preferences so if you have for example new product launches for a specific Market you can adjust adjustments before you launch the real product or understand about Market segmentation think about personalized marketing product testing focus groups so in summary with this new cognitive science wave discovering here LMS and multi-agents and this is one of the important points I would like to stress they conclude in this Con transform the complete marketing industry where providing deeper insight into their consumer Behavior enabling personalized marketing enhancing Market segmentation and improved product testing and advertising and marketing and advertising are two main branches where you can make money so before we just jump now into coding agents and I have to tell you what is an agent in a multi-agent system we have to include here the latest technology and as you can see here from open AI this is open AI official function calling and other API updates and they are nouns here for me it is four days ago that I have now more stable API models new function calling capabilities lower prices and new models available so we will take advantage of this new technology in integrate it if you look at the official documentation from opinion you see they say here we have now the new models audio go with the GPD 3.5 turbo o613 or with GPT 40613 June 13. the date it was published and they are able to have those ability to call functions and the main segments of all the description is here the chat completion API of openai does not called a function instead the model generates just a Json that you can use to call the function in your code that you have written and I will show you the code in a moment so if we integrate this you might ask but why do you need it and this is here the most simple explanation I could think of to show you why we need this new technology and what it offers on the one side we have gpd4 in our natural language understanding and on the other side we have 99.9 percent of the data of the world that are not able to communicate in a natural language that have the data structured in a specific way where data buys well for a flight recording or for some document storage and you have your apis that connect to the data by space and everything and what you have now you have an intelligent system that speaks a natural human language and structured data so you have on the interface to dumb it down and openly I decided it will go with Json and then you have your database query SQL comes back says yes I have the information you're looking for and then again you intelligence it up the Json reply to a natural language so this process of dumbing it down and intelligence it up is exactly what is function calling why we are function calling because here 99 of our structured data are not able that you can communicate with them in your natural language so understanding this you now know why and I will tell you now the code how we do this with agents but just to be absolutely clear the intelligence behind this to dumb it down is our gpt4 and the intelligence behind this to scale the intelligence up to a natural language is also done by gpt4 and you know every time you touch an API you have to pay so you pay for gpd4 you pay for every API and you pay for all interface in and out so just to remind you this is related with some significant costs and what we're gonna do now write some pattern code I will show you for specific tasks we will write the code for certain agents and those agents have certain functions and those function can then be called and I will show you how this system interacts but for me it was interesting to see what is the overview why we need this function calling and what does it perform and you will notice in our code we will use not at all any length chain on any substitution or anything at all because of this new functionality by open Ai and the new llms models by open AI this can be done directly in Python code so let's code so before we start with two agents interacting with each other I think with time and we should have a look here at function calls let's start here for the introduction what is a function call oh wait there's some other things I can show you yeah let's start here with our open EI updates so I told you we have here new models and now we try to understand here what this function calling capability can do for us and the content with multi-agent for our llms so let's have a look at the code make a data we can see it in one glance okay smaller smaller okay so at first we have a function I have a specific task and I've defined a function for this task now for example the task is find my flights from I don't know let's say we are departing from the us and we're flying over to the UK so I want to find my flight so I Define a function a gift a function a name I call it find flights intelligent I say hey what are you you are a function and then I have the arguments and the arguments are from the city where I start to the city where I want to go to my departure date and my return date and all of this is a string type so this is all there is to define a function and as you know we're interacting here with gpd4 for example so you need to define the message I'll make it a little bit bigger so the message is easy you say hey I'm here to system so I give you a command you are a helpful assistant to help users find the flights from us to UK and then you define the instruction and the instruction is for example user base you say hey now I'm as a user find me a flight from New York to London departing on a specific day on the returning on a specific day so beautiful and then you call an API and now you call an open EI API that has the ability here with is function calling and the new model that is compatible and has been trained on function calling so we say here opinion dot chat completion create our standard model and now please watch out you have to put in this model gpt4 June 13. this model or later models whenever you watch this video can do here this beautiful function calling if you go with the standard gpt4 you might have problems when you have messages you have your system message and you have your instruction on a user message and we Define a function this is our function it couldn't be easier I know I know this and then comes the part where you now address cheap84 and you say hey gpt4 do now here the chat completion at a specific point and these are my messages these are my function and I say the response that I get back from gpd4 I look at the choices and I take the function call and this variable this function call variable will have now my Json information that I need to connect to an external API beautiful since I saw that a lot of people just want to have a code video and not explained how it works I'm not gonna tell you how it works we just look at the code so here we go the code you get back from tbd4 here is exactly this in our example let's have a look at it you have an ID beautiful you have here that completion created you have hidden model this is our model for the function calls whatever you pay here are your number of tokens you have to pay and then here we go with the choices remember choices yeah choices remember this so we hear choices and we have mostly two we have here a message and we have a function call now the message is clear this is our natural language message so the assistant comes back gbd4 comes back and says sure I can help you with that let me find your flights for you but now with this new function calling I get a function callback and this is what gpt4 gives me back and this is a Json a dictionary easy as can be you have here the name of the function find flights and the arguments from city is now New York two city is not London departure date and the return date so remember that I Define the function here from City to City departure date return date now I have my data that I communicated here in a natural language sentence I have now here in a Json format this is all there is to a function call the moment you understand this the system is clear for you and we can use this now so again we had here response Joyce's function call and here we have here the function call and as I just told you this is it so okay let's have a look at this separated so you have the name of the function and here the specific parameters beautiful again since it's so important just let me remind you what is a function call it is simply here in programming a commander tells the program to execute a specific function in the context of gbt4 a function call is structured a Json object that include a function name and arguments yes function name and the function arguments this is it nothing else to it again yes you know it and then please please remember this sentence I put it here twice the GPT model generates this function call based on two objects based on its understanding of the user instruction and the user instruction I showed you is find me a flight from New York to London departing on day one and coming back on day two this is the user instruction and then the function description and as I showed you the function description as a name a type and the arguments defined as string this is it beautiful now let's do here now an example of an external API without gpd4 or any llm and then we will do this with gbd4 and then we will do it with gpd4 and agents so what is the classical way before everything we know about gpd4 well you had your request and then you had simply a class a python class let's call this python class flight booking API to access here the flight bookings server from I don't know Delta Airlines you need a key so you need your credit card you say okay I am here I authorize myself and here's my credit card and you get a key to access the flight booking server from Delta then you define a function here is your function that you define right this function includes now here given the specific task that you want to achieve exactly what you want to do you want to call the flight booking API Delta we'll say here request get from delta.com flights you define the parameter that normally are in the function but since we are now without here gpd4 and this function functionality you just Define the four parameters here manually you see there's no no where function it's just parameters a b c d another yes your API key or authorization and then you get a response back here from your request statement that you send to the Delta airlines.com flights whatever API and you get it back and this here is your complete class of the flight booking API this is the traditional way we have done it before function calling external API gbd4 API anything like that so you see easy what we do now we create a flight booking app in Python we say the flight booking app we give our API key of Delta we pay now with our credit card in this moment so we have our API our external API and then we just say okay from our flight booking API we call now the function for the module find flights from New York London day one day two then you have the flights beautiful again simple as hell yes nobody wants to understand why we do this okay so we go to the code same exercise but now with an agent with gbd4 open AI API and an external API so now we go with Max complexity beautiful so this is now our agent our agent is a python class wow who would expect it otherwise in this example I give you a little bit more information and say okay open me I open my import requests and of course since we gonna use Now gpt4 API we need an open AI API key since we are gonna have here an external API in Delta we need here the flight API key and after we paid for all connectivity we can start we Define now a function find flights where we have the parameter from the city to the city departure date and return date so exactly our four parameters and we do exactly the same we say now open AI chat completion create like we do normally when we interact with gpt4 with our gpd4 model now we choose the gbd4 model with the function calling functionality please do not make the mistake and leave this out then we have our role as a system you're a helpful assistant to find flights you notice the rule as a user find me a flight from the city to the city departing on day one coming back on day two and then comes now your function command this is the pink one here we go and this is exactly the function we had before so you give it a name you tell it hey you are now a function you have the arguments as easy as hell you know all these arguments and then you say beautiful now we do the same we have here you know this is our response when we call now careful we're calling gpt4 when we say response from gbd4 choices and now we extract the function call that I showed you two minutes ago and when we have the function call we're going to use this function call now when we connect now to the second app API but now to an external booking flight booking API so we say request get from Delta Airlines flights our parameters but now we have here back from GPT for the function calls so we use this now for our four parameters you see beautiful function call from CD from City to City yes you can read it your authorization beautiful and then you process the flight data so flight response all of this your request is executed Json and you return the flight data as simple as it is so now again we do here our flight booking now it's not a flight booking API but now we have a flight booking agent both are python classes so it's the same you just have to insert now since we are accessing two apis you have now the gpd4 openai API key that you pay and again you have here your Delta flight API key that you have to pay so we create now our flight booking agent a python class and then we say so what's called now agent and then we call here the function find flights remember functions find flights this is it oops where are you though this is a function I make it a little bit smaller even more okay more more okay so you see this is our function and find flights here we have everything you have the interaction with open EI and here we make now the dumming down we get a response now in Json in our function call we can send off the Json command now to our external API from Delta Airlines we of course are Json files is in sync with the API into the data the API can handle and then we come back and maybe I'll make it again a little bit bigger and then we say okay and now we say agent find flight and now we give for example here the data New York London and here we go so now you get the data back and you still have it more or less now in tabular form or in CSV file format or whatever so and now you can do something again now you can intelligence it up remember now I'm gonna yeah I'm gonna I would have explained why the modularity and the reusability but since it was asked only the code let me show you this let me show you this in the original open AI function calling here's it for example here we have a weather example so you connect to weather.com and you want to know the weather in Boston instead of a flight we are now here we use the model response to call our API so here instead of the Delta Airlines we have another weather API and we get some response not our flight data your flight will leave New York to uh London on the day at seven o'clock now we have here temperature in degree celsius beautiful and then now we are not satisfied that we just have here temperature 22 celsius Sunny for a day now we call opinion API again and we have a request and response and we sent a request to gpt4 oh no here's GPT 3.5 Turbo June 13 so this is our jet GPT model that can understand function calling and have a look what we do so again we have the model and then we have the messages the message is clear we have the user what is the weather like then we have the assistant with the function call here we have now the name of the function get current weather and the argument the location Boston Massachusetts unbelievable and then we have now in the function we got the result back remember this is the result of the function we have now from the get current weather we have the content the content here is exactly as I showed you temperature 22 degrees Celsius beautiful so since we want this now in a sentence we Define now here yeah this is the function that we have get current weather this is exactly the function we have here and there we have the property you have a location this is a string type and this is the city in the state San Francisco whatever you like Boston and you have here the temperature unit is also a string but the the unit itself is in Celsius or in Fahrenheit beautiful so you send now this information to gpt4 and you get a response from gpd4 and I remember as I told you will get something back with choices and choices will have here a message and in this message now we have in the role of our assistant Tubidy Force our assistant we have now the content and the content is the answer now we have the content in a human language sentence content reads the weather in Boston is currently Sunny with a temperature of 22 degrees Celsius so this is it so this is the output now of the system in a natural human language English for example this is all that we went through we have a human input natural language sentence you have your agent sends it to GPT for converts it here in a function call in Json this Json call is sent with our python code where I've written the function we have defined my agent that he has a request to better API and I get back from the database here my response in this format you want here this in a natural language in a sentence so you send it back again to open AI this is the request you have to pay for this request of course otherwise it would not be funny and then you get a response that you were looking for so this is the functionality of function calling a new thing with open AI very beautiful we have no length chain perfect we can do it now here directly in our code and the next time we're gonna talk about what we're going to talk about we're going to talk about multi-agents now we will code multi-agents and maybe we go a little bit further you know this Auto GPT or this baby ATI in this gorilla system and I will show you we want to get rid of this first generation and we will substitute all of this with multi-agent llms this is the Outlook this is the first video I hope you enjoyed it a little bit of code a little bit of explanation looking forward to see you in the next part
Info
Channel: code_your_own_AI
Views: 6,277
Rating: undefined out of 5
Keywords:
Id: _-ZsgPel8I4
Channel Id: undefined
Length: 29min 20sec (1760 seconds)
Published: Sat Jun 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.