ChatGPT prompt word project for Java developers (6)

When building applications with GPT, we usually don't just use the prompt words we wrote the first time, but improve them through continuous iteration to find the prompt words that are most suitable for the task we want to achieve. While there may be some usability for first-time written prompts, what matters most is the process of finding the right prompt for your application, not whether the first prompt works. Therefore, we need to constantly try and improve in order to find the best prompt words.

What is the process of building prompt words for an application using GPT? First, we need to have an idea and a task to accomplish. Next, we can try to write a clear and specific cue word to give the system time to think, if needed. Then, we can run it and see the result. If the first result is not good enough, then we can go through an iterative process to find out the problem, such as the instruction is not clear enough, or the algorithm has not enough time to think. That way, we can keep refining ideas and hints, looping through them multiple times until we get one that works for your app.

Personally, I don't pay much attention to articles that claim to have 30 perfect cue words, because I don't think there is a perfect cue word for every situation. More importantly, we need to develop a suitable prompt word process for our specific application.

example

We'll use an example task: write a mobile phone description using a technical specification. The technical specification lists the appearance, capacity, size and weight of the mobile phone, etc., as follows:

public final static String iPhone14 = "外观\n"
        + "- 午夜色\n"
        + "- 紫色\n"
        + "- 星光色\n"
        + "- 红色\n"
        + "- 蓝色\n"
        + "- 黄色\n"
        + "\n"
        + "超瓷晶面板、玻璃背板搭配铝金属边框\n"
        + "\n"
        + "容量\n"
        + "- 128GB\n"
        + "- 256GB\n"
        + "- 512GB\n"
        + "\n"
        + "尺寸与重量\n"
        + "- 宽度: 71.5 毫米 (2.82 英寸)\n"
        + "- 高度: 146.7 毫米 (5.78 英寸)\n"
        + "- 厚度: 7.80 毫米 (0.31 英寸)\n"
        + "- 重量: 172 克 (6.07 盎司)\n"
        + "\n"
        + "显示屏\n"
        + "- 超视网膜 XDR 显示屏\n"
        + "- 6.1 英寸 (对角线) OLED 全面屏\n"
        + "- 2532 x 1170 像素分辨率,460 ppi\n"
        + "- HDR 显示\n"
        + "- 原彩显示\n"
        + "- 广色域 (P3)\n"
        + "- 触感触控\n"
        + "- 2000000:1 对比度 (典型)\n"
        + "- 800 尼特最大亮度 (典型);1200 尼特峰值亮度 (HDR)\n"
        + "- 采用防油渍防指纹涂层\n"
        + "- 支持多种语言文字同时显示\n"
        + "\n"
        + "显示屏采用曲线优美的圆角设计,四个圆角位于一个标准矩形内。按照标准矩形测量时,屏幕的对角线长度是 6.06 英寸 (实际可视区域较小)。\n"
        + "\n"
        + "芯片\n"
        + "- A15 仿生芯片\n"
        + "- 6 核中央处理器,具有 2 个性能核心和 4 个能效核心\n"
        + "- 5 核图形处理器\n"
        + "- 16 核神经网络引擎\n"
        + "\n"
        + "摄像头\n"
        + "- 1200 万像素主摄:26 毫米焦距,ƒ/1.5 光圈,传感器位移式光学图像防抖功能,七镜式镜头,100% Focus Pixels\n"
        + "- 1200 万像素超广角:13 毫米焦距,ƒ/2.4 光圈和 120° 视角,五镜式镜头\n"
        + "- 2 倍光学变焦 (缩小);最高可达 5 倍数码变焦\n";

Let's say we want to use this technical specification to help the marketing team write descriptions for an online retail website. Therefore, we wrote the following prompt words:

public static void main(String[] args) {
    
    
    String prompt = "你的任务是帮助营销团队根据技术说明书为手机的零售网站创建描述。\n"
            + "请根据三个反引号之间的技术说明书编写手机描述。\n"
            + "```%s```";
    String response = getCompletion(String.format(prompt, iPhone14));
    System.out.println(response);
}

Run it to see the result:

The phone is available in a variety of colors, including midnight, purple, starlight, red, blue, and yellow. It adopts the design of ultra-ceramic crystal panel, glass back panel and aluminum metal frame, which has a stylish and beautiful appearance.
The phone is available in three capacities, 128GB, 256GB and 512GB. It measures 71.5mm wide, 146.7mm high, 7.80mm thick and weighs 172 grams.
The phone uses a 6.1-inch OLED full screen with a resolution of 2532 x
1170 pixels, HDR display and wide color gamut, tactile touch, a contrast ratio of up to 2000000:1, a maximum brightness of 800 nits, and a peak brightness of 1200 nits.
The screen adopts anti-oil and anti-fingerprint coating, and supports simultaneous display of multiple languages. The four rounded corners of the screen are located in a standard rectangle with a diagonal length of 6.06 inches.
The mobile phone uses the A15 bionic chip, which has a 6-core central processing unit, a 5-core graphics processor and a 16-core neural network engine.
The phone's camera includes a 12-megapixel main camera and a 12-megapixel ultra-wide-angle camera, which supports 2x optical zoom and up to 5x digital zoom.
The main camera has a 26mm focal length, ƒ/1.5 aperture, sensor-shift optical image stabilization, seven-element lens and 100% Focus
Pixels. The ultra-wide-angle has a 13mm focal length, ƒ/2.4 aperture and 120° viewing angle, and a five-element lens.

GPT seems to do a good job of writing a description, and does a good job of doing what I asked it to do, which is to write a description of a mobile phone from a technical specification. But when we saw this, it felt a little long. Maybe we want to make it shorter. Try giving better prompt words with "up to 100 words" to expect a shorter phone description length.

public static void main(String[] args) {
    
    
    String prompt = "你的任务是帮助营销团队根据技术说明书为手机的零售网站创建描述。\n"
            + "请根据三个反引号之间的技术说明书编写手机描述。\n"
            + "最多使用100个字。\n"
            + "```%s```";
    String response = getCompletion(String.format(prompt, iPhone14));
    System.out.println(response);
}

Run it to see the result:

Available in a variety of colors, the phone features a Ultra-ceramic panel, glass back and aluminum frame.
The capacity is available in 128GB, 256GB and 512GB. The screen is a 6.1-inch OLED full screen, which supports HDR display and simultaneous display of multiple languages.
The chip uses the A15 bionic chip, and the camera has a 12-megapixel main camera and an ultra-wide angle, supporting 2x optical zoom and 5x digital zoom.

That actually looks like a better short description, introducing a phone. Let's check the length of the phone description again, there are 137 characters. GPT is okay, but not great, at adhering to very precise word limits. But it's actually not bad.

In the process of perfecting the text of the website, we may find that this website does not sell to all consumers, but focuses on selling to photography enthusiasts, because they pay more attention to the camera of the mobile phone. Therefore, we need to further modify the prompt words to more precisely describe the camera of the mobile phone to meet the needs of the target audience.

public static void main(String[] args) {
    
    
    String prompt = "你的任务是帮助营销团队根据技术说明书为手机的零售网站创建描述。\n"
            + "请根据三个反引号之间的技术说明书编写手机描述。\n"
            + "描述是为摄影爱好者准备的,所以重点是手机的摄像头。\n"
            + "最多使用100个字。\n"
            + "```%s```";
    String response = getCompletion(String.format(prompt, iPhone14));
    System.out.println(response);
}

Run it to see the result:

For sharper and more vivid photos, this phone's camera is the best choice for you. Both the main camera and the ultra-wide-angle camera have 12 million pixels, and support 2x optical zoom and 5x digital zoom. The appearance is available in a variety of colors, equipped with a super-ceramic panel, a glass back panel and an aluminum metal frame, and the capacity can reach 512GB.

It looks good, and we can learn about the megapixels and zoom of the phone's main and ultra-wide cameras. By changing the cue word, we can make it more focused on the specific features we want. When I see this, we might decide to also include the weight of the phone at the end of the description. So, maybe we can improve this hint further.

public static void main(String[] args) {
    
    
    String prompt = "你的任务是帮助营销团队根据技术说明书为手机的零售网站创建描述。\n"
            + "请根据三个反引号之间的技术说明书编写手机描述。\n"
            + "描述是为摄影爱好者准备的,所以重点是手机的摄像头。\n"
            + "在描述的最后包括重量。\n"
            + "最多使用100个字。\n"
            + "```%s```";
    String response = getCompletion(String.format(prompt, iPhone14));
    System.out.println(response);
}

Run it to see the result:

Take clearer and more vivid photos, 12-megapixel main camera and ultra-wide-angle camera, 2x optical zoom, up to 5x digital zoom. The phone weighs 172 grams.

What we have just seen is a short example of the iterative cue word development that many developers will go through.

Summarize

When trying to use prompt words, sometimes we find that the prompt words don't quite meet our needs. At this time, we need to consider how to clarify our instructions, or give more room for thinking, so as to get closer to the results we want. However, being a successful cue engineer isn't about knowing the perfect cue, it's about having a good development process to develop cue that works for our application.

In this article, we only provide an example of how to develop cue words. For more complex applications, we may need to use multiple examples, say 10, 50, or 100 profiles, and then iteratively develop prompts and evaluate them on a large number of cases. However, in the early development stages of most applications, many people, like us, only use a single example. However, for more mature applications, it may be useful to evaluate the performance of prompts on multiple profiles, e.g. test different prompts on multiple profiles to see how they perform in the average or worst case how. Typically, this is only done when the application is more mature, and there must be these metrics to drive the last few steps that suggest improvement.

General Catalog of "ChatGPT Prompt Words Project for Java Developers"

Guess you like

Origin blog.csdn.net/heihaozi/article/details/131333884