Build An Audio AI App Transcripts
Chapter: Feature 3: Summarize
Lecture: Creating the Prompt

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now with the podcast and the episode details, we're able to write our prompt. So let's go over here and I'll write it in sort of a naive way,
0:08 then we'll make it a little more useful. So prompt, remember, we don't want to just say, Please summarize this. We saw how bad that did.
0:22 Remember, the man got stuck and the mayor pulled him out. No, let's go a little bit more detailed here. You are an expert journalist.
0:34 I need you to read the transcript and summarize it for me. You know, by the way, just hitting enter here in the middle of the string,
0:44 PyCharm will wrap it in parentheses so you don't have to do line continuations and carry it on and so on.
0:51 Use the style of a tech reporter at Ars Technica. Great online resource. This comes from the podcast. Let's convert that to single quotes real quick
1:07 so I can put double quotes into our prompt, podcast.title. And it focuses on the subtitle here, period.
1:16 It's really important that all these lines have spaces on the end because this really just becomes one single string.
1:25 This is like having string concatenation in Python. So if you don't have the spaces, things are going to get weird. All right, the title is this.
1:35 And finally, so all of this is setting the stage, right? You're an expert. I need you to read it and summarize it.
1:43 You use the style of typical reporters at Ars Technica. Here's the podcast information. Here's the subtitle, the episode.
1:51 I realize something happened with its F string. Now comes the actual details of how we want the command. So we'll say, ""Your response.
2:02 Your response should be a TLR, TLDR summary of around five to eight sentences. Excellent. So this is the prompt that we want to send over to Lemur.
2:11 There are two little details here. We want to have another response where it's, you know, ""Key moments. Key moments.
2:21 And the only difference between this one and the key moments is this final string here. So let's get rid of this here.
2:31 And we're going to take this and make it its own little variable. So we'll say, ""Extract a variable.
2:36 Or we'll just cut it out and put it here because somehow that's hard. Let's call this ""Prompt base"" because this is going to be reused here.
2:45 So we'll say, ""Prompt base plus this bit of text. Like that. It says, ""You don't need an F string. And you know what? They are right.
2:59 They are in fact right. So this is the prompt because later we'll call this, let's call this ""Summary prompt.
3:06 And then we'll have the, actually, how about ""TLDR prompt"" and the ""Moments prompt. Your response should be,"" for the moments we'll say,
3:20 Your response should be in the form of 10 bullet points. So we're going to pass these two strings on.
3:26 The other little weird edge case here is that, I've said this before, but if you go and actually look at how we're parsing all these RSS feeds,
3:35 RSS feeds are a standard. There are places you can go and say, Does this RSS feed for a podcast match the expected standard or no?
3:45 And yet, somehow, even major places like NPR, SHIP, invalid or missing or somehow messed up RSS feeds.
3:56 So, for example, sometimes there's a subtitle, sometimes there's not. Sometimes there's an image with a URL.
4:02 Other times there's some complex XML representation of that. Anyway, what is all that about? That means this may not have a subtitle.
4:11 And if it doesn't have a subtitle, the prompt's going to look like, And it focuses on double quote. That's going to mess things up. That's not good.
4:19 So let's change this in two ways. Let's make sure that this can be-- put this space over here, even though it's going to make it look a little weird
4:27 because we want this to end right there. I guess we can put it in what we're going to generate.
4:32 But what we need to do is make this some sort of expression right here. So let's take this out and say, ""Subtitle text.
4:41 It equals this, but it only equals this if podcast.subtitle. Else, what is it going to be? A period. It's going to put--
4:52 again, that's where we want to make sure this goes like this. So put the period right there on the end, or put a space in that word, and then--
5:04 we need a space right there and right there. We need a space right there and right there. Again, make sure these don't get mushed together.
5:12 And the mistake or the warning here is saying you can't just put two variables together, so we've got to use the plus symbol on this particular one.
5:21 All right. That's a lot of work, right, to form up this thing. But we're ready to send this off to Lemur. Everything is just fine.
5:29 Let's just do, really quick, print TLDR moment prompt and the moments prompt, just as a way of making sure things work.
5:39 All right. Let's go check it out. Let's go over here and discover. Let's go pick on fresh air. Okay.
5:48 We can do this best of Emma Stone and the birthplace of-- whatever that is, psychedelic something. So remember the way this is going to work.
5:58 Let's clear--there we go. We're going to try to get the summary of this. And because the transcript doesn't exist, we should go ahead and create it.
6:07 We just won't create the summary, so let's test that behavior. So look, it's kicking it off. It says no--awesome--no transcript yet.
6:14 Let's make one for fresh air. And then you can see we're transcribing this. It's running, it's running.
6:20 Oh, and we're searching while it's happening as well. So hang tight. This is a pretty short episode. It should come back quickly.
6:26 Hey, hey, look at that. Summary is ready. That's not technically true because, remember, we haven't actually created the summary still,
6:35 but we should see that down here we have a transcript. All right. So it looks like everything is hanging together so far,
6:42 and more importantly, the reason we did that is we wanted to see what the prompt looked like. No searching right now, please.
6:49 All right. You are an expert journalist. I need you to read the transcript and summarize it for me. Use the style of a tech reporter.
6:57 This comes from a podcast entitled ""Fresh Air. The title of the episode is ""Best of Emma Stone and the Birth of Psychedelic Science.
7:05 Notice right here this period. That comes--well, the period in space. That's because ""Fresh Air"" doesn't have a subtitle
7:13 or any form of subdescription for their podcast, at least not the way we parsed it. Your response should be a TLDR summary of around 5 to 8 sentences.
7:24 And, again, same thing down to here, and now it should be in the form of 10 bullet points. Excellent. It looks like our prompt is ready to roll.


Talk Python's Mastodon Michael Kennedy's Mastodon