1 00:00:00,700 --> 00:00:05,950 Let s go ahead and talk about another core component of Langchain called prompt 2 00:00:05,960 --> 00:00:10,530 templates which are like recipes for generating prompts for LLMs. 3 00:00:11,540 --> 00:00:15,370 A prompt refers to the input to the model. 4 00:00:16,840 --> 00:00:18,910 Prompt templates are a way to create 5 00:00:18,920 --> 00:00:24,970 dynamic prompts for LLMs that are more flexible and easier to use than 6 00:00:24,980 --> 00:00:26,570 traditional static prompts. 7 00:00:27,440 --> 00:00:30,830 A prompt template takes a piece of text 8 00:00:30,840 --> 00:00:35,090 and injects a user s input into that piece of text. 9 00:00:36,560 --> 00:00:42,950 Note that in Langchain, there are prompt templates and chat prompt templates. 10 00:00:43,920 --> 00:00:49,830 Prompt templates are used for tasks that involve generating text such as answering 11 00:00:49,840 --> 00:00:55,770 questions or completing sentences, while chat prompt templates are specifically 12 00:00:55,780 --> 00:01:00,730 designed for tasks that involve engaging in conversations. 13 00:01:02,040 --> 00:01:07,830 Let s see how to create and use a prompt template that can be used with any type 14 00:01:07,840 --> 00:01:08,870 of LLM. 15 00:01:10,770 --> 00:01:16,650 From Langchain prompts import prompt 16 00:01:16,660 --> 00:01:28,940 template and from Langchain OpenAI, I am importing the ChatOpenAI class. 17 00:01:32,360 --> 00:01:37,390 Even though it was probably already imported in a cell above and it s not 18 00:01:37,400 --> 00:01:42,570 necessary here, I will import it again just in case you want to run only this 19 00:01:42,580 --> 00:01:46,430 cell and the ones below and not the entire notebook. 20 00:01:47,020 --> 00:01:51,030 I am creating a multiline string called template. 21 00:01:52,340 --> 00:01:55,790 This is similar to an F string and uses 22 00:01:55,800 --> 00:01:59,250 curly braces for the dynamic part of the template. 23 00:02:00,080 --> 00:02:05,140 You are an experienced virologist, write 24 00:02:05,150 --> 00:02:20,740 a few sentences about the following virus and the virus in curly braces in and the 25 00:02:20,750 --> 00:02:22,620 language in curly braces. 26 00:02:28,720 --> 00:02:31,850 Now let s define a prompt object of the 27 00:02:31,860 --> 00:02:33,070 class prompt template. 28 00:02:34,320 --> 00:02:39,080 Prompt template equals the prompt 29 00:02:39,090 --> 00:02:49,880 template class constructor from template of and the template equals template. 30 00:02:50,870 --> 00:02:56,720 This piece of code creates a new prompt template object from the provided 31 00:02:56,730 --> 00:02:58,000 template string. 32 00:03:00,310 --> 00:03:03,720 Next, we ll format the prompt template by 33 00:03:03,730 --> 00:03:10,880 replacing the placeholders virus and language in curly braces with the 34 00:03:10,890 --> 00:03:24,400 provided values prompt equals prompt -template .format and the arguments virus 35 00:03:24,410 --> 00:03:30,880 equals HIV and the language equals German. 36 00:03:31,930 --> 00:03:37,240 In this case, the value HIV is used to 37 00:03:37,250 --> 00:03:44,960 replace the placeholder virus and the value German is used to replace the 38 00:03:44,970 --> 00:03:46,460 placeholder language. 39 00:03:49,090 --> 00:03:52,200 This will result in the following prompt. 40 00:03:54,830 --> 00:04:01,540 You are an experienced virologist, write a few sentences about the following virus 41 00:04:01,550 --> 00:04:03,020 in German. 42 00:04:04,610 --> 00:04:09,280 I can write curly braces virus in double quotes. 43 00:04:14,740 --> 00:04:17,310 I am creating the LLM object. 44 00:04:17,960 --> 00:04:24,690 LLM equals chatOpenAi, modelName equals 45 00:04:24,700 --> 00:04:32,180 gpt3 .5 turbo and the temperature equals 0. 46 00:04:33,410 --> 00:04:37,720 Next, I will invoke the LLM with the 47 00:04:37,730 --> 00:04:46,260 prompt string as an argument output equals LLM .invoke of prompt. 48 00:04:51,220 --> 00:04:56,310 Finally, I am printing the response output .content. 49 00:05:00,120 --> 00:05:01,190 I am running it. 50 00:05:10,490 --> 00:05:13,920 Ok, gpt3 .5 turbo in single quotes. 51 00:05:19,580 --> 00:05:23,410 I ve got a short response about HIV in German. 52 00:05:24,340 --> 00:05:26,110 That s it with prompt templates. 53 00:05:26,320 --> 00:05:32,190 We ll take a break and in the next video, we ll go over the other type of prompt 54 00:05:32,200 --> 00:05:34,210 called chat prompt template.