If you are looking at using artificial intelligence and getting an output that you are happy with for your business or life then you will need to understand what prompt engineering is. Prompt engineering in terms of artificial intelligence is the instructions that you give the large language model before you hit generate. Think of prompt engineering as providing artificial intelligence with instructions.
Not all large language models work in the same way however and you may find that simply providing instructions does not give the AI adequate information to work with. This means you may have to go a bit deeper with your instructions or prompt. Think of the AI like a five-year-old, you give it the instructions to do something and if you don’t show it exactly what you want, it will do its best but the output can go in any random direction.
This is where patterns come into the equation and if you construct your prompt in a way where patterns are apparent, then you are halfway to becoming a prompt engineering professional in artificial intelligence. Without a pattern, the chance of randomness or the AI presenting the information that you are trying to get it to generate increases massively.
Say you are trying to make a prompt that answers questions on trivia but you want the answers to be in a sentence format each and every time you ask a question. You could provide a prompt with instructions telling the AI that it is great at trivia and then ask a question like “What is the capital city of Thailand?”, hitting generate on such a question might get the answer of “Bangkok” which is correct but you may be looking for that answer to be constructed in a sentence like; “The capital city of Thailand is Bangkok.” By providing a few examples of questions and the output you expect, you can really tune the AI to provide you the formatted output you expect.
This is a very basic example of how prompt engineering can work in your favor when building with AI large language models. You can see the demonstration of how we build out a trivia bot in Riku here.
If you want the AI to really drill down on the topic that you are providing examples for then the answer would be as many as possible. There are limitations of course with prompt engineering which mainly occur due to the token limits and not being able to put longer text into a prompt successfully and this is something that fine-tuning can solve. If you are interested in learning how to fine-tune with no-code you can read more here.
What we like to do here at Riku when we build out prompts is to start giving examples in the prompt and then letting the AI takeover with the actual prompt construction, by building out prompts with the assistance of AI as part of the process, you can see when the AI is providing outputs that you are happy with and then save your prompt engineering efforts ready to be used in production or via a share link or any integrations. It is pretty simple.
Image generation works in a slightly different way to text-based AI and every time you provide the image AI instructions as to what you want to create, you are in effect prompt engineering. With image AI instead of providing instructions and examples via a pattern that you want the AI to follow, you are more looking to be a master in describing all elements of the image you want to see. Prompt engineering with stable diffusion, Midjourney, or DALL-E works in mostly the same way but there can be specific quirks for each image generation model.
Firstly, you want to describe what you want to see such as; “Husky Puppy sipping milk” but then you can go deeper into describing the scenario, is this in a field, on a mountain, or in a snowy setting? Write it! You can then further manipulate the style by saying if you want to see “a photo of” or “digital art” or “3d render”, all of these tags can help you in getting the image you want to see. If the image you want is using a specific style then you can add this, styles can be something as simple as saying “synth wave”, “cyberpunk”, or “futuristic” but you can also add specific artist styles such as “in the style of Van Gogh”, “in the style of Monet” etc.
Describing what you want to see is the easy part, adding and tweaking all of these individual tags to really refine the art creation is where the magic happens and when you will really start to see amazing creations when prompt engineering with Midjourney, stable diffusion, or DALL-E. There are some excellent resources that exist that go even deeper into this. You can check out this guide available for free which goes into more details about prompt engineering with DALL-E.
If you haven't checked out image generation in Riku yet, what are you waiting for? It is really epic and has some settings that we don't see anywhere else for you to enjoy when generating. Read more here.
Once you have crafted a prompt in the best possible way using all of the tips shown for prompt engineering with AI, you may still not get the output you expect and this can lead to much head scratching. Oftentimes, this is caused by the settings not being set correctly. What is temperature? What is top p? How do I know how to set output tokens correctly. This is worthy of a blog post all on its own but we'll try to give a quick crash course here.
Temperature controls creativity, if you want the AI to produce a more creative output such as for writing descriptions, fiction or just generally giving you ideas on what should come next, then having a high temperature is essential. If you are looking for more controlled outputs where it stays on topic and is more "matter of fact" with the output then set a lower temperature.
If you are modifying temperature, then the general rule of thumb is to not touch the top p setting. These settings work slightly differently, but if you modify one, don't modify the other. A quick hack for getting the ideal output tokens is to look at the examples you provide in your prompt, find the longest one and copy it to the clipboard. Paste it in a website like Wordcounter and make note of the character total. Open up a calculator, and divide this number by 4. This is the approximate tokens for that longest example so you can add that as your output token total (maybe add 20-30 for good measure).
We may be a little biased here at Riku but we created the company to solve this issue for ourselves first of all. There are so many large language models with more coming out all the time and it can be confusing to know what prompt was built with what technology. If you are anything like me, you'll have a mess of random text files saved on your computer, and keep kidding yourself that it is organized.
With Riku, we're all about empowering you to build, experiment and deploy AI through all of the best large language models in a centralized hub. We make transitioning from one technology to another super simple so if you are using OpenAI for a prompt and want to see how it works in AI21, you can do that. You can save all your creations and then use them in production or share them with your team.
Riku is all about making a comfortable environment to learn, build and explore the latest and greatest in AI and our growing community of AI enthusiasts is here to cheer you on as you go deeper into your journey. If that sounds like fun, consider signing up at Riku.AI today.