# Prompting Engineering

## Prompt

**Design**

* Prompts involve instructions and context passed to a language model to achieve a desired task.
* Creating a prompt that is tailored to the specific task that this system is being asked to perform.

**Engineering**

* Prompt engineering is the practice of developing and optimizing prompts to efficiently use language models for a variety of applications.
* Is the process of creating a prompt that is designed to improve performance.
  * This may involve using domain-specific knowledge.
  * Providing examples of the desired output.
  * Using keywords that are known to be effective for the specific system.





## Types of LLM

Each type needs prompting in a different way.

**Generic Language Models**

* These predict the next word (token) based on the language in the training data.
* Are easily confused and five very different outputs.
* Think of these as an autocomplete feature.

**Instruction Tuned**

* Trained to predict a response to the instructions given in the input.
* Are easily confused and five very different outputs.
* Ex.:
  * 'Summarize a text of X'.
  * 'Generate a poem in the style of X'.

**Dialog Tuned**

* Trained to have a dialog by predicting the next response.
* These models are a special case of instruction tuned where requests are typically framed as questions to a chatbot.
* Typically works better with natural question-like phrasings.





## Types of Prompting

**Zero-shot prompting**

* Implies that a model can recognize things that have not explicitly been taught in the training before.
* Leverages a pre-trained model's understanding of words and concept relationships without further training.
* Basically when you just have to ask one time, without examples.
* Ex.: `When is Christmas in America?`.

**Few-shot prompting**

* Training a model with minimal data.
* Enhances the model with training examples via the prompt avoiding retraining.
* Ex.: `Lucas favourite type of foods include: Burguers, fries, pizza. What restaurants should I go this weekend?`.

\


## AI Hallucinations

It refers to the unusual outputs that AI models can produce when they misinterpret data.

\


## Prompts tips

{% embed url="https://www.promptingguide.ai/pt" %}

Official from ChatGPT

{% embed url="https://platform.openai.com/docs/guides/prompt-engineering" %}

Useful video explaining multiple Prompt Engineering

{% embed url="https://www.youtube.com/watch?v=lTI4FyO0ul8" %}

#### **Clear Instructions**

* Writing more detail on the question.
* Do not assume the AI knows what you are talking about.
* When prompting, describe as you were talking to an alien.

#### **Adopt a Persona**

```
[Do something] as [someName]. [somaName] is [goodCharacteristics]. [someName] skills are similar to [someFamousPerson].
...
```

* `someName`: Should be the name of someone generic.
* `goodCharacteristics`: Describe amazing characteristics about this generic person, but these characteristics are related to the task that will be executed next.
* `someFamousPerson`: You can also add the name of someone famous for these characteristics, to help the LLM to understand exactly what you want.

Or make the LLM adopt a persona.

```
Act as [someRole] ...
```

#### **Use Delimiters**

* Using delimiters to clearly indicate distinct parts of the input
* Can be:
  * Quotations.
  * XML tags.
  * Section titles.
  * etc.

```
[doSomething] and put the anwser in [RESULT] or <RESULT> or "Result: "

[RESULT] or <RESULT> or """place text here""" or """[insert RESULT here]"""
```

#### **Specify Steps required to Complete tasks**

* Some tasks are best specified as a sequence of steps.
* Writing the steps explicitly can make it easier for the model to follow them.

```
Follow these steps to [doSomething]

Step 1: ...

Step 2: ...
```

#### **Give Examples of the Answer (Few-shot)**

```
Respond to the questions as the example bellow:
Example: [doSomethingExample]
Response: [theResponseInAWayThatYouWouldLike]
Question: [doSomething]
```

#### **Specify the Format**

* Limiting words, telling it to be concise, or summarize.
* Telling to use lists for explanation.
* Telling to use a specific language.

#### **Stylize**

* `for a [style]`:
  * simple
  * technical
  * creative
  * formal
  * informal
  * persuasive
  * like a pirate

#### **Format**

* Bullet points
* Summary
* Headings & Subheadings
* Blog article
* Table
* Code snippet
* Mind map
* Step-by-step _**(Chain-of-Thought)**_
* Flowcharts

#### **Restrictions**

* One sentence
* 2-3 sentences
* One paragraph
* Extremely detailed
* Only use academic papers
* No sources older than `[year]`

#### **Getting opposed sides/opinions**

* `Steel man the opposing side`.

#### **Ask the GPT on how to prompt**

* `What is the best way to prompt ChatGPT to teach it how to write in my style?`.

#### **With complex reasoning**

Read:

* **Tree of Thoughts (ToT)** https://www.promptingguide.ai/pt/techniques/tot
* **Program-Aided Language Models (PAL)** https://www.promptingguide.ai/pt/techniques/pal

\


## Master ChatGPT

{% embed url="https://www.youtube.com/watch?v=6JeaYWDyw54" %}

