now you can integrate AI into your application using Gro to API this is a complete bers tutorial so even if you haven't coded before you should be able to follow through so what is grock grock 2 is a AI model by X aai it's Elon Musk company and it's one of the best large language model and it is less restricted than Cloe and chat jpt and they have built one of the biggest AI superc computer and they are aiming to reach 200,000 gpus which means in few months or years of time Gro to is going to get upgraded and it's going to be powerful so how can we benefit from this it's a great alternative to chat gbt you can automate repetitive task you can make any application AI powered and you can add this AI to your business systems which can increase your business productivity you can create chat Bots with custom data and also you can make reliable AI agents so I'm going to take you the step by step how you can use this Gro to API and have a basic chat set up a streaming chat talk to image talk to image URL and then how you can use Lang chain with X AI Gro 2 I'm going to teach you how you can create a user interface for this as well which looks like this and you can ask give me a meal plan for me today and you can see the response that is super fast is quickly generating me the response and you're going to learn this but before that this video is sponsored by data Camp here you can learn data and AI skills online you can test your skills learn new skills apply to the real world problems and also you can practice I've been using this platform for a long time now and I completed many different courses from this platform this is very intuitive and here is an example course AI engineer for developers where you have subtopics such as working with open a API the interface is easy to use let's you can learn with interactive users elements you also have area to practice what You' learned also it will have test questions to test your knowledge after each session this will definitely improve your skill in regarding to learning about AI there is 50% off going on so I'll put the link in the description so click on that and you should be able to gain access to this platform First Step let's open our terminal in our computer it's like a blank screen just searching for terminal and there pip install open AI longchain X aai and chain lit open AI is the main package to integrate this API Lang chain X aai it's a package which simplifies the process of integrating this Gro to with many other application and chain lit is used for user interface so after typing like this click enter next export your X AI API key like this and then click enter this you can generate from console. x. a after this I'm going to create a file called app.py I'm going to open it you can open this of code editor of your choice for now I'm going to use vs code so inside the file from open AI import open AI then chat X aai from L chain import Bas 64 import OS now getting the X API key from the environment variable then defining open AI function this is where you define the base URL and the API key I'll provide all theod in the description below so you can just copy and paste it and use it so step number one creating a basic chat basic chat and client. chat. completions doc create function here I'm providing the model name that is grog Beta And as a system message I'm telling that you are Gro a helpful chatbot and here is the question from the user give me a meal plan for me today now after this I'm printing the response so that's all it is just this much amount of code and the basic chat bot is ready I can replace this with any question I want so now I'm going to run this code coming back to my terminal Python app.py and then click enter and here is the answer a meal plan for me today with breakfast midm morning snack lunch afternoon snack and dinner replace this with any other question and it will respond accordingly now step number two streaming chat so this response came after 20 seconds after everything is written but if it's streaming that means line by line that'll be much more user friendly so let's do that coming back to my code stream chat same as before I'm adding another parameter that is stream equals true and after that for Chunk in response and then looping like this that's it just stream equals true and looping code now I'm going to run this python app. p and then click enter and now you can see it's streaming response line by line it's coming out for the same question that is much more user friendly next talk to image coming back to the code chat with image providing the image path triangle.png then we need to encode the image using base 64 encode so base 64 is nothing but converting the image to letter and number format so here is the image which I'm feeding next encoding that image and then again same function chat completions create function and this time I'm adding image URL parameter and providing the base 64 image as a URL and I'm asking what's the area of the triangle now after that printing the response that's it so you can replace this triangle.png with any image so here's the triangle and we're going to find the area so now I'm going to run this code coming to my terminal Python app.py and then click enter and here is the answer it's able to identify the value of the side that is 9 units and six units and it calculated the area that is 27 that is super cool which means this AI is able to understand image and if you see the model name which I used I used Gro Vision beta so if you want only the text model that is Gro beta next talk to image URL coming back to my code so same as before using grock Vision beta and at this time instead of the URL I'm providing a full URL so if I open this URL here is the image the same triangle you can replace this URL with any image or of your choice and ask questions based on that now I'm going to print the response coming back to my terminal and running the code and even for this the value is 27 as expected and finally using L chain to run this the reason why L chain is a quick starter is because you can easily integrate this with many different application to make your work easy so coming back to the code chat using L chain so here I'm using chat X AI function which we have already initialized at the top from blank chain X aai so after this just giving the question here give me a meal plan for me today and just looping through it that's it only few lines of code now I'm going to run this and here is the streaming response is generating now finally creating a user interface which shows how you can integrate this API with any of your application for this I'm using chain lit so here is the chain lit code the basic setup is the same but I've got few settings which you can modify based on your requirement so the the key thing to note is that I'm using on message decorator so whenever I type a message in the chat interface it'll automatically be passed in this message history and streaming is true and finally the message will get returned a slight modification of the code now I'm going to run this in your terminal chain lit run U.P that's where I've saved my code and then click enter now you can see the application is running in this URL so I'm going to open this URL and I am inside the URL now and I'm going to ask give me a meal plan for me today and the response is super quick as you can see here on my screen I'm really excited about this considering this is one of the top model and you can easily integrate this with your own application to increase your productivity to automate to save time and to save energy considering you already like integrating AI within your application I've also created another video which I'll will put that link here and I highly recommend for you to watch for beginners and I will see you there