logo
P
Prompt Master

Prompt 大师

掌握和 AI 对话的艺术

Adding odd numbers

math capability prompt example

TL;DR(中文)

  • 这是一个简单的 math reasoning 测试:先做 filtering(挑 odd numbers),再做 addition,最后判断 parity(odd/even)。
  • 适合用来观察:模型是否会按步骤执行、是否会在中间计算出错、以及是否能保持一致性。
  • 在生产里建议:要求输出每一步的中间结果(列表、求和过程、最终结论),便于 evaluation

Background

This prompt tests an LLM's mathematical capabilities by asking it to check whether the odd numbers in a group add up to an even number. It also nudges the model to break the problem into steps.

How to Apply(中文)

把这个 prompt 当成 “step-by-step 执行” 的模板即可:

  1. Identify(筛选 odd numbers)
  2. Compute(求和)
  3. Verify(判断 odd/even)

如果你要把它迁移到业务里的计算任务,核心是:把每一步写成可验收的子任务,并要求输出中间结果。

How to Iterate(中文)

  1. 结构化输出:要求输出一个小表格 numbers / is_odd / included / running_sum
  2. self-check:最后重复一遍求和,或用不同顺序再算一次
  3. 控制 temperature(数学任务通常建议更低温度以提升一致性)
  4. 对抗干扰:把列表变长、加入无效字符或更复杂格式,测试鲁棒性

Self-check rubric(中文)

  • 是否正确识别了哪些是 odd numbers?
  • 求和是否正确?是否有中间步骤错误?
  • 最终 parity 判断是否与求和一致?
  • 输出是否包含可复核的中间结果?

Practice(中文)

练习:把同样的模板应用到下面两类任务:

  • 从一串混合输入里提取满足条件的数字(例如 divisible by 3),再求和
  • 给定一串日期,筛选出周末,再统计数量

Prompt

The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.
Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.

Code / API

OpenAI (Python)

from openai import OpenAI

client = OpenAI()

response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {
            "role": "user",
            "content": "The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.\nSolve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.",
        }
    ],
    temperature=1,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
)

Fireworks (Python)

import fireworks.client

fireworks.client.api_key = "<FIREWORKS_API_KEY>"

completion = fireworks.client.ChatCompletion.create(
    model="accounts/fireworks/models/mixtral-8x7b-instruct",
    messages=[
        {
            "role": "user",
            "content": "The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.\nSolve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.",
        }
    ],
    stop=["<|im_start|>", "<|im_end|>", "<|endoftext|>"],
    stream=True,
    n=1,
    top_p=1,
    top_k=40,
    presence_penalty=0,
    frequency_penalty=0,
    prompt_truncate_len=1024,
    context_length_exceeded_behavior="truncate",
    temperature=0.9,
    max_tokens=4000,
)

Reference