back to indexAzure OpenAI in LangChain: Getting Started
Chapters
0:0 Azure OpenAI in LangChain
0:27 OpenAI in Azure Portal
3:54 Creating Deployments in Azure OpenAI Studio
5:17 Connecting LangChain with AzureChatOpenAI
00:00:00.000 |
Today we're going to take a look at how we can use Lang chain with OpenAI in Azure. 00:00:06.680 |
Now for those of you that don't know OpenAI can be accessed in one of two ways either 00:00:12.680 |
through the OpenAI API directly or via the Azure version of OpenAI's API. 00:00:20.280 |
Now I'm going to show you how to do all of this within Lang chain so we can have Lang 00:00:27.140 |
So the first thing that we're going to do is head on over to portal.azure.com. 00:00:33.880 |
You will naturally need an Azure account if you don't already but once you have set that 00:00:39.680 |
up all you're going to do is head on over to your subscriptions, make sure you have 00:00:43.920 |
a subscription, you may need to create one so you add a subscription there. 00:00:48.200 |
Mine is called development and testing so okay I know that is there. 00:00:56.980 |
If you can't find any of this stuff you can actually just go up here and type it in. 00:01:06.500 |
You may also need to create that resource but once you have it, Azure OpenAI, you come 00:01:10.380 |
over here and we already have a deployment down here but what I'm going to do is create 00:01:24.940 |
I'm going to use that subscription that I showed you earlier. 00:01:27.880 |
I'm going to use a resource group so you may also need to create a resource group. 00:01:33.200 |
You can click create new if you don't have one already and I'm going to go to instant 00:01:45.740 |
Pricing tier, a standard S0 and we can go on to next. 00:01:52.620 |
Now here you just set up your security, network security items. 00:01:58.100 |
For me I'm just going to go with all networks. 00:02:01.500 |
Tags so this is naturally if you have many people and categories on your Azure instance 00:02:12.540 |
Okay and once you've done that you have the terms you just go down to create. 00:02:17.340 |
You will have to wait a moment while that is deploying and once it has deployed you'll 00:02:26.180 |
From here we want to go to I'm not sure the best way but I'm going to go to home. 00:02:30.860 |
I'm going to go back to Azure OpenAI and you'll be able to see your new resource or deployment 00:02:37.140 |
So I'm going to click on that deployment and there's now a few things that we need to grab 00:02:47.260 |
I'm going to go to this notebook so you'll be able to find your own version of this notebook 00:02:52.160 |
linked near the top of the video right now or if not in the video description. 00:02:57.700 |
So I'm going to come down to here and you see that we have this OpenAI API base right 00:03:06.900 |
So I'm going to replace that with what I just pasted from the endpoint. 00:03:12.020 |
So YouTube demo openaiazure.com I also need the OpenAI API version. 00:03:18.580 |
Right now the one of the most up-to-date versions or the version I'm using at least is this 00:03:25.980 |
so there might be more recent versions but that's it works right now so I'm using that. 00:03:32.980 |
We want to set the OpenAI API type which is Azure and we also want to set the OpenAI API 00:03:41.060 |
Right so where do we get that we want to come over to keys and endpoint and we just copy 00:03:54.640 |
So once we have our items there what we now need to do is we want to go to Azure OpenAI 00:04:02.300 |
Open that and this is one of the main differences between the default version of OpenAI and 00:04:09.220 |
the Azure version of OpenAI with Azure or actually with the default version we would 00:04:15.460 |
just call the model endpoints we would say okay we want to use GPT-4 and we do that. 00:04:21.660 |
You can't do that with the Azure version you actually need to create a deployment for every 00:04:29.620 |
So you'd come over to create new deployment and you see I currently have no deployments 00:04:35.740 |
okay so I'm going to create a new one I'm going to choose a model so we have a few here 00:04:43.300 |
let's go with a GPT-4 model version we can let's use the default and deployment name 00:04:52.140 |
so this is the deployment name that you will use within line chain to connect to this deployment 00:05:00.460 |
right so it needs to be unique I don't currently have any other deployments so I can call it 00:05:05.420 |
whatever I want essentially so I'm going to call it chat endpoint okay I'm going to create 00:05:12.300 |
that okay so I now have chat endpoint so I'm going to come over to the code again I'm just 00:05:19.300 |
going to run the pip install up at the top here and then I'm going to come down to here 00:05:25.480 |
so I have deployment name I need to change this because I called it chat endpoint so 00:05:33.140 |
we have the chat endpoint as our deployment name we have our model name which aligns to 00:05:39.000 |
our deployment over here now if we try to run this straight away we'll get an error 00:05:48.420 |
it won't work so after waiting a little while it will work as we can see here so for this 00:05:55.580 |
it took sort of three to four minutes for that to actually deploy now what we've done 00:06:01.660 |
here is we're using a chat model so when we're using chat model we use line chains system 00:06:08.500 |
messages human message and AI message to create that sort of chat log so we initialize it 00:06:14.360 |
with the system message then we basically system message just tells the model how to 00:06:20.180 |
behave okay so I'm saying that it's basically it's an AGI but it cannot answer any questions 00:06:26.700 |
about cheese because it just doesn't understand cheese as a concept okay so we can ask it 00:06:32.820 |
like hey how are you doing today what's the meaning of life and it's going to respond 00:06:37.660 |
you know it's really typical like as an AI I don't have emotions or personal experiences 00:06:42.220 |
so on and so on but I'm here to help and then it gives you kind of generic meaning of life 00:06:48.180 |
answer okay cool so after that we want to take this message the AI message and append 00:06:56.860 |
it to our messages okay and then we can feed that back into the model so I'm gonna take 00:07:03.620 |
all those interactions so far and I'm gonna ask another question can you give me one concrete 00:07:07.100 |
example one of these interpretations so interpretations that's a very I'm not specifying what exactly 00:07:14.100 |
I want to know about in that query in order for that to work it has to rely on the previous 00:07:19.500 |
messages so it's going to need to take a look at this but because it's a chat model and 00:07:23.900 |
because we appended the response to those messages it will understand that we're asking 00:07:29.480 |
about the interpretation of something around here so we're saying what are the interpretations 00:07:36.100 |
of the sort of meaning of life that people have been debating for centuries okay so in 00:07:44.060 |
order to answer that it needs to have some of that conversational history which it does 00:07:50.420 |
so we ask that question okay and we get this so one concrete example of an interpretation 00:07:57.180 |
meaning life is found within the philosophy of existentialism and yeah it's like it's 00:08:04.140 |
a pretty good kind of like meaningful answer I think so that's great it's working as an 00:08:11.000 |
expert AGI now just to confirm that it is still considering its system message that 00:08:17.140 |
we initially set it up with we can say okay something really simple what is the color 00:08:21.540 |
of cheese so we can ask that and it says as an AGI system I am unable to provide any information 00:08:28.140 |
related to cheese I apologize for the inconvenience and so on and so on right so it's considering 00:08:34.340 |
all those previous messages so everything seems to be working and we have rather than 00:08:39.420 |
use the typical OpenAI API endpoints we're doing this through Azure's like OpenAI offering 00:08:47.940 |
so everything seems to be working that looks good and that is exactly what I wanted to 00:08:53.820 |
show you in this video so that is it for now I hope this has been useful and interesting 00:09:01.820 |
so thank you very much for watching and I will see you again in the next one. Bye.