How To Consume Azure OpenAI Model Programmatically Using Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in my previous videos I have shown you how to get started with Azure rupania and how to deploy a model so in this video we will see how we can consume the model which we have already deployed in azure so for that the very first thing we need to do is we need to go back to our Azure portal and open the resource which we just deployed so I'm not going through this part again because we have in how we can deploy it but if you are not sure how to deploy it I would recommend you to watch out my previous video in which I have clearly explained all these elements okay so this is the instance which we have deployed so let's click on explore so it will open up the Azure opens to AI Studio just give it few more seconds so this is our studio and on the left hand side you can see the chat and the completions so this is the portion which we will try it shortly we are going to try now and if you will go to deployments so this is the one which we deployed last time and today we are going to consume the same model using python okay let me go ahead and quickly type in something so write a python function to add two numbers okay and here we need to select some example so let me go ahead and choose this one I have to write it again right uh python function to add two numbers let me quickly execute this and you can see that it is giving this function successfully so how we can achieve the same result or similar kind of result using python so let me switch on to my vs code and the two things which I have imported is open AI as well as OS let's go ahead and initialize a few important variables the very first one is the deployment name so here we need to provide the deployment name then we need the kind of apis so for that we need to say open AI Dot API type so this will all will always be Azure in case of azure open AI then we need to provide our API key which I am going to read it from my environment so get EnV and let me quickly type in the name here the next thing we need is we need to provide the base URL our endpoint which we are going to hit so that we can do it using API base and here we will be providing that URL and the last version is the API version so this API version Dot API version so this version you can look into the documentation and you can figure it out but the current one which I am typing is 2022 hyphen 12 hyphen 0 1 so this is the latest one okay so first of all we need to grab the deployment name so deployment name would be this one so here we can provide deployment name then we need the API base which is nothing but our endpoint so let's go back to this portal and this is the end point so we need to place that end point here okay and in case of key if you are not aware I can show you from where I have picked it so go to keys and end points and this is the one any of these you can pick so this is the key you need to use okay so once this is done let me quickly execute this cell the only thing remaining is to make a call to the completion endpoint now that you can do it using web API or you can also do it using SDK so let's go ahead and do it using SDK because that is the one which is very popular way Okay so for that first of all we will Define the prompt and prompt we can grab the same one which we have written over there so let's go to this go to completions and grab this one so this would be my prompt next thing is we need to phrase how we are going to make a call so for that we will say result equal openai dot completion dot create so you must have seen this API earlier when we were doing with open AI so it is almost the same thing and then those few parameters if you want to Define you can define it temperature let's go with 0 then Max tokens I will go with bare minimum let's go with just 30 okay and then we need to define the engine so engine is nothing but our deployment name deployment name okay so this part is done and the only thing which is remaining is we need to print the result so for that we can say result dot choices of 0 so if you're not sure why I am writing choices.txt and all these so this is how the response format is okay let's run it and you can see that the response is exactly the same which we have received over there so this is how we can make a call to the models which we have already deployed in Azure open AI so in next video I will show you more advanced scenario but before going ahead you should know this particular basic things like how to grab deployment name how to grab the key which one would which one is your end point what is your API version so once these things are clear you are good to go with our next grid like complex scenarios so I hope you enjoyed watching this video and thanks for watching
Info
Channel: Shweta Lodha
Views: 9,177
Rating: undefined out of 5
Keywords: Artificial Intelligence, Programming, OpenAI, Machine learning, Shweta lodha, ChatGPT, What is embedding in OpenAI, How to save openai model, How to use langchain with pinecone and openai, How to get answer from PDF using ChatGPT OpenAI, How to query PDF using Langchain, Azure OpenAI, OpenAI vs Azure OpenAI, How to get started with Azure OpenAI, How to get access to Azure OpenAI, How to deploy OpenAI model is Azure
Id: UP743VnDUtU
Channel Id: undefined
Length: 7min 28sec (448 seconds)
Published: Tue May 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.