AutoGen function calling - A more reliable Solution

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
by providing autogen with our custom functions we could make autogen more reliable and gain control over some parts of the execution process the arguments used for the function call and the result of the function call are marked Green in the terminal making it easy for us to test and debug it later using function calls brings more consistency to autogen as the agents use each time are well tested Solutions instead of trying to find new ways so let's see how we can use this important feature in our apps we create a new folder for our project and switch to the new folder from within the folder we start Visual Studio code first we create a requirements.txt file and paste a list of packages required for our project next we create a virtual environment and activate the virtual environment when activated the name of the virtual environment appears before the prompt in our case VN now we can install our packages using Pip this takes some time and after all of the packages are installed the prompt comes back and we can clear the screen close the terminal and close the requirements.txt file the next step is to add the oi config list here we can list our models and the keys you can have multiple models listed here even local open-source models which we will cover in the upcoming tutorials now that the preparation is finished we create our app.py file file in the first part of this tutorial we use autogen without a function call we use a simple combination of the user proxy agent and an assistant agent first we import the agents from autogen next we load the configuration of OI config list to config list now it's time to create our assistant agent we name it assistant and provide assistant message we ask it not to show any appreciation otherwise the agents go in an infinite Loop of thaning each other to prevent this We additionally set the request time out to 60 seconds after the assistant is defined we create our user proxy agent here we give it the name user proxy and Define coding as working directory if in the conversation process some code gets generated it goes into this directory we use a Lambda function to check if the content ends with terminate and use it as is terminate message always is the default value for human input mode but we added it here for clarity with alwayss we need to confirm the steps in the conversation later if you want to automate the process we can set it to never finally we initiate the chat between the user proxy agent and the assistant with the prompt what is the latest price of Apple now we can test the script and run it in the terminal so the conversation starts and as expected the assistant has no access to the realtime data and informs the user proxy agent about it as the human input mode is set to always we need to provide our feedback we let them know that they should use Yahoo finance to get the data and we already installed the library this saves us time and cost as otherwise it may suggest other libraries to get the same result when we go further we get some solution ions to get the data and we hit enter to confirm the conversation goes back and forth till a solution is found and we get finally the answer we wanted and the latest closing price of Apple sometimes this conversation goes in an infinite Loop and we have to terminate the execution so we need a more reliable solution and here comes the aogen function call which brings us to the second part of this tutorial the first step is to create a function we create a new file to implement our own function we import Yahoo finance and Define the function get stock price to get a ticker and return the latest closing price of the stock as we will import this file into our app we check if the file is executed directly or is just import Ed if the file is executed directly it will test the function and print the result to test it we execute this file directly and sure enough we see the latest price of Apple this shows that our function works as intended and we can use it in our autogen app going back to our app.py we import the function the next step is to list all of the functions that our agents can use in our case our list has just one function feel free to expand this list on your own we covered this subject in multiple tutorials on this channel here just a recap we give our function and name like get stuck price then we use a description this description helps the agents and llm in our case open AI when to use this function addition Ally we Define the parameters used by this function in this case it's only thicker and thicker is required next we need to pass the list of our functions to the llm config of our assistant the next step is to map the description of the function to a real python function in our user proxy with that said we are ready to test our app and use the autogen function call but before that there is one change we should make in the oi config file here we do not need the GPT 4 anymore and we can use the more cost efficient GPT 3.5 turbo 0613 which is optimized for function calling back to our app we open the terminal and run the app this this time we do not need to waste time and cost on finding a solution to get the latest price of Apple instead we see the suggested function called to get stock price with ticker AAP for Apple in green as the human input mode is still on always we need to confirm the autogen function call and sure enough the response of the function call comes back and we see the result in Green in the conversation this is much better solution than the first part of this tutorial to wrap it up you can use autogen in many patterns to give you some inspiration on how to solve a problem but once you have find the solution it's much better to create your own custom tools and functions you can even provide autogen with Lang chain tools but this is the subject of coming tutorials if you like the content of this tutorial make sure to hit the like button and subscribe to the channel to see more contents of this kind good luck
Info
Channel: business24_ai
Views: 3,601
Rating: undefined out of 5
Keywords: autogen, autogen tutorial, autogen function calling, function calling, OpenAI, artificial intelligence, ai, chatgpt
Id: dCBXFjjOD5c
Channel Id: undefined
Length: 8min 41sec (521 seconds)
Published: Mon Nov 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.