WEBVTT

00:00.000 --> 00:01.320
Instructor: Hey, welcome, and in this video,

00:01.320 --> 00:03.420
we're gonna have a look at how you can easily install

00:03.420 --> 00:05.700
LangChain inside of your computer.

00:05.700 --> 00:06.990
The first thing that you're gonna need to do

00:06.990 --> 00:09.120
is install a couple of different packages.

00:09.120 --> 00:11.820
We're gonna be installing pip install langchain.

00:11.820 --> 00:14.460
We're also gonna install langchain_openai

00:14.460 --> 00:16.200
and langchain-community.

00:16.200 --> 00:19.504
The reason why you're gonna need to install langchain_openai

00:19.504 --> 00:20.790
and langchain-community

00:20.790 --> 00:24.360
is langchain_openai gives you the ability to easily operate

00:24.360 --> 00:27.930
with the OpenAI API package inside of LangChain

00:27.930 --> 00:30.570
and they've split out the different packages

00:30.570 --> 00:32.100
into community packages.

00:32.100 --> 00:33.840
So once you've installed all of these,

00:33.840 --> 00:35.640
then the next thing you're gonna need to do

00:35.640 --> 00:38.490
is make sure that the environment variable that you have

00:38.490 --> 00:41.340
for your OpenAI API key is exposed

00:41.340 --> 00:43.950
inside of your Google CoLab notebooks or your Python scripts

00:43.950 --> 00:47.130
or wherever you're interfacing with OpenAI.

00:47.130 --> 00:49.770
So there is one option where you can put it in

00:49.770 --> 00:52.740
as an environment variable using the os package.

00:52.740 --> 00:54.690
I wouldn't personally recommend that.

00:54.690 --> 00:56.400
there are a couple of alternatives.

00:56.400 --> 01:00.510
Python-dotenv is a Python package that you can install

01:00.510 --> 01:03.780
and then what you can do is place a environment file,

01:03.780 --> 01:06.960
so a dotenv file in the root of your directory,

01:06.960 --> 01:09.960
and then put the OpenAI API key

01:09.960 --> 01:12.420
key value inside of that dotenv.

01:12.420 --> 01:14.010
And then at the top of your Python script,

01:14.010 --> 01:18.840
you can load the from dotenv load_dotenv function.

01:18.840 --> 01:20.370
So that's one approach.

01:20.370 --> 01:22.590
The other approach, which I personally prefer,

01:22.590 --> 01:26.490
is in your terminal on macOS or on Windows,

01:26.490 --> 01:28.560
you can have different environment variables

01:28.560 --> 01:30.960
that are exposed at the operating system level.

01:30.960 --> 01:32.880
And you can do this with the export.

01:32.880 --> 01:34.815
So for example, if I was to go

01:34.815 --> 01:37.350
and load a new terminal

01:37.350 --> 01:39.640
and then we go and type export

01:41.280 --> 01:43.710
export OPENAI_API_KEY

01:43.710 --> 01:45.360
and I type 123,

01:45.360 --> 01:48.900
then what you'll see is when I dollar the OPENAI

01:48.900 --> 01:50.430
and then we echo this,

01:50.430 --> 01:53.250
you can see that we've now got this 123 exposed.

01:53.250 --> 01:55.290
Now this won't actually carry across

01:55.290 --> 01:57.000
between different terminal sessions,

01:57.000 --> 01:58.980
which is why I would recommend adding this

01:58.980 --> 02:03.780
to either the .bashrc file or the .zshrc file.

02:03.780 --> 02:06.360
So I have a .zshrc file,

02:06.360 --> 02:11.360
so I'm gonna do nano tilde forward slash .zshrc.

02:11.820 --> 02:14.970
And you can see here I've only got Google Cloud SDK.

02:14.970 --> 02:16.890
I do actually have other API keys on here,

02:16.890 --> 02:18.720
but obviously for the sake of this video,

02:18.720 --> 02:19.770
we've hidden those.

02:19.770 --> 02:21.870
But what you could then do is do something like this

02:21.870 --> 02:23.920
where you can export OPENAI_API_KEY

02:26.460 --> 02:30.063
and then you would put in your secret project key here,

02:31.830 --> 02:34.740
so that's Control + X + Y.

02:34.740 --> 02:35.700
And then after that,

02:35.700 --> 02:38.130
then you need to run the source command,

02:38.130 --> 02:40.560
which will actually then reload those.

02:40.560 --> 02:44.010
So now you'll see if I do echo OPENAI_API_KEY,

02:44.010 --> 02:46.320
then it would have the right API key there.

02:46.320 --> 02:49.350
So that is a way that you can basically make sure

02:49.350 --> 02:52.170
that the OpenAI API key is accessible

02:52.170 --> 02:54.540
regardless of what kind of code you're working on

02:54.540 --> 02:56.850
as that's completely done

02:56.850 --> 02:58.890
through your terminal shell session.

02:58.890 --> 03:00.780
Now that you've done that, there is also the option

03:00.780 --> 03:03.720
that I've commented out where you can manually enter

03:03.720 --> 03:06.420
the OpenAI API key if you would prefer.

03:06.420 --> 03:08.550
I definitely wouldn't recommend that method,

03:08.550 --> 03:10.110
but you can do that if you want.

03:10.110 --> 03:11.820
So once you've then done that

03:11.820 --> 03:13.410
and you've run and installed the packages,

03:13.410 --> 03:16.530
then you can do from langchain_openai.chat_models,

03:16.530 --> 03:18.150
load the ChatOpenAI.

03:18.150 --> 03:20.730
And then after that, then you can just .invoke that

03:20.730 --> 03:21.750
and you can see we get back

03:21.750 --> 03:23.520
that AI message with the content.

03:23.520 --> 03:24.480
Okay, in the next video,

03:24.480 --> 03:26.763
we'll dive a bit more into chat models.
