Instructor: Hey, welcome, and in this video,
we're gonna have a look at how you can easily install
LangChain inside of your computer.
The first thing that you're gonna need to do
is install a couple of different packages.
We're gonna be installing pip install langchain.
We're also gonna install langchain_openai
and langchain-community.
The reason why you're gonna need to install langchain_openai
and langchain-community
is langchain_openai gives you the ability to easily operate
with the OpenAI API package inside of LangChain
and they've split out the different packages
into community packages.
So once you've installed all of these,
then the next thing you're gonna need to do
is make sure that the environment variable that you have
for your OpenAI API key is exposed
inside of your Google CoLab notebooks or your Python scripts
or wherever you're interfacing with OpenAI.
So there is one option where you can put it in
as an environment variable using the os package.
I wouldn't personally recommend that.
there are a couple of alternatives.
Python-dotenv is a Python package that you can install
and then what you can do is place a environment file,
so a dotenv file in the root of your directory,
and then put the OpenAI API key
key value inside of that dotenv.
And then at the top of your Python script,
you can load the from dotenv load_dotenv function.
So that's one approach.
The other approach, which I personally prefer,
is in your terminal on macOS or on Windows,
you can have different environment variables
that are exposed at the operating system level.
And you can do this with the export.
So for example, if I was to go
and load a new terminal
and then we go and type export
export OPENAI_API_KEY
and I type 123,
then what you'll see is when I dollar the OPENAI
and then we echo this,
you can see that we've now got this 123 exposed.
Now this won't actually carry across
between different terminal sessions,
which is why I would recommend adding this
to either the .bashrc file or the .zshrc file.
So I have a .zshrc file,
so I'm gonna do nano tilde forward slash .zshrc.
And you can see here I've only got Google Cloud SDK.
I do actually have other API keys on here,
but obviously for the sake of this video,
we've hidden those.
But what you could then do is do something like this
where you can export OPENAI_API_KEY
and then you would put in your secret project key here,
so that's Control + X + Y.
And then after that,
then you need to run the source command,
which will actually then reload those.
So now you'll see if I do echo OPENAI_API_KEY,
then it would have the right API key there.
So that is a way that you can basically make sure
that the OpenAI API key is accessible
regardless of what kind of code you're working on
as that's completely done
through your terminal shell session.
Now that you've done that, there is also the option
that I've commented out where you can manually enter
the OpenAI API key if you would prefer.
I definitely wouldn't recommend that method,
but you can do that if you want.
So once you've then done that
and you've run and installed the packages,
then you can do from langchain_openai.chat_models,
load the ChatOpenAI.
And then after that, then you can just .invoke that
and you can see we get back
that AI message with the content.
Okay, in the next video,
we'll dive a bit more into chat models.