## 📚 Prompt Engineering

<img src="https://raw.githubusercontent.com/genieincodebottle/generative-ai/main/images/Prompt_engineering.png">

---

[Prompt Engineering](https://www.promptingguide.ai/introduction) is the **art** and **science** of crafting effective inputs for Large Language Models (LLMs) to produce desired outputs. It's a crucial skill in GenAI related tasks, allowing users to harness the full potential of Large Language Models (LLMs) for various tasks.

------------

### 📖 Fundamentals of Prompt Design

  * **Clarity** - Be specific and unambiguous in your instructions.

  * **Context** - Provide relevant background information.

  * **Constraints** - Set boundaries for the AI's response.

  * **Examples** - Include sample inputs and outputs when possible.

  * **Format** - Specify the desired structure of the response.

---

### 📌 Important Prompt Techniques

  1. **[basic Prompt Engineering](./basic_prompt_engineering.ipynb)** - Basic Prompt Engineering
  
  2. **[Chain of Thought (CoT)](./chain_of_thought_CoT.ipynb)** - A strategy to enhance reasoning by articulating intermediate steps.

  3. **[Zero-Shot Chain of Thought (Zero-Shot-CoT)](./zero_shot_chain_of_thought.ipynb)** - Applying CoT without prior examples or training on similar tasks.

  4. **[Few-Shot Chain of Thought  (Few-Shot-CoT)](./few_shot_chain_of_thought.ipynb)** - Using a few examples to guide the reasoning process.

  5. **[Prompt Chaining](./prompt_chaining.ipynb)** - Connecting multiple prompts to create a coherent narrative.

  6. **[ReAct (Reasoning and Acting)](./reasoning_and_acting_ReAct.ipynb)** - Combining reasoning with action to improve responses.

  7. **[Tree of Thoughts (ToT)](./tree_of_thoughts_ToT.ipynb)** - Organizing thoughts hierarchically for better decision-making.

  8. **[Self-Consistency](./self_consistency.ipynb)** - Ensuring responses are stable and consistent across queries.

  9. **[Hypothetical Document Embeddings (HyDE)](./hypothetical_document_embeddings_HyDE.ipynb)** - Leveraging embeddings to represent potential documents for reasoning.

  10. **[Least-to-Most Prompting](./least_to_most_prompting.ipynb)** - Starting with simpler prompts and gradually increasing complexity.
  
  11. **[Graph Prompting](./graph_prompting.ipynb)** - Using graph structures to represent complex relationships.

  12. **[Recursive Prompting](./recursive_prompting.ipynb)** - Iteratively refining prompts to enhance results.

  13. **Generated Knowledge** - Utilizing generated content as a basis for further reasoning.

  14. **[Automatic Reasoning and Tool-Use (ART)](./automatic_reasoning_and_tool_use.ipynb)** - Automating reasoning processes and tool interactions.

  15. **[Automatic Prompt Engineer (APE)](./automatic_prompt_engineer_APE.ipynb)** - Tools to automatically generate and refine prompts.

  16. **Reflexion**: Reflecting on past responses to improve future prompts.
    
  17. **Prompt Ensembling**: Combining multiple prompts for enhanced results.
    
  18. **Directional Stimulus Prompting**: Guiding responses with targeted prompts.

---

### 🛠️ Prompt Optimization Techniques

1. **Iterative refinement:** Start with a basic prompt and gradually improve it based on the results.

2. [**A/B testing:**](https://www.oracle.com/in/cx/marketing/what-is-ab-testing/#:~:text=A%2FB%20testing%3F-,A%2FB%20testing%20definition,based%20on%20your%20key%20metrics.) Compare different versions of a prompt to see which performs better.

3. **Prompt libraries:** Create and maintain a collection of effective prompts for reuse.

4. **Collaborative prompting:** Combine insights from multiple team members to create stronger prompts.

---

### ⚖️ Ethical Considerations in Prompt Engineering

1. **Bias mitigation:** Be aware of and actively work to reduce biases in prompts and outputs.

2. **Content safety:** Implement safeguards against generating harmful or inappropriate content.

4. **Data privacy:** Avoid including sensitive information in prompts.

---

### ✅ Evaluating Prompt Effectiveness

1. **Relevance:** Does the output address the intended task or question?

2. **Accuracy:** Is the information provided correct and up-to-date?

3. **Coherence:** Is the response well-structured and logical?

4. **Creativity:** For open-ended tasks, does the output demonstrate originality?

5. **Efficiency:** Does the prompt produce the desired result with minimal back-and-forth?


### 📚 Resources

1. [Coursera Specialization](https://www.coursera.org/specializations/prompt-engineering)
2. [Kaggle Whitepaper](https://www.kaggle.com/whitepaper-prompt-engineering)
3. [GitHub](https://github.com/genieincodebottle/generative-ai/blob/main/genai-usecases/prompt-engineering)