Latest / Talk Python To Me / #417: Test-Driven Prompt Engineering for LLMs with Promptimize
Transcript
- 0:00Large language models and chat-based AIs are kind of mind-blowing at the moment.
- 0:04Many of us are playing with them for working on code or just as a fun alternative to search,
- 0:10but others of us are building applications with AI at the core. And when doing that,
- 0:16the slight unpredictable nature and probabilistic style of LLMs makes writing and testing Python
- 0:22code very tricky. Enter Promptimize from Maxine Boschman and Preset. It's a framework for
- 0:29non-deterministic testing of LLMs inside of our applications. Let's dive inside the AIs with Max.
- 0:35This is Talk Python To Me, episode 417, recorded May 22nd, 2023.
- 0:40Welcome to Talk Python To Me, a weekly podcast on Python. This is your host,
- 0:58Michael Kennedy. Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using
- 1:03at Talk Python, both on fosstodon.org. Be careful with impersonating accounts on other instances.
- 1:09There are many. Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:15We've started streaming most of our episodes live on YouTube. Subscribe to our YouTube channel over
- 1:21at talkpython.fm to get notified about upcoming shows and be part of that episode.
- 1:27This episode is brought to you by JetBrains, who encourage you to get work done with PyCharm.
- 1:33Download your free trial of PyCharm Professional at talkpython.fm/done dash with dash PyCharm.
- 1:40And it's brought to you by the Compiler Podcast from Red Hat. Listen to an episode of their podcast
- 1:46to demystify the tech industry over at talkpython.fm/compiler.
- 1:51Max, welcome to Talk Python To Me.
- 1:54Well, it's good to be back on the show. And now I know it's live too, so no mistakes. I'm going to
- 1:59try to not say anything outrageous.
- 2:02People get the unfiltered versions. So absolutely. Absolutely. I love it when people come check out
- 2:07the live show. Welcome back. It's been a little while since you were on the show, about since
- 2:12September. We talked about superset. We also talked a little bit about airflow, some of the stuff that
- 2:18you've been working on. And now we're kind of circling back through this data side of things,
- 2:23but trying to bring AI into the whole story. So pretty cool project that I'm looking forward to
- 2:28talking to you about.
- 2:29Awesome. I'm excited to talk about it too. And these things are related in many ways. Like one
- 2:35common foundation is Python. Like a lot of these projects are in Python. They're data related.
- 2:40And here, promptimize and prompt engineering and integrating AI is related in a way that we're
- 2:47building some AI features into superset right now and into presets. So it ties things together in some way.
- 2:55Yeah, I can certainly see a lot of synergy here. Before we dive into it, it hasn't been that long,
- 2:59since you were on the show. But give us a quick update, just a bit about your background for people who don't know you.
- 3:05Yeah, so my career is a career of like maybe 20 or so years in data building, doing data engineering,
- 3:13doing trying to make useful data useful for organizations. Over the past decade or so, I've been very involved in open source.
- 3:22So I started Apache Airflow 2014. So for those not familiar with Airflow, though, it's pretty well known now.
- 3:28It's used at, I heard like, I think it's like 10s of 1000, I think above 100,000 companies are using Apache Airflow, which is kind of insane to think about.
- 3:38It's like you started a little project. So for me, I started this project at Airbnb, and it really took off.
- 3:44And I think it's just like great project community fit, like people really needed that. It was the right abstraction for people at the time.
- 3:52And still today, and it just really took off. So I was working on orchestration. And then I was like, I just love things that are visual and interactive.
- 4:01So there was no great open source BI tool out there business intelligence. So the sole data, data dashboarding, exploration, SQL IDE.
- 4:11So it's like a playground for people trying to understand and visualize and explore data. So I started working on Apache Super Set in 2000.
- 4:18It was like 15 or 16 at Airbnb, too. And we also brought that to the Apache Software Foundation. So again, like a very, very popular open source project that's used in like 10s, 10s of 1000, 100,000 organizations.
- 4:31And a great today, like it has become a super great open source alternative to Tableau Looker, like all those business intelligence tools very viable for organizations.
- 4:44And then quick, quick plugs at preset IO company, I started some also an entrepreneur, started a company a little bit more than four years ago around Apache Super Set.
- 4:54And then the idea is to bring, bring super set to the masses. So it's really like hosted, manage state of the art Apache Super Set for everyone with some bells and whistles.
- 5:04So the best super set you can run, there's a there's a free version too. So you can go and play and try it, you know, today gets started in five minutes.
- 5:12So it's a, it's a little bit of a commercial pointer, but also very relevant to what I've been doing, you know, personally over the past like three or four years.
- 5:20Sure, it's some of the inspiration for some of the things we're going to talk about as well and trying to bring some of the AI craziness back to products, right?
- 5:28So I think that's a, you know, from an engineering perspective, not just a, hey, look, I asked it, what basketball team was gonna, you know, win this year, and it gave me this answer, right?
- 5:37It's like, and I, and caveats, I don't know anything that happened since 2021. So AI, or, and AI specifically, Bart is a little bit better at that. But it's like, you know, the last thing I read off of the internet was in fall 2021.
- 5:50It makes some things a little bit challenging. But yeah, so we're looking at we're building, you know, AI features into preset, you know, as a commercial open source company, we need, we need to build some differentiators to from supersets, we contribute a huge amount, like maybe 50 80% of the work we do at preset is contributed back to superset, but we're looking to build differentiators. And we feel like AI is a, is a great, kind of commercial differentiator to on top, on top of superset that makes people even more interested to come and run, run, run, run, run,
- 6:20on preset too. So yeah, excellent. And jump people you say they were popular, popular projects, like airflow has 30,000 stars, Apache superset has 50,000 stars, which puts it on par with Django and flask, for people sort of mentors models out there, which is, I would say it's pretty well known. So awesome.
- 6:40Yeah, Star is a vanity metric in some ways. It's not necessarily usefulness or value delivered, but it's a proxy for popularity and hype. It gives a good sense. I think at 50,000 stars, it's probably in the top 100 of GitHub projects.
- 6:59If you remove the top 100, there's a lot of documentations and guides and things that are not really open source projects. It's probably like top 100 open source project-ish in both cases.
- 7:13Right.
- 7:14It's pretty cool. It's like you start a project and you don't know whether it's going to take off and how. It's just nice to see that.
- 7:21Yeah, absolutely. On one hand, it's nice, but it doesn't necessarily make it better.
- 7:26But it does mean there's a lot of people using it. There's a lot of polish. There's a lot of PRs and stuff that have been submitted to make it work. A lot of things that can plug into it.
- 7:36So there's certainly a value for having a project popular versus unpopular.
- 7:40Oh my God. Yes. And I would say one thing is, you know, all the dark, call it like secondary assets outside of the core projects documentation. And there will be a lot of like use cases and testimonials and reviews and people bending the framework in various ways and forks and plugins.
- 7:58So another thing too, that people, I think don't really understand the value of in software and open sources, or I'm sure people understand the value, but it's not talked about as just a whole battle tested thing.
- 8:10So when something is run at thousands of organizations in production for a long time, there's a lot of things that happen in a software that are very, very valuable for the incremental organization adopting it.
- 8:23Well, let's talk large language models for a second. So AI means different things to different people, right? It, they, they kind of get carved off as they find some kind of productive productize use, right?
- 8:37AI is this general term and like, Oh, machine learning is now a thing that we've done, or computer vision is a thing we've done.
- 8:43And the large language models are starting to find their own, their own special space. So maybe we could talk a bit about a couple of examples just so people get a sense.
- 8:53I mean, to me, ChatGPT seems like the most well-known. What do you think?
- 8:58Yeah. I mean, well, I'll say, if you think about like, what is a large language model and what are some of the leaps there?
- 9:05And I'm not an expert, so I'm going to try to not put my foot in my mouth, but some things that I think are interesting.
- 9:11So a large language model is a big neural network that is trained on a big corpus of text.
- 9:18I think one of the big leaps we've seen is unsupervised learning. So like really often, like in machine learning in the past or pre-LLMs, we would have very specific like training set and outcomes we were looking for.
- 9:33And then the training data would have to be really structured here.
- 9:36Here, what we're doing with large language models is feeding a lot of huge corpus of text and what the large language model is trying to do or resolve is to chain words.
- 9:46So he's trying to predict the next word, which seems like you would be able to put words together that kind of make sense.
- 9:55But like you wouldn't think that consciousness, not just like consciousness, but intelligence would come out of that.
- 9:59But somehow it does. Right.
- 10:01Like if you chain that it's like if you say, you know, up to the empty that he sits on a it's really clear.
- 10:07It's going to be wall, you know, the next word.
- 10:10But if you push this idea much further with a very large corpus of like human knowledge, somehow there's some really amazing stuff that does happen on these large language models.
- 10:21And I think that realization around happened at around, you know, Chad at GPT three, three, five getting pretty good.
- 10:29And then at four, like, oh, my God, this stuff can really kind of seems like it can think or be smart to be very helpful.
- 10:36Yeah. The thing that I think impresses me the most about these is they seem and people can tell me it's statistics and, you know, I'll believe them.
- 10:44But it seems like they have an understanding of the context of what they're talking about more than just predicting like Humpty Dumpty sat on the what it said on the wall.
- 10:53Right. Obviously, that's what was likely to come next when you see those that set of words.
- 10:58But there's an example that I like to play with, which I copy.
- 11:02You know, I'll give it a little thing. I'll say, hey, here's a program, Python program.
- 11:07I'm going to ask you questions about it. Let's call it arrow.
- 11:09And it's like this is a highly nested program that function that tests whether something's a platypus.
- 11:15I saw this example somewhere and I thought, OK, this is this is pretty cool.
- 11:18But it has this if it's a mammal, then if it has fur, then if it has a beak, then if it has a tail and you can just do stuff that's really interesting, like I'll ask it to a bird or something like that.
- 11:31Yeah, yeah, yeah, yeah, rewrite it, write it using guarding clauses to be not nested.
- 11:38Right.
- 11:39Oh, yeah.
- 11:40Right. And it will say, sure, here we go.
- 11:42And instead of being if this, then nest, if this, then if this, it'll do if not, if not return false.
- 11:47Right. Which is which is really cool. And that's kind of a pretty interesting one.
- 11:51But like this is this is the one. This is the example that I think is crazy is rewrite arrow to test for crocodiles.
- 12:00They're using that.
- 12:01It's like what people would call a one shot, a few shot example of like a here's a here's an example, the kind of stuff I might want.
- 12:09There's some different ways to do that.
- 12:11But it's a pattern in prompt engineering where you'll say you have a zero shot, one shot, few shot examples we get into.
- 12:17But it does feel like it understands the code. Right. Like what you're trying to do.
- 12:22Right. Just for people listening, it said, OK, here's a function is crocodile.
- 12:26If not, self thought is reptile. If not, self thought has scales. These are false examples. Right.
- 12:30And if it has four legs and a long snout that can swim. Right. Like it it rewrote the little tests and stuff. Right.
- 12:36In a way that seems really unlikely that just predicting likelihood because it's never seen anything like this, really, which is really it's pretty mind blowing, I think.
- 12:46Or it or it had like it read the entire internet and all of GitHub and that kind of stuff.
- 12:51So it has seen. Exactly.
- 12:52Things that think that's mind boggling is just like can like when you think about what it did there is it read the entire conversation so far, your your input prompt.
- 13:03And it has like a system prompt ahead of time that says, you know, your ChatGPT try to be helpful to people.
- 13:09And here's a bunch of things that you should or should not say and non bias.
- 13:13You try to be concise and good and virtuous.
- 13:16And people have found all sorts of jail breaks out of that.
- 13:19But like all it does from that point on as I try to predict the new the next word, which is kind of insane that it gets to, you know, the amount of structure that that we see.
- 13:29Right. Right. That's a lot of structure there. Right.
- 13:31So pretty impressive. And ChatGPT is starting to grow.
- 13:35You know, you've got version four and you can start using some of the plugins.
- 13:37It's going to keep going crazy there.
- 13:39Other examples are simply just released lemur, which is a large language model, but really focused on transcribing speech, which I think is kind of cool.
- 13:48Microsoft reduce Microsoft security release Microsoft security copilot, which is a large language model to talk about things like engine X misconfiguration and stuff like that.
- 13:59There's just just a lot of a lot of stuff out there that's coming along here. Right.
- 14:04A lot of type of thing on the on the open source front to there's there's all ethical thing.
- 14:11Like, should everyone and anyone have access to open source models doing that while we don't really understand and we probably shouldn't get to the ethics part of the debate here, because that's a whole series of episodes.
- 14:25We probably want to get into.
- 14:26But what's interesting is, you know, Databricks came up with a model for what's called Facebook call.
- 14:30It came up with one called Lama and they open source and or the weight.
- 14:34So you have the model topology with the pre trained weights.
- 14:39In some cases, there's open source corpus of training that are also coming out and are also open source.
- 14:45So that means like and these these open source models are somewhat competitive or increasingly competitive with GPT or.
- 14:54Yeah, which is kind of crazy.
- 14:57And some of them don't are where GPT for has limitations.
- 15:01They break through these limitations.
- 15:03So one thing that's really important as a current limitation of the GPT models and LLMs is the prompt window, the token prompt window.
- 15:13So basically, when you ask a question, you know, it's been it's been trained and has machine learn with data up to I think in the case of GPT three, five or four.
- 15:24It's the corpus of training goes all the way to fall 2021.
- 15:28So if you ask like, who is the current president of the United States, it just doesn't know or I will tell you as of 2021 it is this person.
- 15:36But so if you're trying to do tasks like what I've been working on, would probably get into later in the conversation is trying to generate SQL.
- 15:44SQL, it doesn't know your table.
- 15:46So you have to say, hey, here's all the tables in my database.
- 15:48Now, can you generate SQL that does X on top of it?
- 15:51And that context window is increased is limited and increasing.
- 15:56And some of these open source models have different types of limitations.
- 16:01This portion of talk Python to me is brought to you by JetBrains, who encourage you to get work done with PyCharm.
- 16:08PyCharm Professional is the complete IDE that supports all major Python workflows, including full stack development.
- 16:15That's front end JavaScript, Python back end and data support, as well as data science workflows with Jupyter.
- 16:22PyCharm just works out of the box.
- 16:24Some editors provide their functionality through piecemeal add ins that you put together from a variety of sources.
- 16:31PyCharm is ready to go from minute one.
- 16:34And PyCharm thrives on complexity.
- 16:37The biggest selling point for me personally is that PyCharm understands the code structure of my entire project, even across languages such as Python and SQL and HTML.
- 16:48If you see your editor completing statements just because the word appears elsewhere in the file, but it's not actually relevant to that code block, that should make you really nervous.
- 16:58I've been a happy paying customer of PyCharm for years.
- 17:01Hardly a workday passes that I'm not deep inside PyCharm working on projects here at Talk Python.
- 17:08What tool is more important to your productivity than your code editor?
- 17:12You deserve one that works the best.
- 17:14So download your free trial of PyCharm Professional today at talkpython.fm/donewithpycharm and get work done.
- 17:22That link is in your podcast player show notes.
- 17:25Thank you to PyCharm from JetBrains for sponsoring the show and keeping Talk Python going strong.
- 17:30Right. It's interesting to ask questions, right?
- 17:34But it's more interesting from a software developer's perspective of, can I teach it a little bit more about what my app needs to know or what my app structure is, right?
- 17:45In your case, I want to use superset to ask the database questions.
- 17:51But if I'm going to bring in AI, it needs to understand the database structure so that when I say help me do a query to do this thing, it needs to know what the heck to do, right?
- 18:02The table I need to know.
- 18:03So there's the stuff it knows and the stuff it can't know.
- 18:07And some of it goes, is related to the fact that whether this information is public on the internet, whether it has happened to be trained against it.
- 18:15And then if it's in private, there's just no hope that it would know about, you know, your own internal documents or your database structure.
- 18:21So in our case, it speaks SQL very, very well.
- 18:25So as we get into this example, like how to get GPT to generate good SQL in the context of a tool like superset or SQL lab, which is our SQL IDE.
- 18:34So it knows how to speak SQL super well.
- 18:37It knows the different dialects of SQL very, very well.
- 18:40It knows its functions, its dates functions, which a lot of the SQL engineers on the call, like, yeah, I can never remember like what Postgres data function is.
- 18:50But at GPT or GPT models, just it knows SQL, it knows the dialects, it knows the mechanical SQL, it understands data modeling, foreign keys, drawings, primary, all this stuff it understands.
- 19:01It knows nothing about your specific database, the, you know, the schema names and the table names, the column names that I might be able to use.
- 19:10So that's where we need to start providing some context.
- 19:13And this context window is limited.
- 19:15So it's like, oh, how do you use that context well or as well as possible?
- 19:21And that's the field and some of the ideas behind it is prompt crafting and prompt engineering, which we can get into once we get there.
- 19:29Maybe we're there already.
- 19:31Yeah, yeah.
- 19:32Well, yeah, I think where I see this stuff going is from this general purpose knowledge starting to bring in more private or personal or internal type of information.
- 19:44Right.
- 19:44Like our data about our customers is like structured like this in a table.
- 19:48And here's what we know about them.
- 19:49Now let us ask questions about our company and our thing.
- 19:52Right.
- 19:53And it's like starting to make inroads in that direction, I think.
- 19:56Yeah.
- 19:57You know, one thing to know about is there's different approaches to teach or provide that context.
- 20:04So one would be to build your own model from scratch.
- 20:07Right.
- 20:08And that's pretty prohibitive.
- 20:10So you'd have to, you know, find the right corpus.
- 20:12And instead of starting with a model that knows SQL and needs to know your table and context, you have to start from from zero and very prohibitive.
- 20:20Another one is you start from a base model at some point of some kind.
- 20:24There's a topology.
- 20:25So there's, you know, different layers and number of neurons and it knows some things.
- 20:29And then you load up some weights that are open source.
- 20:31And then you say, I'm going to, I'm going to tune this model to teach it my database schemas and basically my own corpus of data.
- 20:39So it could be your data dictionaries could be your internal documents.
- 20:43It could be your GitHub code, your dbt projects.
- 20:46If you have one of your airflow tags, be like, I'm going to dump all this stuff in the model and that will be get baked into their own network itself.
- 20:54That's doable, pretty prohibitive in this era.
- 20:58If you have the challenge that we have a preset, which is we have multiple customers with different schemas, we can't have spillover.
- 21:05So you have to train a model for each one of our customers and serve a model for each one of our customers.
- 21:10So still pretty prohibitive.
- 21:12And a lot of people fall back on this third or fourth method that I would call prompt engineering, which is going to use the base model, the open API API or just an API on LLM.
- 21:24And then I will, if no SQL already, I'll just say, hey, here's a bunch of tables that you might want to use.
- 21:29Can you generate SQL on top of it?
- 21:31So then that's just a big request with a lot of context.
- 21:36Then we have to start thinking about maximizing the use of that context window to pass the information that's most relevant within the limits allowed by the specific model.
- 21:46Right. And that starts to get into reproducibility, accuracy, and just those limitations, which is kind of an engineering type of thing. Right.
- 21:56Yeah. And then, you know, maybe a topic too. And, you know, this conversation is based on a recent blog post and the flow.
- 22:02Just going back to the flow of that blog post, we started by establishing the premise that everyone is trying to bring AI into their product today.
- 22:11Right. Thousands of product builders are currently exploring ways to harness the power of AI and the products and experiences they create.
- 22:18That's the premise for us with text to SQL and SQL lab as part of preset.
- 22:23But I don't know if you think of any product, any startup, any SAS product you use to work at HubSpot today, you're trying to figure out how to leverage AI to build, you know, sales chat bots or as the chat chat bot.
- 22:38So everyone everywhere is trying to figure that out. And the challenge is the challenges, I guess, very probabilistic in a different interface to anything we know.
- 22:47Like, you know, engineers would be like, oh, let's look at an API and leverage it.
- 22:51And APIs are very, very deterministic. And in general, AI is kind of wild beast to tame.
- 22:58You know, you ask first the interface is language, not code.
- 23:03And then what comes back is like semi probabilistic in nature.
- 23:07And it could change underneath you. It's a little bit like web scraping in that regard that like it does the same.
- 23:12It does the same. And then, you know, something out there change, not your code.
- 23:16And then a potentially different behavior comes back. Right.
- 23:20Because they may have trained another couple of years, refine the model, switch the model, change the default temperature, all these things.
- 23:26Yeah, there's a lot that can happen there. One thing I noticed, like starting to work with what I would call prompt crafting, which is, you know, you work with ChatGPT and you, you craft different prompt with putting emphasis in a place or another or changing the order of things or just changing a word.
- 23:43Right. Just say like important exclamation point, capitalize the words, you know, the reserve words in SQL.
- 23:51And then just the fact that you put important exclamation point, you know, will make it do it or not do it, changing from a model to another.
- 23:59So one thing that's great is the model, at least at OpenAI are, they are immutable as far as I know.
- 24:06But like if you use GPT-5, 3.5 Turbo, for instance, as just one trained model, I believe that that is immutable.
- 24:15The chat bot on top of it might get fine tuned and change over time.
- 24:20But the model is supposed to be static.
- 24:23You mentioned temperature.
- 24:24Be kind of interesting to just mention for those who are not familiar with that.
- 24:27So when you interact with AI, one of the core parameters is temperature.
- 24:31And it's it's I think it's a value from zero to one or I'm not sure if you know how exactly you pass it.
- 24:39But it basically defines how creative you want.
- 24:43You want to let the AI be like how to put it to zero.
- 24:48You're going to have something more deterministic.
- 24:50So asking the same question should lead to a similar or the same answer.
- 24:54Though not in my experience, it feels like it should, but it doesn't.
- 24:57But then if you put a higher, it will get more creative to talk more about like how that actually seemed to work behind the scenes.
- 25:05Yeah. Well, the that variability seems to show up more in the image based ones.
- 25:10So, for example, this article, this blog post that you wrote, you have this image here and you said, oh, and I made this image from mid journey.
- 25:17I've also I was I got some examples of a couple that I did.
- 25:22Where did I stick them somewhere?
- 25:23Here we go.
- 25:24Where I asked just for like YouTube thumbnails.
- 25:26I asked mid journey for like a radio astronomy example that I can use, because here's one that's not encumbered by, you know, some sort of licensing, but still looks kind of cool and is representative.
- 25:36Right.
- 25:37And there it's like massive difference.
- 25:40I don't I'm not sure how much difference I've seen.
- 25:43I know it will make some, but I haven't seen as dramatic of a difference on chat.
- 25:47Yeah.
- 25:48Yeah.
- 25:49Yeah.
- 25:50I'm not sure exactly how they introduce the variability on the generative images.
- 25:55AI.
- 25:56Right.
- 25:57I know it's like this multi dimensional space with a lot of words and a lot of images in there.
- 26:02And then it's probably like where the location point of that the rent rent, like they randomized that point in that multi dimensional space.
- 26:12So for ChatGPT is pretty easy to reason about, and I might be wrong on this again, I'm not an expert, but you know how the way it works is it writes, it takes the prompt and then it comes up with the next word sequentially.
- 26:24So for each word for the next word, so Humpty Dumpty sat on a, it might be wall at 99%, but like that might be 1% of, you know, fence or something like that.
- 26:36And if you, you up the temperature, there's, it's more likely to pick the non first word and that probably less, they probably do in a weighted way.
- 26:48Like it's possible.
- 26:49I take a second or third word randomly.
- 26:51And then of course it's going to get a tree or decision tree.
- 26:54Once it picks the words, the next word is also changes.
- 26:57So as you up that it goes down path that sends it into more creative or different.
- 27:04Right.
- 27:05Yeah.
- 27:05A little butterfly effect.
- 27:06It makes a different choice here.
- 27:08And then it sends it, you know, sends it down through the graph.
- 27:11Interesting.
- 27:12So one thing that you really pointed out here, and I think is, is maybe worth touching on a bit is this idea of prompt engineering.
- 27:19There's even places like learn prompting.org that like try to teach you how to talk to these things.
- 27:24And, and you make a strong distinction between prompt crafting or just talking to the AI versus like really trying to put an engineering focus on it.
- 27:33Do you want to?
- 27:34Yeah.
- 27:35Because like, yeah, I think it's a super important differentiation, but one that I'm proposing.
- 27:40Right.
- 27:41So I don't think that people have settled as to what is one or what is the other.
- 27:45I think I saw a Reddit post recently that was like prompt engineering is just a load of crap.
- 27:50Like, you know, anyone can go because they thought their, their understanding of prompt engineering was like, oh, you know, you fine tune or you craft your prompt.
- 27:59Then you say like, you are an expert AI working on, you know, creating molecules.
- 28:05Now, can you do this?
- 28:06And then, you know, by doing that, you might get a better outcome or a one really interesting thing that people have been doing in prompt crafting.
- 28:13That seemed to have like huge impact on there's been paper written on this specific just hint or craft tweak is let's proceed step by step.
- 28:26So basically, whatever the question is that you are asking is specifically around like more mathematicals or like things that require more systematic step by step thinking the whole like just like, let's think let's expose this or let's go about it.
- 28:41Step by step makes it much better.
- 28:43So here you might be able to, well, so you know, if you had, if you had an example where ChatGPT three failed or ChatGPT-4 failed, you could just say, Colin, let's go step by step.
- 28:56And it might succeed that, that time around, which is kind of, maybe you can get it to help you understand instead of just get the answer.
- 29:03Right. Like factor this polynomial into its primary solutions or roots or whatever.
- 29:10And you're like, okay, show me that. Don't just show me the answer.
- 29:12Show me step by step.
- 29:13So I could understand and try to learn from what you've done. Right.
- 29:16Yeah. I mean, if you think about how the way that it's trying to come up with a new word, if all it does is a language based answer to a mathematical question, like how many days are there between this date and that date?
- 29:29There's no, that specific example might not exist or it's kind of complicated for it to go about it.
- 29:35But if you say, let's think step by steps. Okay. There's this many months. This month's duration is this long. There's this many days since the beginning of that month and might get it right. That, you know, that time around.
- 29:48Right. Or if it fails, you could pick up partway along where it has some more.
- 29:52Yeah. You know, and then you can trace, I mean, just you too, like, I think, you know, one thing is like, you should be extremely careful as like taking for granted that it's right all the time, you know?
- 30:00So that means like, it also helps you review its process and where it might be wrong, but back to crafting versus engineering.
- 30:08So crafting would be the process that I think is more attached to a use ChatGPT every day, the same way that, you know, we've been trained at Googling, you know, over the past like two decades.
- 30:20You know, use a pollute, use quotes, use plus and minus, and you know which keywords to use intuitively, right? You know where it's going to get confused or not.
- 30:29So I think prompt crafting is a different version of that. That's just more worthy.
- 30:35And if you're, you know, you're working with the AI to try to assist you, write your blog post or to try to assist you in any task really, just to be smart about how you bring the context, how you tell it to proceed, goes a very, very long way.
- 30:49So that's what I call prompt crafting, call it like one of cases.
- 30:53What people do when they're interacting with, with the large language model.
- 30:57I think so. Right. Like it's not evident for a lot of people. Well, they are exploring the edge of where it fails and they love to see it fail.
- 31:05And, and then they don't think about like, Oh, what could I have told it to get the answer?
- 31:10I was actually looking for like, ah, I got you wrong. You know, it's as if I had that actor in a conversation. I like, ah, you're wrong. And I told you so, you know, so I think there's a lot of that online, but I think for all these examples that I've seen,
- 31:22I'm really tempted to take the prompt that they had and then give, give it an instruction or two or more, and then figure out how to get it to come up with the right thing.
- 31:30So prompt crafting super important skill. you know, you could probably get a boost of, for most knowledge information workers, you'll get a boost of 50% to 10 X for a lot of the tasks you do every day.
- 31:41If you use AI well, so it's great personal skill to have, go and develop that skill. If you don't.
- 31:48This portion of talk Python is sponsored by the compiler podcast from Red Hat.
- 31:51Just like you, I'm a big fan of podcasts and I'm happy to share a new one from a highly respected open source company compiler and original podcast from Red Hat.
- 32:01Do you want to stay on top of tech without dedicating tons of time to it? Compiler presents perspectives, topics, and insights from the tech industry free from jargon and judgment.
- 32:11They want to discover where technology is headed beyond the headlines and create a place for new IT professionals to learn, grow, and thrive.
- 32:17Compiler helps people break through the barriers and challenges turning code into community at all levels of the enterprise.
- 32:23One recent and interesting episode is there. The great stack debate.
- 32:27I love, love, love talking to people about how they architect their code, the trade offs and conventions they chose, and the costs, challenges, and smiles that result.
- 32:37This great stack debate episode is like that. Check it out and see if software is more like an onion or more like lasagna or maybe even more complicated than that.
- 32:45It's the first episode in compiler series on software stacks. Learn more about compiler at talkpython.fm/compiler.
- 32:53The link is in your podcast player show notes. And yes, you could just go search for compiler and subscribe to it. But follow that link and click on your players icon to add it.
- 33:03That way they know you came from us. Our thanks to the compiler podcast for keeping this podcast going strong.
- 33:11Prop engineering. In my case, I'm like, you're building something, you're using an AI as an API behind the scene.
- 33:19You want to pass it a bunch of relevant contexts, really specify what you want to get out of it.
- 33:25Maybe you even want to get a structured output, right? You might want to get a JSON blob out of it.
- 33:30You say, return a JSON blob with the following format so it's more structured.
- 33:35So then to give all these instructions, there's this idea of providing few shots too.
- 33:40You might be storing context in a vector database. I don't know if we're getting to that today, but there are ways to kind of structure and organize your potential embeddings or the things you want to pass as context.
- 33:52So there's a lot here. I think somewhere too, I talk about prompt engineering. If we scroll in the blog post, like what is prompt engineering?
- 33:59And prompt engineering will list the kind of things. It might be higher in the post. Sorry, we're scrolling for people.
- 34:06I want to introduce what is prompt engineering.
- 34:10Yeah.
- 34:11Well, there's not above this section.
- 34:16You can scroll at the beginning of what is prompt engineering.
- 34:20Yeah, here you go.
- 34:21Oh yeah, right here. The definition of this is Chad's GPT's version of it. So when you do prompt engineering, you can add context, which that means that you're going to have to retrieve context maybe from a database, from a user session, from your Redux store if you're in the front end, right?
- 34:37You're going to go and fetch the context that's relevant in the context of the application.
- 34:41It leads while building products.
- 34:42Specify an answer format.
- 34:43You could just say, yes, I just want a yes or no, a Boolean.
- 34:46I want a JSON blob with not only the answer, but your confidence on that answer or something like that.
- 34:52Limiting scope, asking for pros and cons, incorporating verification or sourcing.
- 34:59So that's more, you know, if you iterate on a prompt, you're going to be rigorous about is this prompt better than the previous prompt I had like this.
- 35:07If I pass five rows of sample data while doing text to SQL, does it do better than if I or does it do more poorly than if I pass 10 rows of sample data or provide a certain amount of column level statistics.
- 35:20So prompt engineering is not just prompt crafting.
- 35:23It is like bringing maybe the scientific method to it, bring some engineering of like fetching the right context and organizing it well and then measuring the outcome.
- 35:33Right. Exactly.
- 35:34Something that comes out, you can measure and say, this is, you know, 10% better by my metric than it was before with this additional data.
- 35:41Right. That's, that's a big difference.
- 35:42Right. And then there's so many things moving, right?
- 35:45Like, and everything is changing so fast in the space that you're like, oh, well, ChatGPT five or GPT five is out or GPT-4 turbo is half the price and then just came out.
- 35:54Now I'm just going to move to that.
- 35:55They're like, wait, is that that performing better?
- 35:58Or, you know, what are, what are the trade off?
- 36:01Or even I'm going to add, I'm going to move this section, you know, asking for a certain Jason format above this other section.
- 36:08I'm going to write important exclamation point do X. Does that improve my results?
- 36:14Does that messes mess it up?
- 36:16And which one of my test case perhaps that succeeded before fails now, which one failed before succeeds now.
- 36:22So you can be like, is that a better, a worse iteration towards my goal?
- 36:28Right. Right.
- 36:29Kind of training, bringing this unit testing TDD mindset.
- 36:33Yes.
- 36:34Yeah.
- 36:35We're getting deeper into the blog post, right?
- 36:37So the blog post is talking about bringing this TDD, the test driven development mindset to prompt engineering.
- 36:46Right.
- 36:47And there's a lot of things that are in common.
- 36:49You can, you can take and apply and kind of transfer just over.
- 36:53There are some things to that breakdown that are fundamentally different between testing a prompt or working with AI and working with, you know, just a bit more deterministic code testing type framework.
- 37:05We can get into that.
- 37:06Yeah. Yeah, for sure.
- 37:08So you called out a couple of reasons of why TDD is important for prompt engineering.
- 37:13Maybe we could run through those.
- 37:15Yeah.
- 37:16So, you know, the first thing is, the AI model is not a deterministic things, right?
- 37:22You, you use a modern API or a graph, you are a rest API.
- 37:26The, the format of what you ask is extremely clear.
- 37:30And then the format of what you get back is usually defined, defined by a schema.
- 37:34It's like very deterministic, pretty guaranteed that you're, you do the same request.
- 37:37We'll get the same output ish, or at least format.
- 37:40what AI that's not the case, right?
- 37:43So it's much more unpredictable and probabilistic by nature.
- 37:47second one is handling complexity.
- 37:50So, AI systems are complex, black boxy, kind of unpredictable too.
- 37:54So, and embrace that and assume that you might get something really creative coming out of there for better or for worse.
- 38:01and then reducing risk, like you're shipping product, you know, if you're shipping product, writing product,
- 38:08um, you don't want to silly, like any sort of like, bias or weird thing like the AI could go a little crazy and, and yeah,
- 38:16There are examples of AIs going crazy before like Tay.
- 38:20Do you remember Microsoft Tay?
- 38:22I don't know that one, but I know of other examples.
- 38:24Yeah.
- 38:25I mean, it came out and it was like this, this sort of just, you know, I'm here to learn from you internet.
- 38:30And people just turned it into a racist and made it do all sorts of horrible things.
- 38:34And they had to shut it down a couple of days later because it's just, it's like, whoa, it met the internet and the internet is mean.
- 38:40So, that's not great.
- 38:42Yeah.
- 38:42Yeah.
- 38:43Train it on a 4chan or let it go crawl 4chan and Reddit.
- 38:47And that's not always going to be nice.
- 38:49So bad.
- 38:50Right.
- 38:51I mean, you, you, you don't entirely control what's going to come out of those things.
- 38:54And so.
- 38:55Oh yeah.
- 38:56Or I would say a little more predictable.
- 38:57Right.
- 38:58I would say, yeah, like, you don't entirely control.
- 38:59Like I think, yeah, like basically, you know, control might be a complete illusion.
- 39:04Like even the people working at OpenAI don't fully understand what's happening in there.
- 39:09Yeah.
- 39:10Like, well, it read a bunch of stuff and it's predicting the next word and, it gets most things right.
- 39:17By the way, like they do a lot around this idea of like, not necessarily TDD, but there's a whole eval framework.
- 39:22So you can submit your evaluation functions to OpenAI.
- 39:26And as they, they train the next version of things, they include that in what their evaluation system for the new thing.
- 39:33So say if I wanted to go and contribute back a bunch of like text to SQL type use cases, as they call evals, then they would take that into consideration when they, they train their next models.
- 39:45All right.
- 39:45So going down the list, reducing risk, right?
- 39:47So you're integrating some, that beast that's not fully tamed into your product.
- 39:52So you probably want to make sure it's tamed enough to live inside your product.
- 39:56continuous improvements that I, that should have been maybe the first one in the list is you're iterating on your prompts.
- 40:02You're trying to figure out a past context.
- 40:04you're, you're, you're trying different model versions.
- 40:08Maybe you're, you're trying some open source models or the latest GPT cheaper greater thing.
- 40:14so you want to make sure that as you iterate, you're getting to the actual outcomes that you want systematically.
- 40:21And then performance measurement too, like how long does it take?
- 40:24How much does it cost?
- 40:25you, you kind of need, to have a handle on that.
- 40:29The new model might be 3% better on your corpus of tests, but it might be six times the price.
- 40:35Like, do you, do you want, are you okay?
- 40:37Right, right.
- 40:38Or just from a user perspective.
- 40:40Yeah.
- 40:40Time to interaction.
- 40:41You know, that's one thing with AI we're realizing now is a lot of the prompts on, on four will be like, you know, two to, one to seven seconds, which in the Google era, you know, there's been some really great papers out of Google early on that, prove that, you know, it's like a hundred milliseconds as an impact on user behaviors.
- 41:01Right.
- 41:02Right.
- 41:03Yeah.
- 41:04People give up on checkout flows or whatever, not going to the next part of your site on a measurably on a hundred millisecond blocks.
- 41:11Right.
- 41:11When you're talking, well, here's 7,000, you know, you're 70 of those.
- 41:14That's going to have an effect potentially.
- 41:15Oh, it has, has been proven and very intricate and usage pattern session duration session outcomes.
- 41:23Right.
- 41:24And you know, a second is a mountain.
- 41:26If today, like we were at this AB test Google between like whatever millisecond it's at now, like just one second or half a second that the results coming out of that AB test would, which show very, very different behaviors.
- 41:39Wow.
- 41:40I think there's some, no code mailnet, there's some really great papers, you know, written on TTI and just time to interaction and the way it influenced user behavior.
- 41:48So we're still, you know, in the AI world has to, if you're going to wait two to seven seconds for your prompt to come back, it's got to add some real, some real important value to what's happening.
- 41:58Yeah, it does.
- 41:59I think it's interesting that it's presented as a chat.
- 42:01Right.
- 42:02I think that gives people a little bit of a pause, like, oh, it's talking to me.
- 42:05So let's let, let's let it think for a second rather than it's a website that's supposed to give me an answer.
- 42:09Yeah.
- 42:10Compared to then, I guess your basis for comparison is a human, not a, you know, a website or not comparing against Google.
- 42:17So that's great.
- 42:18Yeah.
- 42:19I ask it a really hard question.
- 42:20Give it some time, right?
- 42:21Like that's not normally how we think about these things.
- 42:23Okay.
- 42:24So what's the workflow from this engineering, building a product testing, like an AI inside of your product.
- 42:30You want to walk us through your workflow here?
- 42:32Yeah.
- 42:33And you know, if you, if you, I think I looked at TDD, you know, and, and originally what is the normal like TDD type workflow?
- 42:40And I just adapted this little diagram to, to, to prompt engineering work.
- 42:46Cause the whole idea of the blog post is to, to bring prompt engine, like TDD mindset to prompt engineering.
- 42:51So this is where, where I went, but yeah, the workflow is like, okay, define the use case and desired AI behavior.
- 42:58What are you trying to solve with AI?
- 43:00In my case, the example that I'll, I'll use and try to reuse throughout this presentation is, as throughout this, you know, conversation is, you know, text to SQL.
- 43:10So like, we're trying to, what a user prompt, what a database schema gets, get the AI to generate goods, good, useful SQL, find the right tables and columns to use that kind of stuff, create test cases.
- 43:21So it's like, okay, if I have this database and I have this prompt, give me my top five salary per department on this HHR dataset, there's a fairly deterministic output to that.
- 43:33Or you could say the SQL is not necessarily deterministic.
- 43:35There's different ways to write that SQL, but there's a deterministic data frame or results set that might come up.
- 43:41There is a right answer of the top five salaries.
- 43:44That's right.
- 43:45You can see like, you're not getting, ultimately get that.
- 43:47And it's great if it's, if it is, deterministic, cause you can test it.
- 43:51If you, you know, if you, if you're trying to use AI to say, write an essay about, Napoleon Bonaparte's, second conquest, you know, in less than 500 words, it's a, it's not as deterministic as it's hard to test whether the AI is doing good or not.
- 44:08So you might need human evaluators before I would say in most AI product or people are trying to bring AI into their product.
- 44:16in many cases, more deterministic.
- 44:18So another example of like more deterministic would say like, Oh, getting, if you say getting AI to write Python functions, it's like, Oh, write a function that, you know, returns.
- 44:28If a, if, if a number is prime, yes or no, like the, you can get the function and test it in a deterministic kind of way.
- 44:38So anyways, just pointing out it's better.
- 44:40You're only going to be able to have a TDD mindset if you have like somewhat deterministic, you know, outcome to the, you want to use the AI for then create the prompt generator.
- 44:50So that would be your first version or in the text to SQL example, it's given, you know, the 20 tables in this database and this columns and table names and data types and sample data generate SQL that answers the following user prompt.
- 45:04And then the user prompt would say something like department by type, type five salary for department.
- 45:10and then you, then we're getting for people that are not on the visual, stream, not YouTube, but on just audio, we're getting into the loop here where it's like, run the test, evaluate the results, refine the tests, refine the prompts and then start over.
- 45:23Right.
- 45:24And probably, compile the results, keep track of the results so that you can compare, not just like, Oh, are you 3% better on your test cases?
- 45:32but also did you, which tests that used to fail succeed now, which, which tests that used to fail, succeed, fail now.
- 45:41And then, once you're happy with the level of success you have, you know, you can integrate the prompt into the product or maybe upgrade.
- 45:49Ship it.
- 45:50Yeah.
- 45:50Ship it.
- 45:51Ship it.
- 45:52So I think it's probably a good time to jump over to your framework for this because py tests and other testing frameworks in Python are great.
- 46:01But they're pretty low level compared to these types of questions you're trying to answer.
- 46:06Right.
- 46:06Like how has this improved over time for, you know, I was doing 83% right.
- 46:12Right.
- 46:13Py tests, a search, a true or a false.
- 46:14It doesn't assert that 83% is.
- 46:17Yeah.
- 46:18Like if, if any of your, your py tests fail, you're, you're probably gonna not see, I not allow, see, I'm not even merge the PR.
- 46:28Right.
- 46:28So one thing that's different between test driven development and unit testing and prompt engineering is that the out, the out, the outcome is probabilistic.
- 46:36It's not true or false to it might just be like zero or one, right.
- 46:39Where I are a spectrum, you know, it fails.
- 46:43so for a specific test, you're like, off, it gets this column, but not this other column, you succeed at, you know, 50%.
- 46:50So it's non binary.
- 46:52It's also, you don't need perfection to ship.
- 46:54You just need better than the previous version or good enough to start with.
- 46:58So the mindset is, is, so there's a bunch of differences.
- 47:02And for, for those interested, we won't, get into the, in the blog post.
- 47:06I think I list out the things that are, different between the two.
- 47:09I think it's a little bit above this, but, you know, the first thing I want to say is like the level of ambition of this project versus an air flow is super set is like very low.
- 47:18Right. So it's maybe, more similar to, a test, a unit test library and no discredit to the great, awesome, like a unit test libraries out there.
- 47:29But you would think those are fairly simple and straightforward.
- 47:32I was just the information architecture of a pie test is probably simpler than the information architecture of a Django for instance.
- 47:39Right. It's just like a different thing.
- 47:41And here, the level of ambition is much low and much, you know, for this is, is fairly simple.
- 47:47So prompt demise is something that I created, which is a toolkit to help people write, to, to evaluate and score and understand while they iterate on their pro while doing prompt engineering.
- 48:03But so in this case, I think, I talk about the use case at preset, which is a, we have a big corpus, that luckily was contributed by, I forgot which university, but a bunch of PhD people did a text to SQL, contest.
- 48:16I think it was Yale.
- 48:17I think it was Yale.
- 48:18Yale. Yeah.
- 48:19Yeah.
- 48:20So yeah.
- 48:21So great people at Yale were like, Hey, we're going to generate, you know, 3000 prompts on 200 databases with the SQL that should be the outcome of that.
- 48:31It's a big test set so that different researchers working on text to SQL can compare their results.
- 48:36so for us, we're able to take that test set and some of our own test sets and run it at scale against, you know, OpenAI or against Lama or against, different models.
- 48:48And by, by doing that, we're able to evaluate like, you know, this particular combo of like this prompt engine methodology with this model generates, you know, 73% accuracy.
- 49:00And we have these reports we can compare, you know, fairly easily, which prompts that, as I said before, we're failing before succeeding now and vice versa.
- 49:09So you know, I mean, am I actually making progress here or going backwards?
- 49:13And if you try to do that on your own, like if you're crafting your prompt, just anecdotally and try on five or six things like you quickly realize like, Oh shit, I'm going to need to really test out of much broader range of this and some rigor methodology around that.
- 49:27So, right.
- 49:28And try and you remember and go back and go, this actually made it better.
- 49:31Right.
- 49:32Cause it's, it's hard to keep all that in your mind.
- 49:34Yeah.
- 49:34Yeah.
- 49:35And something interesting that I'm realizing to work on this stuff is like everything is changing so fast, right?
- 49:41The models are changing fast.
- 49:42The prompting windows are changing fast.
- 49:44The vector databases, which is a way that organize and structure context for your prompts evolving extremely fast.
- 49:51It feels like you're working on unsettled ground in a lot of ways.
- 49:55Like a lot of stuff you're doing might be challenged by, you know, but the BART API came out last week and maybe it's better at SQL generation.
- 50:02And then I got to throw everything that I did on open act, but here's something you don't throw away your test library and your use cases.
- 50:10Right.
- 50:11Maybe is the thing is the real asset here.
- 50:14The rest of the stuff is like, oh yeah, it's moving so fast that all the mechanics of the prompt engineering itself and the interface with the, whatever model is the best at the time.
- 50:26You're probably gonna have to throw away as this evolves quickly.
- 50:29But your test library is something really, really solid that you can perpetuate or like, you know, keep improving and bringing along with you along the way.
- 50:39So it's kind of an interesting thought around that.
- 50:41Yeah.
- 50:42Let's talk to this.
- 50:43Let's talk to this example.
- 50:44You have on promptimize is GitHub read me here to give it, make it a little concrete for people.
- 50:49Like how do you actually write one of these tests?
- 50:51Yeah.
- 50:52So, so there's different types of prompts, but yeah, the, you know, what I wanted to get to was just like, just like, what is the prompt and how do you evaluate it?
- 51:00Right.
- 51:01And then behind the scene, we're going to be, you know, discovering all your prompts and running them and compiling results and reports, right.
- 51:08And doing analytics and making it easy to do analytics on it.
- 51:11The examples that we have here and I'll try to be conscious of both the people who can read the code and people who don't like the people who are just on audio, but here from promptimize.prompt, we import a simple prompt.
- 51:23And then we bring some evals that are just like utility functions around evaluating the output of what comes back from the AI.
- 51:31And here, the first prompt case in the model, here, I could just create an array or a list of prompt cases.
- 51:38And it's a prompt case, like a test case.
- 51:40And with this prompt case, this very simple one, I say, hello there, exclamation point.
- 51:46And then I evaluate that as says, you know, either hi or hello in the output.
- 51:52Right.
- 51:53So if any of the words exists and what comes back, I give it a one or a zero framework allows you to, you could say, oh, it has to have both these words or give the percentage of success based on the number of words from this list that it has.
- 52:07But, you know, that's the first case.
- 52:10The second one is like a little bit more complicated, but name the top 50 guitar players of all time, I guess.
- 52:17And I make sure that Frank Zappa is in the list because I'm a Frank Zappa fan here.
- 52:21But, you know, you could have a different, you could say, hey, I want to make sure that, you know, at least three out of five of these are in the list.
- 52:29Those are like very more like natural language, very simple tests to, you know, just so that's the hello world, essentially.
- 52:37And then, you know, we're showing some examples of what's happening behind the scene.
- 52:40Well, it will actually like call, you know, the underlying API, get the results, run your eval function and compile a report.
- 52:48What was the prompt?
- 52:49What was, oh, a bird just flew into my room.
- 52:52Inside?
- 52:53Yeah, that's going to make the podcast interesting.
- 52:56Oh, my goodness.
- 52:58Okay.
- 52:59That might be a first here.
- 53:01That is nuts.
- 53:02Oh, well, it's out of my room.
- 53:04Guess what?
- 53:05There's other people in the house.
- 53:06I'm just going to close the door to my room.
- 53:09I'm dealing with it later.
- 53:11All right.
- 53:12Well, that's a first.
- 53:14I've had a bat fly into my house once, but never a bird.
- 53:19So both are crazy.
- 53:21How indirect.
- 53:22You're the first on the podcast out of eight years.
- 53:23We've never had a bird wild animal enter the studio of the guests.
- 53:28Yes.
- 53:29Well, welcome to my room.
- 53:30I live in Tahoe.
- 53:31So I guess that's something that's better than a bear.
- 53:34You know, it could have been better.
- 53:35It is better than there.
- 53:37All right.
- 53:38But yes, like this, I keep an emery any kind of what we're seeing visually here.
- 53:43You know, we'll keep a YAML file as the report output.
- 53:48So in promptimize, you have your test case or your prompt cases.
- 53:52I like test cases.
- 53:53You have an output report that says for this, you know, prompt case.
- 53:57Here's the key.
- 53:58Here's what the prompt that was actually the user input that came in.
- 54:02Here's what the prompt looked like.
- 54:04You know, what was the response or raw response from the API?
- 54:08What are all the tasks?
- 54:09How long did it run?
- 54:10So a bunch of metadata and relevant information that we can use later to create these reports.
- 54:15Saying like was the score zero or one.
- 54:18So you get the whole output report.
- 54:20Yeah.
- 54:21Okay.
- 54:22And then you also have a way to get like a report.
- 54:25I'm not sure.
- 54:26Maybe I scroll down.
- 54:27Yeah.
- 54:28It shows you how it, how it did.
- 54:29Right.
- 54:30I think that was in your, in your.
- 54:31I think at the blog post, do you see a much more?
- 54:33Yeah.
- 54:34So this one we're running the spider data set that I just, that I talked about.
- 54:39Remember it's like the Yale generated text to SQL competition, you know, corpus.
- 54:44And so here we, we, we looked at, you know, my percentage of success is 70%.
- 54:49So, you know, here you say weight and score.
- 54:51So there's a way to say, oh, this, this particular prompt case is 10 times more important.
- 54:56Another one.
- 54:57Right.
- 54:58So you can do a relative importance of weight of your different text cases.
- 55:02Now, one thing we didn't mention too, it's like all these tests are generated programmatically too.
- 55:07So that it's the same philosophy behind, you know, airflow of like, you know, it's almost like a little DSL to write your test case.
- 55:14So you could, you know, I could read from a YAML file, for instance, in the case of a, what we do with spider SQL, there's a big JSON file of all the prompts and all the databases.
- 55:22And then we dynamically generate, you know, a thousand tests, based on that.
- 55:27So you can do programmatic test definition, so more and more dynamic if you want it to be, or you could do more static if you prefer that.
- 55:35So in this case we're doing, we introduced this idea of a category too.
- 55:39So I mentioned like there's some features and prompt them as like categorizing your tests or, weights, you know, and things like that.
- 55:47So here we'll do some reporting on, on per category.
- 55:50What is the score per category?
- 55:52You can see which database is perfect.
- 55:54We're perfect.
- 55:55Well, or poorly again.
- 55:57So I could have another category that is large database, small databases and see how that, what the score is and compare reports.
- 56:05It's pretty cool that it saves the test run to a file that then you can ask questions about and write and generate this report on and rather than just running it and passing or failing.
- 56:15Right.
- 56:16Yeah.
- 56:17Or like giving the output and then having to run it again.
- 56:19Yeah.
- 56:20There's some other features around if, so you can memoize the test.
- 56:24So because it has a reports, if you like, you know, exit off of it or restart it later, you, you, it will, it won't rerun the same tests.
- 56:32If it's the same hash input, even though with AI, you might get a different answer with the same input, but at least in this case, it will say like, Hey, I reran, I'm rerunning the same prompt instead of like waiting five seconds for OpenAI and paying the tokens and paying the piper.
- 56:48You know, I'm just gonna skip that.
- 56:50So there's some logic around skipping what's been done already.
- 56:53It's not just a couple of milliseconds to run it.
- 56:56It could be a while to get the answers.
- 56:58Yeah.
- 56:59It's also like early libraries out.
- 57:00I haven't written the sub the threading for it where you can say like, Oh, run it on eight threads.
- 57:05so sure.
- 57:07With prompt demise, I think.
- 57:09And you know, the blog post is probably more impactful than the Python project itself.
- 57:14if the project takes off and a bunch of people are using it to test prompts and improve and contribute to it is great.
- 57:20But I think it's more like, okay, this is uncharted territory.
- 57:24working with what an AI type interface.
- 57:28And then it's more like, Oh, how do we, what's, how do we best do that as practitioners or as people building products?
- 57:35I think that's the big idea there, you know, then the test library, you could probably write your own.
- 57:40Like, I think for me, that was like a one or two week project.
- 57:43The weather, what I just say is like, normally, if it wasn't for getting all the help from ChatGPT on, you know, it's like, I'm create a project.
- 57:52I'm setting up my setup.py, you know, set up tools is always a little bit of a gas.
- 57:57And then I'm like, can you help me set it, create like my setup.py and then, you know, generate some code and I'm like, Oh, I want to make sure that pipe E is going to get my read me from GitHub.
- 58:09I forgot how to read the mark down and pass the stuff.
- 58:12Can you do that for me?
- 58:13And then ChatGPT generates this stuff very nicely.
- 58:16Right.
- 58:17Or I want to make sure I use my request that requirements of TXT inside my dynamically building my setup tools integration.
- 58:25Can you do that for me?
- 58:26And it's just like, bam, bam, bam.
- 58:28Like all the repetitive stuff.
- 58:29I need to function.
- 58:30It's incredible.
- 58:31Go ahead.
- 58:32Yeah.
- 58:33I kind of want to close out the conversation with that.
- 58:35I do agree that the blog post is super powerful in how it, it kind of teaches you to think about how might you go about testing, integrating with an AI and these types of products.
- 58:45Right.
- 58:46Much like TDD brought a way to think about how do we actually apply the concept just, well, I have things that I can test them with this assert thing.
- 58:54How should I actually go about building software?
- 58:56Right.
- 58:57So this is kind of that for, for AI integrated software.
- 58:59So it's certainly worth people watching.
- 59:01Let's just close it out with, you know, you kind of touched on some of those things there.
- 59:04Like, you know, how do you recommend that people leverage things like ChatGPT to help them build, build their, their apps or how to use AI.
- 59:15Just kind of amp up your software development.
- 59:20A hundred percent.
- 59:21I mean, it's, it's been a lot of people report, you know, on Twitter, people used to Google, you know, all the problems that they had while writing, you know, writing code and using a lot of stack overflow.
- 59:34I don't know what the stats on like stack overflow traffic, but if once you try working with ChatGPT to do coding, you probably don't go back to those other flows of, I don't know.
- 59:45It's like putting your error message or stack trace into Google and then go into a bunch of stack overflow link and try to make, make sense of what comes out.
- 59:54To me, it's been so much better to go just with ChatGPT.
- 59:58And there's a conversation there too.
- 59:59So say for instance, if I'm in proptimize, I needed a function to say, can you write, I wrote that function before, you know, but it's a, can you crawl a certain given folder and look for modules that contain objects of a certain class and then bring that back.
- 1:00:15And, you know, you have to use the import lib and she's a little bit of pain in the ass to write this.
- 1:00:20So it writes, you know, a function that works pretty well.
- 1:00:23I'm like, Oh yeah, I forgot to ask you to look into lists and dictionaries.
- 1:00:26Can you do that too?
- 1:00:27Then it does that in a second.
- 1:00:29It's like, I, you know, you didn't have like type hints and duck string and duck, duck test.
- 1:00:34Can you write that, you know, too?
- 1:00:36And it's a bang, bang, bang.
- 1:00:37And just like copy paste in your utils file and it works.
- 1:00:40And you save like two hours, you know, I think it would be really good at those things that are kind of algorithmic.
- 1:00:47Now you might, they might be the kind of thing that you would do on a whiteboard job interview test.
- 1:00:52Right.
- 1:00:53It just, it's just going to know that really, really solid.
- 1:00:56It actually, but it knows quite a bit about the other libraries and stuff that are out there.
- 1:01:01It's insane.
- 1:01:02Yeah.
- 1:01:03So one, one thing that I came across is I wanted, I leveraged something called length chain, which pointed to people getting interested in prompt engineering.
- 1:01:10There's a really good, well, the library length chain is really interesting.
- 1:01:14That's not perfect.
- 1:01:15It's new.
- 1:01:16It's moving fast, but I appreciate people to check it out.
- 1:01:19Also like 41,000 stars.
- 1:01:21So very, I know that's right.
- 1:01:23Is it in Python?
- 1:01:24Yes.
- 1:01:25You can do like, yeah, it's in Python too.
- 1:01:27You should talk to whoever is writing this or started this, but yeah, you can change some prompt to say like the output of a prompt will generate the next one.
- 1:01:36There's this idea of agents.
- 1:01:38There's this idea of estimating tokens before the, doing the request.
- 1:01:43There's a bunch of really cool things that it does to me.
- 1:01:47The docs are not that comprehensive.
- 1:01:49There's someone else that created, if you Google, link change, link chain cookbook, you'll find someone else that wrote what I thought was more comprehensive way to start.
- 1:02:02This one has a YouTube video and an IP one B file introduces you to the concept in an interactive way.
- 1:02:09I thought that was really, really good.
- 1:02:11But yeah, so we were trying to, I was trying to use this.
- 1:02:14I was like, oh, can you generate a bunch of like land chain really?
- 1:02:17So I was like, I don't know of a project calling chain.
- 1:02:19It was created after 2021.
- 1:02:21So that's like, I wish I could just say like, just go read the GitHub, you know, just read it all, read the docs.
- 1:02:27And then I'll ask you questions and then ChaggPD is not that great at that currently at learning things that doesn't know for a reason we talked about.
- 1:02:37Bard is much more up to date.
- 1:02:40So you can always for those projects, you know, ChaggPD might be better at Django because it's, it's old and settled and it's better at writing code overall.
- 1:02:48But Bard might be decent and pretty good for the new project.
- 1:02:52Right.
- 1:02:52If you ask advice on how to do promptimize stuff, it's like, I don't know what that is.
- 1:02:55Yeah, it's like, I've never heard of it might hallucinate too.
- 1:02:58I think if you'd go and might make sure that like, I've seen it.
- 1:03:01I prompt them.
- 1:03:02It sounds like it would be this and it just makes up stuff.
- 1:03:05So, so not that great.
- 1:03:07But yeah, absolutely.
- 1:03:08I encourage people to try, you know, for any subtasks that you're trying to do to see if it can help you at it and maybe try a variation on the prompt.
- 1:03:17And then, you know, if it's not good at it, do it the old way.
- 1:03:21But yeah, it might be better too for those familiar with the idea of like functional programming where each function is more deterministic and can be reasoned about and unit tested in isolation.
- 1:03:32So, yeah, it's going to be better at that because it doesn't know about all your other packages and modules.
- 1:03:37So really great for the utils functions are very deterministic functional.
- 1:03:41Yeah.
- 1:03:42Super great at that.
- 1:03:43Another thing is, and I don't, you tell me when we run out of time, but another thing that that was really interesting too, of, you know, bring the, some of the concept and promptimize and writing the blog post itself.
- 1:03:55Right.
- 1:03:56And things like, Hey, I'm thinking about the difference of like the properties of test driven development as it applies for prompt engineering.
- 1:04:03Here's my blog post, but can you think of other differences between the two that are very core?
- 1:04:09And, you know, can you talk about the similarities and the differences?
- 1:04:13And it would come up with like, just really, really great ideas, right?
- 1:04:17Brainstorming and just very smart at mixing concepts.
- 1:04:21I do think one thing that not a great idea is just say, write this for me.
- 1:04:25But if you've got something in mind and you're going to say, give me some ideas or how should I go?
- 1:04:30Where should I go deeper into this?
- 1:04:31And then you use your own creativity to create that.
- 1:04:34That's a totally valid use.
- 1:04:36I wouldn't feel like, Oh, I'm reading this AI crap.
- 1:04:39Right.
- 1:04:40It just, it, it brought out some insights that you had forgot to think about.
- 1:04:42And now you, now you are.
- 1:04:44Right.
- 1:04:45Or when it fails and says, say like, I got it to fail.
- 1:04:47AI is wrong.
- 1:04:48I'm smarter than it.
- 1:04:49You're like, wait, is there something I can, can I try to, you know, here's what it didn't get right.
- 1:04:54And why, like, what did I need to tell it?
- 1:04:56So you can go and edit your prompt or ask a follow up.
- 1:04:59And generally it will, it will do better and well.
- 1:05:02Yeah.
- 1:05:03I think also you can ask it to find bugs or security vulnerabilities.
- 1:05:05Yeah.
- 1:05:06Right.
- 1:05:07You like here, here's my 30 line function.
- 1:05:09Do you see any bugs?
- 1:05:10Do you, do you, do you see it?
- 1:05:12Do you see any security vulnerability?
- 1:05:14Like, yeah, you're, you're passing this straight to, you're concatenating the string into SQL or something.
- 1:05:20Yeah.
- 1:05:21The rigor.
- 1:05:21Yeah.
- 1:05:22The rigor stuff too.
- 1:05:23or like, you know, I would say writing a good doc string, writing doc tests, writing unit tests, reviewing the logic, that kind of stuff.
- 1:05:32It does type hints, right?
- 1:05:34If you, you're like me, like, I don't really like to write type hints upfront.
- 1:05:39but I'm like, can you just like sprinkle some type hints on top of that?
- 1:05:42Retrofit this thing for me.
- 1:05:43Yeah.
- 1:05:44That's it.
- 1:05:45Just make it that production grade.
- 1:05:46You know, one thing that's interesting too, of like, you know, you would think I'm a big TDD guy.
- 1:05:50Like I don't do tests.
- 1:05:52It's just not my thing.
- 1:05:54I like to write code.
- 1:05:55I don't think of like what I'm going to use the function for.
- 1:05:58And before I write it, but like generating, it's good at generating unit tests for a function too.
- 1:06:06And then I think what's interesting with prompt and nice too, is you might think you want to deterministic, what I call prompt cases or test cases, but you can say, I've written, you know, five or six of these.
- 1:06:19Can you write variations on that theme too?
- 1:06:22So you can use it to generate test cases in the case of like TDD, but also the opposite, like for, for prompt demise, you can get it to generate stuff dynamically to itself.
- 1:06:33Yeah.
- 1:06:34It's, it's pretty amazing.
- 1:06:35It is.
- 1:06:36It is pretty.
- 1:06:37Let's maybe close this out, but I'll ask you one more question.
- 1:06:39Okay.
- 1:06:40Can I do one more?
- 1:06:41Can I show one more thing?
- 1:06:42Since it's a Python podcast, if you go on my repo on that repo for prompt demise under examples, there's one called Python exam.
- 1:06:49Here we go.
- 1:06:50Something like this.
- 1:06:51Yeah.
- 1:06:52So I'm going to do this stuff right here.
- 1:06:53so say here it says, so here I wrote a prompt that asks the bot to, generate Python function.
- 1:07:01Then I sandbox it and, and bring the function it wrote into the interpreter.
- 1:07:05And then I test it.
- 1:07:06So I say, write a function that tests if a number is a prime number returns, and returns a Boolean.
- 1:07:12And then I test, I have, you know, six state test cases for it.
- 1:07:16So I write a function that finds the greatest common denominator of two numbers.
- 1:07:19Right.
- 1:07:20then behind the scene, if we won't get into the class above the class above, like basically interacts with it, gets the input, then runs the test and compiles the results.
- 1:07:30Right.
- 1:07:30So we could test, you know, how well, 3.5 compares to four.
- 1:07:35Sure.
- 1:07:36But I thought it was relevant for the Python folks on the line.
- 1:07:39So we're testing out what it is at writing Python function.
- 1:07:42Write a function that generates the Fibonacci sequence.
- 1:07:44Yeah.
- 1:07:45Up to a number of terms, right?
- 1:07:47It's easy to test.
- 1:07:48So it's cool stuff.
- 1:07:49And what was your last question?
- 1:07:52Oh, I was going to say something like, see if I see how far we could push it.
- 1:07:56I'm right.
- 1:07:57A Python function to use requests and beautiful soup to scrape the titles of episodes of talk Python to me.
- 1:08:08Oh yeah.
- 1:08:09And then, yeah, it is.
- 1:08:11And if you don't have a, you know, one thing that's a pain in the butt for a podcast people is to write the, like what, what all we talk about.
- 1:08:17So you use another AI to get the transcripts.
- 1:08:20It's like, can you write something that's going to leverage this library to transcript the library, summarize it and publish it back on the, with SEO in mind.
- 1:08:30Yeah, it's, it's really quite amazing.
- 1:08:33It went through and said, okay, here's a function and it knows talkpython.fm/episode/all.
- 1:08:38Use H, get the title.
- 1:08:39And let's, let's just finish this out, Max.
- 1:08:42I'll throw this into a.
- 1:08:43An interpreter.
- 1:08:44See if it runs.
- 1:08:45An interpreter and I'll see if I can get it to run.
- 1:08:47Hey, you know, what's really interesting too, is like, you can give it a random function.
- 1:08:51Like you can write a function and say like, if you know, write a, write a certain function that does certain things.
- 1:08:57And you say, if I give the, this input to this function, what is it going to come out of?
- 1:09:02And it doesn't have an interpreter, but it can interpret code like you and I do.
- 1:09:07Right.
- 1:09:08Like, like an interview question of like, Hey, here's a function.
- 1:09:11If I input a three as a value, what's going to come, what's going to return.
- 1:09:14So it's able to do it, follow the loops, you know, follow the if statements and basically just do a logical.
- 1:09:20Yeah.
- 1:09:21Yeah.
- 1:09:22Another thing I think would be really good is to say, here's a function.
- 1:09:25Explain to me what it does.
- 1:09:26Oh yeah.
- 1:09:27It's super great at that.
- 1:09:28It's great at that for SQL too.
- 1:09:29Here's a, there's a stupid long SQL query.
- 1:09:31Can you explain to me?
- 1:09:32No, it does.
- 1:09:33It's like, the explanation is on, can you just summarize that 300, you know, in a hundred words?
- 1:09:37Yeah.
- 1:09:38Let's go step by step.
- 1:09:39Let's go step by step.
- 1:09:40What's this do?
- 1:09:41But yeah, I mean, maybe a closing statement is like, this stuff is changing our world.
- 1:09:46Like for me, I'm interested in how it's changing, how we're building products, you know, but the core things as a, as a data practitioner, as a Python expert.
- 1:09:55As a programmer, it's really changing the way people work day after day faster than, than, than we all think.
- 1:10:04and, and across a lot, like, you know, you might understand pretty well, it's changing your daily workflow as an, as a software engineer, but it's changing people.
- 1:10:12Like people's workflow to do chemistry or like in every field.
- 1:10:17There's a lot we can leverage here.
- 1:10:19if you use it well.
- 1:10:21Right.
- 1:10:22Yeah.
- 1:10:23And apply it to, you know, whatever, vertical you want to think of it's, it's doing the same thing there.
- 1:10:28Right.
- 1:10:29Medicine all over.
- 1:10:30Yeah.
- 1:10:31A hundred percent.
- 1:10:32Well, let's, let's call it a color up.
- 1:10:35I think we're, we're out of, out of time here.
- 1:10:37So, really quick before, before we quit PI PI package to recommend, maybe something AI related that you found recently.
- 1:10:44Like all this thing's cool.
- 1:10:45People should check it out.
- 1:10:46prompt to my eyes.
- 1:10:47I think it would be, you know, something to check out.
- 1:10:49I think there's something called future tools that you could try to navigate there, but it's, it shows like all of the AI powered tools that are coming out and it's, it's hard to keep up.
- 1:10:59Yeah.
- 1:11:00Yeah.
- 1:11:00I think I have seen that.
- 1:11:01Yeah.
- 1:11:01And then, if you, if you want to keep up on a daily with what's happening in AI, there's, you know, TLDR AI, they have like a DL with their relevant list for the day.
- 1:11:12I think that's a, it's, it's hard to stay on to, I prefer like their weekly digest of what's going on in AI.
- 1:11:19It's like, just a stream of information.
- 1:11:23yeah.
- 1:11:24It's just kind of dizzying and it's like, oh, this new model does this.
- 1:11:27Like I've got to change everything to that.
- 1:11:28And then, then something else.
- 1:11:30If you update the correct course too often, and it's just like, you know, do nothing.
- 1:11:36Cause you're like the foundation, the foundation is shifting too fast on through you.
- 1:11:40So yeah, absolutely.
- 1:11:41Well, very cool.
- 1:11:42All right.
- 1:11:43And then final question, you know, right.
- 1:11:45Supply the code, what editor using these days?
- 1:11:47I'm a Vim user.
- 1:11:48Yeah.
- 1:11:49I, I know it's not the best.
- 1:11:51I'd like, I know all the limitation, but it's like muscle memory.
- 1:11:54And, I, I, I'm a UX guy now working on supersets.
- 1:11:58I do appreciate the development of all the new IDEs and the functionality that they have.
- 1:12:04I think it's, it's amazing.
- 1:12:06And it's just like, for me, it's all like, I know all my bash commands and big commands.
- 1:12:11Absolutely.
- 1:12:12All right.
- 1:12:12Well, Max, thanks for coming on the show, helping everyone explore this wild new frontier of AI and large language models.
- 1:12:19And, you know, exploring while we're exploring, while we're still relevant, because I don't know how long we're going to be relevant for.
- 1:12:26So yeah.
- 1:12:27Yeah.
- 1:12:28Yeah.
- 1:12:29Enjoy.
- 1:12:30Enjoy while we can, right.
- 1:12:31Get out there.
- 1:12:32Either control the robots or be controlled by them.
- 1:12:34So get on the right side of that.
- 1:12:36All right.
- 1:12:37Thanks again.
- 1:12:38Thank you.
- 1:12:39This has been another episode of talk Python to me.
- 1:12:43Thank you to our sponsors.
- 1:12:44Be sure to check out what they're offering.
- 1:12:46It really helps support the show.
- 1:12:47The folks over at jet brains encourage you to get work done with PyCharm.
- 1:12:52PyCharm professional understands complex projects across multiple languages and technologies.
- 1:12:57So you can stay productive while you're writing Python code and other code like HTML or SQL.
- 1:13:03Download your free trial at talkpython.fm/donewithpycharm.
- 1:13:08Listen to an episode of compiler, an original podcast from Red Hat.
- 1:13:13Compiler unravels industry topics, trends, and things you've always wanted to know about tech through interviews with the people who know it best.
- 1:13:20Subscribe today by following talkpython.fm/compiler.
- 1:13:24Want to level up your Python?
- 1:13:26We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:13:30Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:13:35And best of all, there's not a subscription in sight.
- 1:13:38Check it out for yourself at training.talkpython.fm.
- 1:13:40Be sure to subscribe to the show.
- 1:13:42Open your favorite podcast app and search for Python.
- 1:13:46We should be right at the top.
- 1:13:47You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:13:56We're live streaming most of our recordings these days.
- 1:14:00If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at /talkpython.fm/youtube.
- 1:14:08This is your host, Michael Kennedy.
- 1:14:10Thanks so much for listening.
- 1:14:11I really appreciate it.
- 1:14:12Now get out there and write some Python code.
- 1:14:14Thanks for listening.
- 1:14:15Thanks for listening.
- 1:14:15Thanks for listening.
- 1:14:16Thanks for listening.
- 1:14:17Thanks for listening.
- 1:14:18Thanks for listening.
- 1:14:19Thanks for listening.
- 1:14:20Thanks for listening.
- 1:14:21Thanks for listening.
- 1:14:22Thanks for listening.
- 1:14:23Thanks for listening.
- 1:14:24Thanks for listening.
- 1:14:25Thanks for listening.
- 1:14:26Thanks for listening.
- 1:14:27Thanks for listening.
- 1:14:28Thanks for listening.
- 1:14:29Thanks for listening.
- 1:14:30Thanks for listening.
- 1:14:31you
- 1:14:31you
- 1:14:32Thank you.