Meta prompt engineering
Credit to Jake Hills, Unsplash

Meta prompt engineering

It turns out that ChatGPT is a pretty awesome prompt engineer! I guess that shouldn't be too much of a surprise?

It took me a little bit of time to figure that out. Before my moment of realisation, I'd gotten into a workflow pattern where I had set aside my Friday afternoons as working from home for tough prompt engineering challenges, in order to give them my undivided attention.

I was in a bit of a hyper-focused mode, full of intent and purpose, and treating ChatGPT like an obedient AI machine, giving it instructions and wanting something out. I come from a developer background, and I thought about ChatGPT as a more modern type of compiler: code in → bytecodes out; so, prompt in → magic out.

Paradoxically, that kind of intense focus had actually been what had been getting in the way. Things got easier once I relaxed.

After one day of going around in circles and trying to fine tune a prompt, I reached frustration point. I wanted a particular output – it was a generative AI project I was working on – and I'd put a lot of effort into perfecting the tone of voice to match the rest of our content (written by professional writers), but every time I fixed one thing I broke another.

This was something that happened to us often in the AI team when we first started figuring out how to develop prompt engineering skills in early 2023: fix one thing, and break another. That rarely happens now, partly because we've switched from GPT-3.5 to 4 for all generative work, and partly because we approach prompt development in a different way.

There was one moment when my way of working with ChatGPT flipped, and from that point on this feeling of fighting with the technology fell away.

Flipped perspective

I had been treating ChatGPT as a machine that had to obey my instructions. I was trying to refine my commands – fiddling with verbs and adjectives – so that I could get what I wanted out of it.

As a general rule, I've found that trying to put tight bounds on ChatGPT puts a bit of a metaphorical squeeze on it, and that compression can cause something else to pop out of alignment. It feels like Whack-a-Mole. It can be frustrating.

The alternative to that is to give ChatGPT as much context as you can, and refrain from setting so many bounds or rules. It is somewhat a leap of faith, especially with generative AI when users will get to see the AI output without intermediating human curation; but, counter-intuitively, this approach is the one that most consistently produces highly-aligned output.

That moment of realisation came for me when I was trying to understand a complex open source prompt that contained no imperative instructions, only declarative descriptions of the parameters of the task at hand. It's a novel approach and not one I'd seen before; and I couldn't wrap my head around how it worked when there was no focal point of control.

It was the wonderfully-named open-source Mr Ranedeer project ??. It's a novel AI tutor, constantly evolving, and I would recommend reading it to intermediate prompt engineers as a different way to think about prompting. You can see the prompt yourself here.

It's a monster of a prompt and it's written in an unusual, albeit effective, pseudocode style. (To execute it, you'll need to have ChatGPT with the Code Interpreter beta feature turned on.)

I was still in the phase of trying to understand prompt engineering principles and to gain some skills myself. The thought occurred to me that I had an expert on hand! I gave ChatGPT a prompt like the following and copy pasted in the Mr Ranedeer prompt:

I have a prompt I'm trying to understand how it works. May I share it with you? Please just read it and then I'll ask you some questions.

AI courtesy

You might notice I said please and "may I" to ChatGPT. I know that looks a bit odd, but holding that idea in my head – that I'm working with a partner and seeking their assistance – helps me approach the collaboration in the right way, and also elicits similarly collegial responses from the AI. If I have to do 6-8 hours of prompt engineering, having these kind of courteous exchanges actually helps me not get too fatigued. It provides a bit of mental space that barking out "do this" and "do that" commands doesn't.

I recently thanked it after a long day of doing good work together and it said this to me:

No alt text provided for this image

Yes, I know it's just tech. But, even still, my nice interactions with ChatGPT really do make me feel like I have a little robot buddy that I'm doing good work with ??. I enjoy my time in collaboration. My time spent with ChatGPT feels rewarding, and I feel relaxed and unhurried. We do good work together.

ChatGPT as prompt reviewer

If I want to talk about prompts with ChatGPT rather than giving it prompts to respond to, I find I need to be a little more directive that I usually am.

I don't want extraneous pre- and post-amble. So I say something like "I have a ChatGPT prompt to share with you. Please read it, and then I'll ask you some questions about it. Here it is:"

I put that in one prompt followed by the prompt to be reviewed itself (wrapped in some curly braces so it can see where it starts and ends), and then "Please acknowledge you have read it."

No alt text provided for this image

Its response should be something like "I've read the prompt you provided. Please proceed with your questions."

Now you can enter into a collaboration with ChatGPT to improve it. Not needed on a prompt this size but, for production prompts that are doing a lot of heavy lifting, this form of "interactive IDE" can be quite helpful.

This starting prompt elicits a business-like approach from ChatGPT Pro. It has many observations and practical suggestions if you approach it in an open-ended conversational way.

Going meta

This turning around of perspectives was a bit of a lightbulb moment ??.

Maybe we have to stop using this word now that Facebook has renamed itself? It did feel very meta to be talking about a prompt with ChatGPT and saying things like "I have a prompt designed for ChatGPT. Can we review it together?" But this is actually how I do most of my prompt engineering now.

Sometimes I ask ChatGPT to write the whole prompt, especially if we are using GPT-3.5 for mechanical transformations of textual data. GPT-4 is able to write great prompts that often require little, if any, fine tuning.

I feel like I know what the inside of a recursive function looks like: I don't write code to do a transformation; it's 2023, so I use a ChatGPT prompt instead. But... I don't write the prompt; I ask ChatGPT to write it for me.

Here's an example... ChatGPT most naturally produces output in enhanced markdown format. Our prompts are written to support that form of output. In multi-step prompts, we might have instructions like "Output a markdown heading 2 of 'Welcome'."

For generative AI products, output is requested as markdown, we use ChatGPT to do the translations and localisations, we then transform the output from markdown to JSON, and then we render the JSON to the UI in web or mobile.

Transforming markdown to JSON

To do that we need to transform markdown to JSON. That's something that can be done quickly and inexpensively by GPT-3.5. We could do it with code (but then we'd have to write it), so instead we just push it through GPT-3.5.

We have a prompt for that, but we never wrote that prompt; we just asked GPT-4 for a prompt to do that, and here it is:

No alt text provided for this image

It's short and reliable. We ask ChatGPT to produce all its output in markdown (the final line of our prompts is "All output in markdown.") This prompt above transforms ChatGPT markdown output into parseable and renderable JSON.

So our runtime process in production for generative AI is that we:

  • post a prompt to the ChatGPT API (GPT-4) saying we want all output in markdown
  • get the response
  • send that response to GPT-3.5 prefixed with the transformation prompt above
  • receive the original GPT-4 output, but in JSON format
  • render that to the UI

There's an important reason why we in the AI team at GoodHabitz don't do markdown to JSON in the base prompt, or ask for output directly in that format (full details here). TL;DR: doing so can make it lose its gen-AI charm (and drop its 'tone of voice' training). Just as with humans, it's hard to be charming and funny if everything you want to say has to be in JSON.

Prompt engineering collaborator

That meta approach of working with ChatGPT as part of the workflow of developing a new prompt has become the norm for us.

ChatGPT is a prompting expert who can provide insight into prompts and make suggestions for improvements.

Sharing a prompt with it (and asking it to read it, but not execute it), and then asking questions like the following can produce useful and actionable insights:

  • How can I improve this prompt?
  • How can I make it shorter?
  • What do you like about it?
  • Does it have any gaps or cases it doesn't handle?
  • Could you explain it back to me?
  • Can you rewrite it for me better?

For complex prompts, this can be invaluable input.

No alt text provided for this image

When I have a simple task that GPT-3.5 could perform, I just ask GPT-4 to write the first version of the prompt for me. You might get just what you wanted, or some inspiration, or something you can edit and use... or maybe nothing you can use. But crank up the temperature parameter, rephrase your request and have another go! ??

Workflow steps

That brings us to our workflow for AI-powered activities:

  • Develop an initial prompt. I usually do this in ChatGPT Pro unless I might want to tweak some of the other parameters (like the penalties or temperature). I use ChatGPT Pro instead of the playground for the simplest reason that it's slightly lazier to type ? rather than ?-?. Also, I'm a heavy duty user, and we pay per token in the playground. Save some pennies.
  • Collaborate with GPT-4 to improve it. Once I have a roughly working prompt, I engage GPT-4's expertise as a prompt engineering expert.
  • Iterate over the design. We use ChatGPT Pro (or the platform playground) as our "Prompt Engineering IDE". We involve our colleagues and ask them to imagine a slick web or mobile user interface around the interactions. The nice thing about ChatGPT's interface (as opposed to the playground) is that it renders markdown with nice looking headings and bold/italics. That's actually helpful when you're talking to non-technical colleagues. It's less of the ChatGPT "wall of text" to have to imagine an interface in front of.
  • Build it into into a beta product. It can be initially helpful to run through a new prompt / AI product with a colleague in ChatGPT Pro, but you're limited to one-on-one interactions. To get more feedback from a larger audience, you'll need to productionise it into the your product. We use feature flags so that only staff can see the new AI feature.
  • Add metrics, reviews and feedback. Next, we involve our UX Research team to design metrics, review forms, feedback methods. That data – both qualitative and quantitative – helps us gain useful feedback from the next step...
  • Select a beta audience. We use feature flags to enable the new AI feature with a few selected clients who understand that this is a feature in beta testing and who want to partner with us in exploring how this might be effective in increased learning outcomes for their employees.
  • Iterations of improvement until the product is ready for a full audience.

I should mention regarding the last step that we are – like everyone – currently limited by the maximum token throughput of GPT-4. As exciting as these new product features are, we're needing to keep the audience who can experience them small. The API for GPT-4 still has throughput caps (number of tokens per minute), as does the platform playground.

As a developer you think immediately of load balancing your demand... but it's not a practicable solution to have n platform API accounts and load balance them because you're limited to how many accounts you can have on the same corporate credit card and then there's the whole business of applying for each of these accounts to go on the waitlist to be granted GPT-4 access (months rather than weeks).

Flowing, not forcing

We've learned a lot about prompt engineering this year, most of it from trial and error. ChatGPT is itself too much of a moving target for any book or reference manual to be helpful.

I've seen GPT-4 change enormously just in the last six months. There was a major update of GPT-4 last week (2 Aug) and, within half an hour on the Monday morning, I felt like I was collaborating with a completely different partner. I slacked a colleague that 'GPT is on fire this morning! ??', and he let me know that there had been a major update in the previous week. How can you keep up with that other than through daily interactions?

No alt text provided for this image
The Great Wave off Kanagawa by Hokusai

I once described ChatGPT as a tsunami, a huge wave that has been unleashed upon the world. We at GoodHabitz have chosen to surf the wave rather than have it crash upon us; we're embracing it in ways that will transform our product radically over time, and also in empowering our staff with tools that will allow them to perform their tasks much more efficiently (and enjoyably, by removing tedious tasks).

But I think my preferred metaphor has shifted now. There's a river; it's flowing and changing. We're a part of its flow now. We're adapting our ways of working, finding the ways that this technology enables us to work quicker, and to off-load mundane tasks. We've learned how to engage its creativity and humour, and add ours to the mix. We are discovering how this tool supports us in being really good at what we do; in a way, to help us better understand what it is that makes us unique – when stripped of the busywork – what makes us unique and special?

I don't see AI tech any more as something outside threatening us – a threat I need to respond to – but as a tool for collaboration that enables us to bring more flow and ease to our existing workflows. When we train it on our values and style (through existing content), we find a tool that can take the work of human authors and extrapolate that into new scenarios. That's a stepping stone and starting place that aids the creative process.

I can only speak for myself, but I feel I have a creative AI companion in exploring new territory that was previous closed to me.

Christian Kaufmann

Energy Economist & Modelling Professional | Planning Net Zero with SSEN Transmission ?? | Family-time enthusiast

10 个月

Bravo, Steve! Six months well spent. Looking forward to hearing more about your project!

回复

要查看或添加评论,请登录

社区洞察