Reaching for the Stars

Tom Chant
InstructorTom Chant
Share this video with your friends

Social Share Links

Send Tweet
Published 9 months ago
Updated 9 months ago

The focus of this lesson is on text extraction using OpenAI to enhance a movie synopsis. Tom demonstrates how to include actors' names in brackets after each character in the synopsis and even suggests using OpenAI to generate actors that would be ideal for the role.

The challenge is to extract the names from the synopsis using OpenAI. The instructor provides guidance and prompts to guide learners through the process. The extracted names are then displayed alongside the synopsis.

You'll learn about generating images with OpenAI in the next step. Overall, this lesson highlights the flexibility and power of OpenAI in enhancing content by dynamically extracting and generating text to create more compelling and visually appealing outputs.

[00:00] In our finished product, we're going to have a star-studded cast, so movie industry insiders can better visualize our story. And this is going to give us a great chance to look at text extraction using OpenAI.

[00:13] If we have a look at our Fetch Synopsis prompt, in this example, we have actually got the actors' names in brackets after each character. But we're not always seeing that in the output. In this screenshot we are, we've got Jeff Bridges and Emily Blunt.

[00:29] But in this screenshot, we're actually not getting that at all. We've got the characters, but no names for suggested actors. Now that's probably being a bit inconsistent because we're not specifically asking for it. Although we've got it in the example, we haven't got it in the instruction.

[00:46] So here's a very quick mini challenge for you. Ask for actors' names in brackets after each character. And I've just put here, you could also suggest that OpenAI thinks of actors that would particularly suit the role. Okay, pause now and quickly sort out that challenge.

[01:09] Okay, hopefully you got that to work just fine. I'm just going to add a sentence onto the end of the instruction. The synopsis should include actors' names in brackets after each character. Choose actors that would be ideal for the role. Okay, let's save that and see if it's worked.

[01:26] So I'll put an idea in here and we'll press send. And there we are, we've got our synopsis and we can indeed see that we're getting the actors' names in brackets after each character. Now I've tested this and it is very consistent.

[01:42] Okay, the next thing that we need then is a function so we can extract the stars' names from this text. So they can be listed out right here, just above our synopsis. You could do that with vanilla JavaScript, but it's actually going to be easier to let OpenAI do that for us.

[02:00] So I'm going to come down here then and after we've generated the synopsis, at the same time as we ask for the title, I'm going to call another function called FetchStars. And of course, we'll pass in the synopsis. Now I'll come down here and because you've done this lots and lots of times,

[02:19] I'm going to do all of the heavy lifting here and set up that function minus the prompt. Now we should set some max tokens here. I think we don't need very many, 30 will be more than enough. And I'm not actually going to set a temperature here. I've tested this and it really doesn't make much difference at all.

[02:37] So we might as well leave it at its default. Now we can see on the screenshot that we want the stars right here. Let's just check the HTML and we've got this H2 element with the ID of output-stars. So that is where we're going to render our stars.

[02:55] And of course, this function needs a parameter. Okay, now it's time for a challenge and I'm going to paste it in right here just above the prompt. I want you to use OpenAI to extract the names in brackets from our synopsis.

[03:10] Now I've left that challenge wide open because I think we've done enough prompt engineering by now for you to be able to figure out how to do this. If you feel ready for that, pause now, go ahead, get it sorted. It's always best to try and figure things out on your own as much as possible.

[03:26] But if you'd like a few more pointers or if you've tried it and you've got stuck, I have put a hint file up here. It's called hint.md and it's just got a couple of pointers that will push you in the right direction. Okay, pause now, get this challenge sorted, do some experimentation, take all the time you need

[03:43] and I'll see you back here when you've got it working and we'll have a look together. Okay, hopefully you got that working just fine. So I'm going to come in here and I'm going to start off with a simple instruction. Extract the names in brackets from the synopsis.

[04:05] That should do the trick because OpenAI is more than capable of recognizing names and brackets. But what I do want to do though is add an example. So I'm going to come down here onto a new line and I'll use a divider so that will be the triple hashtag.

[04:22] And now I'm actually going to take the example that we've got up here. It's this Top Gun one. So we can borrow all of that and I'll just paste it in here. Now we've got all of the names in brackets. So let's just show OpenAI what it is we're looking for.

[04:38] So I'll say names and then a colon and then I'll just list out all of the names from the brackets. So Tom Cruise, Val Kilmer and Kelly McGillis. And if we have a look back at the slide, we're actually getting a comma separated list here and that is actually what we want.

[04:55] So those commas are there for a reason. Now let's come on to a new line again and I'll use a divider. And now let's just put synopsis colon. And this is where we want to pass it the synopsis that we're bringing in right here. And then underneath that, names.

[05:13] And we'll leave that blank because that is where OpenAI is going to do its thing. Okay, let's hit save and we'll see if it's working. I'll paste an idea in and hit send. And let's check out our results. So we've got a title and there we are.

[05:29] We have got our stars, Al Pacino, Kevin Hart and Dwayne Johnson. What a lineup. That I think will just be a really, really cool film. And we've also got a decent synopsis. Now the final thing that we need to finish this app off is an image.

[05:46] But before we can do that, we need to learn about generating images with OpenAI. That's a little bit different to everything we've done so far. So let's investigate that next.

egghead
egghead
~ 2 hours ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today