Skip to content

EchoesInAI/Prompt-Engineering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Prompt Engineering

A comprehensive Jupyter notebook exploring various prompt engineering techniques and strategies for working with Large Language Models (LLMs). This notebook demonstrates core prompting patterns using OpenAI's GPT models.

Overview

This notebook serves as both a tutorial and a practical guide to prompt engineering, covering techniques from basic zero-shot prompting to advanced methods like Tree-of-Thought and Graph-of-Thought reasoning. Each technique includes explanations, examples, and working code demonstrations (for most).

Features

Core Prompting Techniques

  1. Zero-Shot Prompting - Direct instructions without examples
  2. One-Shot Prompting - Single example demonstration
  3. Few-Shot Prompting - Multiple examples for pattern recognition
  4. Chain-of-Thought (CoT) - Step-by-step reasoning
  5. Meta Prompting - Structured templates and formats
  6. Generated Knowledge Prompting - Generating background knowledge first
  7. Self-Consistency Prompting - Multiple reasoning paths with consensus
  8. Prompt Chaining - Sequential prompts with output feeding
  9. Directional Stimulus Prompting - Hints and cues for guidance
  10. Tree-of-Thought (ToT) - Branching reasoning paths
  11. ReAct Prompting - Reasoning + Acting loops
  12. Reflection Prompting - Learning from feedback
  13. Graph-of-Thought (GoT) - Graph-structured reasoning

Getting Started

Prerequisites

  • Python 3.10 or higher
  • OpenAI API key (Get one here)
  • Jupyter Notebook or JupyterLab

Installation

  1. Clone or download this repository

  2. Create a virtual environment (recommended):

    python3 -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install required packages:

    pip install langchain-openai openai pandas numpy ipython jupyter
  4. Set up your API key:

    Option A: Environment Variable (Recommended)

    export OPENAI_API_KEY="sk-your-api-key-here"  # On Windows: set OPENAI_API_KEY=sk-your-api-key-here

    Option B: Using a Python module

    • Create a chatgpt_key.py file in your parent directory with:
      OPENAI_API_KEY = "sk-your-api-key-here"
    • Update the sys.path.append() line in the notebook to point to the directory containing chatgpt_key.py

Running the Notebook

  1. Launch Jupyter:

    jupyter notebook
  2. Open Prompt Engineering.ipynb

  3. Update the path in the setup cell if using Option B for API key:

    sys.path.append("/path/to/your/parent/directory")
  4. Run cells sequentially to follow along with the examples

Configuration

Model Selection

The notebook uses gpt-5.2 by default. To use a different model, update the model name in the initialization cell:

openai_chat_client = ChatOpenAI(
    model="gpt-4",  # or "gpt-3.5-turbo", "gpt-4-turbo", etc.
    api_key=OPENAI_API_KEY,
    temperature=0
)

Temperature Settings

The notebook uses temperature=0 for deterministic outputs. Adjust this value (0.0 to 2.0) to control randomness:

  • 0 - Most deterministic, consistent outputs
  • 0.7 - Balanced creativity and consistency
  • 1.0+ - More creative and varied outputs

Notes

  • API Costs: Running all cells will make multiple API calls. Monitor your usage on the OpenAI dashboard.
  • Sequential Execution: Some cells depend on previous cells. Run them in order.
  • Customization: Feel free to modify prompts, add your own examples, or experiment with different models.
  • Path Configuration: Update the sys.path.append() line to match your directory structure.

Troubleshooting

API Key Issues

  • Verify your API key is set correctly
  • Check that the key has sufficient credits
  • Ensure the key has access to the model you're using

Model Not Found

  • Verify the model name is correct (e.g., gpt-4, gpt-3.5-turbo)
  • Check OpenAI's model availability page

Contributing

Feel free to:

  • Add new prompting techniques
  • Improve existing examples
  • Fix bugs or typos
  • Enhance documentation

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published