SuperAPI AI Directory

Prompt Engineering: From Words to Art

This article introduces the application of prompt engineering in AI art generation and proposes five cross-model core principles: give direction, specify format, provide examples, evaluate quality, and divide labor. Using tools such as Midjourney as examples, it explains how to improve the controllability and quality of image generation through detailed descriptions, format definitions, example references, quality evaluation, and multi-step decomposition, and provides specific operational suggestions and points to note.

Open website

About this tool

This content revolves around "Prompt Engineering: From Text to Art" and is aimed at users of AI image and text generation tools (such as Midjourney and ChatGPT), introducing how to obtain reliable and desired generation results through a systematic prompting method.

I. Purpose and Background The article points out that AI art and prompt engineering are becoming an important skill. The output of generative AI is non-deterministic and sometimes randomly produces undesirable results, so prompts need to be optimized to stabilize output. The author proposes the "five prompting principles" as a cross-model, long-term effective working framework, rather than relying only on short-term tricks.

II. The Five Principles

  1. Give direction: describe the desired style in detail, or reference relevant people/characters. For image generation, this is especially important because tools such as Midjourney are familiar with various artists and art styles. Seed keywords can be used to bias the latent space searched by the AI, thereby influencing the results. If you lack art vocabulary, you can use Midjourney's Describe function to upload an image you like and obtain four prompts that may generate similar images.

  2. Specify format: define the rules to follow and the structure of the response. This is especially important for integrating AI into production tools, because inconsistent formats affect reliability. Text models can output structured data such as JSON and YAML; image models can output any format such as photos, oil paintings, and ice sculptures. Sometimes format and style conflict, requiring experimentation. The author also developed a free visual prompt builder tool that lists common formats and styles.

  3. Provide examples: insert diverse test cases that correctly complete the task. Examples can significantly improve response quality, but be careful that the AI may overlearn from the examples, leading to reduced creativity. Providing examples is similar to "fine-tuning" the AI. If prompt length is limited, LlamaIndex and Pinecone DB can be used to inject context. In the image example, the author used a still from the film The Great Gatsby as a reference, and by adding after the prompt:: 0.1to reduce its weight by 90%. Attention must be paid to copyright issues.

  4. Evaluate quality: identify errors and score responses, and test which factors drive performance. Due to the randomness of LLMs, robustness varies across different prompts. It is recommended to run prompts multiple times, and even compare with other LLMs. LangChain can be used to enable tracing and import results into LangSmith for analysis. For image generation, you can try a large number of different words and manually inspect the results, or use Midjourney's Shorten feature to analyze which parts of the prompt are most important.

  5. Divide labor: split tasks into multiple steps and link them together to accomplish complex goals. Due to prompt length limits (about 4k tokens), it is recommended to break tasks into multiple prompts. For example, first have the model generate options, then have the model evaluate those options according to criteria. Tools such as Langchain can connect multiple operations in sequence. Different models each have their strengths; for example, DALL-E 3 is good at text in images and composition, Midjourney has excellent aesthetics and is good at fantasy styles, and background.bg is good at removing backgrounds.

  6. How to use and applicable scenarios The article provides ready-to-use prompt engineering templates and explains step by step how the templates work. It is suitable for scenarios involving creative work such as art creation, design, and writing with AI. The author also shares a case study of using AI art to illustrate their own book.

  7. Limitations and precautions Prompt engineering techniques may quickly become outdated. OpenAI CEO Sam Altman believes that in five years prompt engineering (referring to finding "magic words") may no longer be needed, but "the quality of ideas and understanding what you want" will always matter. Therefore, the author emphasizes that the five principles are timeless and can transfer across models. In addition, when using examples, pay attention to copyright, and be cautious with commercial use. Models differ in capabilities and limitations, requiring experimentation and evaluation.

  8. Other information The author offers the course "Prompt Engineering Principles: ChatGPT & DALL-E" on Udemy, and was commissioned by O'Reilly to write a related book, expected to be published in 2024; the unedited version is available for pre-release online. For more learning resources, see Vexpower's prompt engineering course.