1 00:00:00,700 --> 00:00:07,130 In the previous lecture, you learned what Langchain is, what needs it fills, and 2 00:00:07,140 --> 00:00:07,890 its components. 3 00:00:08,520 --> 00:00:10,090 Let's dive into coding. 4 00:00:10,940 --> 00:00:14,650 We'll write the code in Jupyter Notebook or Google Colab. 5 00:00:15,280 --> 00:00:20,730 I showed you how to install them in the first course of the series OpenAI API 6 00:00:20,740 --> 00:00:21,830 with Python. 7 00:00:22,680 --> 00:00:25,070 In this video, we'll set up the 8 00:00:25,080 --> 00:00:30,910 environment, we'll install the required libraries, and set up the API keys using 9 00:00:30,920 --> 00:00:32,070 Python .env. 10 00:00:32,820 --> 00:00:35,650 We can install the libraries using pip 11 00:00:35,660 --> 00:00:41,190 install and the name of the libraries like we've done so many times or we could 12 00:00:41,200 --> 00:00:48,370 write the name of the libraries in a text file called requirements .txt and then 13 00:00:48,380 --> 00:00:51,490 run pip install -r requirements .txt. 14 00:00:51,500 --> 00:00:56,440 I am creating a text file called 15 00:00:56,450 --> 00:01:00,060 requirements .txt in the current directory. 16 00:01:04,830 --> 00:01:07,480 I am adding to the file the necessary 17 00:01:07,490 --> 00:01:15,720 libraries OpenAI, Langchain, Pinecone Client, Python .env, and TicToken. 18 00:01:15,730 --> 00:01:18,140 We'll use them all later in this course. 19 00:01:19,170 --> 00:01:22,060 I am pasting a few more libraries that 20 00:01:22,070 --> 00:01:24,580 will be necessary in the projects section. 21 00:01:25,470 --> 00:01:28,760 You will find the requirements .txt file 22 00:01:28,770 --> 00:01:29,920 in the resources. 23 00:01:31,090 --> 00:01:32,020 I am saving it. 24 00:01:37,120 --> 00:01:44,530 Now, in the terminal or in a Jupyter notebook cell, run pip install -r 25 00:01:44,540 --> 00:01:51,930 requirements .txt and the dash q from quiet. 26 00:01:53,690 --> 00:01:57,080 It is installing the libraries specified 27 00:01:57,090 --> 00:01:59,640 in requirements .txt. 28 00:02:00,710 --> 00:02:01,840 It is done. 29 00:02:02,490 --> 00:02:07,440 To check the version of a library, run pip show and the name of the library. 30 00:02:07,950 --> 00:02:09,700 pip show Langchain. 31 00:02:11,150 --> 00:02:11,900 And I am running the cell. 32 00:02:14,500 --> 00:02:16,530 Or pip show OpenAI. 33 00:02:17,220 --> 00:02:20,870 We are using the latest versions of these libraries. 34 00:02:22,100 --> 00:02:23,270 Very well. 35 00:02:24,420 --> 00:02:27,870 Let's talk about Python .env we've just installed. 36 00:02:33,750 --> 00:02:39,440 Python .env is a Python module that allows you to specify environment 37 00:02:39,450 --> 00:02:45,880 variables as key value pairs in a .env file within your Python project directory. 38 00:02:46,550 --> 00:02:53,140 It is a convenient and secure way to load and use environment variables in your application. 39 00:02:54,210 --> 00:02:58,600 You will find Python .env used in many Python applications. 40 00:02:59,270 --> 00:03:04,880 We can have more than one API key and will save them all in .env. 41 00:03:05,270 --> 00:03:10,380 We will have an API key for OpenAI, another one for Pinecone, a key for 42 00:03:10,390 --> 00:03:13,460 Google's Gemini, Hugging Face and so on. 43 00:03:14,430 --> 00:03:17,600 Let's suppose we've already created an 44 00:03:17,610 --> 00:03:20,800 OpenAI account and generated an API key. 45 00:03:21,510 --> 00:03:27,620 If not, go to platform .openai .com and 46 00:03:27,630 --> 00:03:29,320 sign up for a new account. 47 00:03:33,110 --> 00:03:34,260 Then login. 48 00:03:34,670 --> 00:03:43,320 Once logged in, click the OpenAI logo in the left upper corner and the API keys. 49 00:03:46,030 --> 00:03:51,220 Here you can generate a new API key or invalidate an existing one. 50 00:03:52,990 --> 00:03:54,780 I am creating a new key. 51 00:03:57,620 --> 00:04:00,090 This key will have all the permissions 52 00:04:00,100 --> 00:04:02,650 but you can restrict some of them. 53 00:04:08,840 --> 00:04:12,170 I am creating the key and copying it to Clipboard. 54 00:04:14,530 --> 00:04:20,500 Using a text editor, I am creating a new text file in the projects directory. 55 00:04:23,790 --> 00:04:34,680 In the file, I am adding OpenAI API key in capitals, equals and the key in double quotes. 56 00:04:38,630 --> 00:04:42,120 Next, I am saving the file as .env. 57 00:04:49,220 --> 00:04:51,430 I am removing the new text document. 58 00:04:52,260 --> 00:04:56,570 This is the .env file that contains the OpenAI API key. 59 00:04:57,540 --> 00:04:59,590 Here, I would have one remark. 60 00:05:00,040 --> 00:05:03,930 On Linux and MacOS, the file names that 61 00:05:03,940 --> 00:05:09,390 start with a dot are hidden and are not displayed by default in the file explorer. 62 00:05:10,120 --> 00:05:13,690 Go to settings and select to see them as well. 63 00:05:14,840 --> 00:05:18,070 Let's load the environment variables. 64 00:05:18,340 --> 00:05:31,190 I am importing OS and from .env, I am importing load .env and find .env. 65 00:05:32,340 --> 00:05:39,750 I am calling load .env to load the variables found in .env. 66 00:05:40,460 --> 00:05:46,990 I can give the path to .env as an argument or I can call find .env. 67 00:05:49,380 --> 00:05:53,350 Find .env tries to find the .env file. 68 00:05:54,080 --> 00:06:00,580 I am adding override equals true which is 69 00:06:00,590 --> 00:06:05,500 necessary to override the value of the variable if you change it in .env. 70 00:06:06,910 --> 00:06:14,420 Note that find .env retries a path to the file if found or an empty string 71 00:06:14,430 --> 00:06:16,680 otherwise and that's it. 72 00:06:17,550 --> 00:06:20,360 Now, the environment variables are loaded 73 00:06:20,370 --> 00:06:21,800 and I can use them. 74 00:06:23,030 --> 00:06:25,640 To get the value of an environment 75 00:06:25,650 --> 00:06:32,660 variable use os .env .get and the name of the variable. 76 00:06:33,890 --> 00:06:35,580 OpenAI API key. 77 00:06:38,230 --> 00:06:40,780 We've successfully set up the environment. 78 00:06:44,590 --> 00:06:50,020 In this video, we installed the necessary libraries, obtained the API key for 79 00:06:50,030 --> 00:06:54,800 OpenAI and loaded it as an environment variable in our application. 80 00:06:55,370 --> 00:06:56,380 We'll pause here briefly. 81 00:06:56,930 --> 00:06:59,680 In the next video, we'll explore language 82 00:06:59,690 --> 00:07:04,480 components and demonstrate how to invoke various AI models.