Dynamic Prompt Examples

Adjusting prompt inputs based on content length to reduce token consumption

Write three easy-to-read sentences summarizing the following text:
{# The if-else logic below checks if the document is long, or short in order to reduce your token consumption. #}
{% if (content | num_tokens) > 8000 %}
{{ content | central_part }}
{% else %}
{{ content }}
{% endif %}

Providing different Summary Prompts based on content length to enhance summarization experience

{# For extremely long content, use a complex prompt, and only extract central part #}
{% if (content | num_tokens) > 10000 %}
Please summarize and extract the following text according to the structure below:

1. **Abstract**: Provide a one-sentence abstract of the main content and key points of the article.
2. **Summary**: Provide a detailed summary of the article, covering main points, data, and solutions, in no more than 500 words.
3. **Opinions**: Extract some key opinions mentioned in the content, with each opinion no more than 100 words.

Extraction Standards:
1. Preserve the core information and key points without omitting important content.
2. Use concise and clear language, avoiding redundancy.
3. Ensure clear logic and distinct paragraphs.
4. Use markdown format for output.
5. Highlight key data points effectively.

Example Output:

## Abstract 
[Abstract content]

## Summary
[Summary content]

## Opinions 
- Opinion 1 ...
- Opinion 2 ...
- ...

===

Here is the text:
{{ content | central_part }}

{# For long content, use a complex prompt #}
{% elif (content | num_tokens) > 3000 %}
Please summarize and extract the following text according to the structure below:

1. **Abstract**: Provide a one-sentence abstract of the main content and key points of the article.
2. **Summary**: Provide a detailed summary of the article, covering main points, data, and solutions, in no more than 500 words.
3. **Opinions**: Extract some key opinions mentioned in the content, with each opinion no more than 100 words.

Extraction Standards:
1. Preserve the core information and key points without omitting important content.
2. Use concise and clear language, avoiding redundancy.
3. Ensure clear logic and distinct paragraphs.
4. Use markdown format for output.
5. Highlight key data points effectively.

Example Output:

## Abstract 
[Abstract content]

## Summary
[Summary content]

## Opinions 
- Opinion 1 ...
- Opinion 2 ...
- ...

===

Here is the text:
{{ content }}

{# For medium-length content, use a general prompt #}
{% elif (content | num_tokens) >= 500 %}
Based on the type and structure of the following text, choose the most appropriate template outline for summarizing to extract as much valuable information as possible. It must include at least a one-sentence summary and key points. If more valuable information can be extracted, additional sections such as insights, takeaways, and any other relevant content can be included. Output using markdown sections with headings. Use single-level headings without nesting.

Here is the text:
{{ content }}

{# For short content, use a simple prompt #}
{% elif (content | num_tokens) > 100 %}
Write three easy-to-read sentences summarizing the following text:
{{ content }}

{# For very short content, use a one sentence prompt #}
{% else %}
Summarize the following content in one easy-to-read sentence:
{{ content }}
{% endif %}

Syntax

Comments

The content between {# #} is a comment and will not be parsed.

Conditional Statements

{% if ... %} ... {% else %} ... {% elif %} ... {% endif %} are conditional statements that execute different code blocks based on the conditions in the parentheses.

Variables

The content between {{ ... }} is a variable and will be parsed into the corresponding value.

Builtin Variables:

  • content. The content of the article.
  • lang. The language you set in basic settings.

Filter

Filters are essentially functions that can be applied to variables. They are called with a pipe operator (|) and can take arguments.

Builtin Filters:

  • num_tokens. Calculate the number of tokens of the content.
  • central_part. Extract the central part of the content.

More

Refer to nunjucks doc