Assignment: Build an Advanced Prompt Engineering SystemΒΆ

🎯 Objective¢

Build a comprehensive prompt engineering system that demonstrates mastery of various prompting techniques. You’ll create a multi-purpose AI assistant that adapts its prompting strategy based on the task type.

Estimated Time: 5-7 hours
Difficulty: ⭐⭐⭐ Intermediate
Due Date: 2 weeks from assignment

πŸ“‹ RequirementsΒΆ

Part 1: Prompting Technique Library (30 points)ΒΆ

Implement at least 6 different prompting techniques:

  • Zero-shot: Direct task execution without examples

  • Few-shot: Learning from 3-5 examples

  • Chain-of-Thought (CoT): Step-by-step reasoning

  • ReAct: Reasoning + Acting with tools

  • Self-Consistency: Multiple reasoning paths with voting

  • Tree-of-Thoughts: Exploring multiple solution branches

Implementation Structure:

class PromptEngine:
    def __init__(self, api_key, model="gpt-4"):
        self.client = OpenAI(api_key=api_key)
        self.model = model
        self.techniques = {}
    
    def zero_shot(self, task, context=None):
        """Execute task with zero-shot prompting."""
        pass
    
    def few_shot(self, task, examples, context=None):
        """Execute task with few-shot examples."""
        pass
    
    def chain_of_thought(self, task, context=None):
        """Use CoT prompting for complex reasoning."""
        pass
    
    def react(self, task, tools, max_iterations=5):
        """ReAct: Reasoning and Acting with tools."""
        pass
    
    def self_consistency(self, task, n_samples=5):
        """Generate multiple solutions and vote."""
        pass
    
    def tree_of_thoughts(self, task, depth=3, breadth=3):
        """Explore solution tree."""
        pass

Part 2: Adaptive Strategy Selector (25 points)ΒΆ

Create a system that automatically selects the best prompting strategy:

  • Classify task type (simple Q&A, reasoning, creative, analytical)

  • Choose appropriate prompting technique based on task

  • Adjust parameters (temperature, tokens) per technique

  • Track token usage and costs per technique

Strategy Selection Logic:

class StrategySelector:
    def classify_task(self, task):
        """
        Classify task into categories:
        - simple: Direct Q&A, facts
        - reasoning: Math, logic, multi-step
        - creative: Writing, brainstorming
        - analytical: Data analysis, summarization
        - tool_use: Requires external APIs/tools
        """
        pass
    
    def select_strategy(self, task):
        """Select best prompting technique for task."""
        task_type = self.classify_task(task)
        
        strategy_map = {
            "simple": "zero_shot",
            "reasoning": "chain_of_thought",
            "creative": "few_shot",
            "analytical": "tree_of_thoughts",
            "tool_use": "react"
        }
        
        return strategy_map.get(task_type, "zero_shot")

Part 3: Real-World Applications (25 points)ΒΆ

Build 4 practical applications using different techniques:

App 1: Research Assistant (CoT + Tools)ΒΆ

  • Takes a research question

  • Breaks it into sub-questions

  • Searches web for each sub-question

  • Synthesizes comprehensive answer with citations

App 2: Code Reviewer (Few-shot)ΒΆ

  • Analyzes code for bugs, style, performance

  • Uses examples of good/bad code patterns

  • Provides specific, actionable feedback

  • Suggests improvements

App 3: Creative Writing Coach (Self-Consistency)ΒΆ

  • Generates multiple story plot variations

  • Gets feedback on each

  • Combines best elements

  • Produces final polished version

App 4: Data Analyst (Tree-of-Thoughts)ΒΆ

  • Takes dataset description and question

  • Explores multiple analysis approaches

  • Evaluates each approach

  • Presents best insights

Part 4: Optimization & Analysis (20 points)ΒΆ

Analyze and optimize your system:

  • Token Usage: Track tokens per technique, identify savings opportunities

  • Cost Analysis: Calculate cost per task type

  • Quality Metrics: Compare output quality across techniques

  • Speed Benchmarks: Measure latency for each technique

  • A/B Testing: Compare techniques on same tasks

Required Report:

  • Table comparing all 6 techniques on:

    • Average tokens used

    • Average cost

    • Subjective quality rating (1-5)

    • Average latency

    • Best use cases

πŸ“Š Grading RubricΒΆ

Criteria

Exemplary (A)

Proficient (B)

Adequate Β©

Needs Work (D/F)

Techniques (30pts)

6+ techniques, flawless implementation

5-6 techniques, minor issues

4-5 techniques, some bugs

<4 techniques or broken

Strategy Selector (25pts)

Smart auto-selection, handles edge cases

Good selection logic

Basic selection

Poor or no selection

Applications (25pts)

4 polished apps, excellent UX

3-4 good apps

2-3 basic apps

<2 or poor quality

Analysis (20pts)

Deep insights, comprehensive data

Good analysis

Basic metrics

Minimal analysis

🌟 Bonus Challenges (+10 points each, max +30)¢

Bonus 1: Prompt Optimization System (+10)ΒΆ

  • Automatically refine prompts based on output quality

  • Use LLM to critique and improve prompts

  • Show before/after prompt examples with quality improvements

Bonus 2: Cost Control Dashboard (+10)ΒΆ

  • Real-time token tracking

  • Budget alerts when approaching limits

  • Cost prediction for new tasks

  • Recommendations for cheaper alternatives

Bonus 3: Multi-Modal Prompting (+10)ΒΆ

  • Integrate image understanding (GPT-4 Vision)

  • Process images + text together

  • Build visual Q&A system

  • Image-to-text and text-to-image workflows

Bonus 4: Evaluation Framework (+10)ΒΆ

  • Automated quality scoring for outputs

  • Human evaluation interface

  • Inter-rater reliability metrics

  • Continuous improvement tracking

πŸ“¦ Submission RequirementsΒΆ

Repository StructureΒΆ

your-name-prompt-engineering/
β”œβ”€β”€ README.md                    # Setup and usage
β”œβ”€β”€ requirements.txt             # Dependencies
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ prompt_engine.py         # Core prompting techniques
β”‚   β”œβ”€β”€ strategy_selector.py    # Adaptive selection
β”‚   β”œβ”€β”€ apps/
β”‚   β”‚   β”œβ”€β”€ research_assistant.py
β”‚   β”‚   β”œβ”€β”€ code_reviewer.py
β”‚   β”‚   β”œβ”€β”€ writing_coach.py
β”‚   β”‚   └── data_analyst.py
β”‚   └── utils/
β”‚       β”œβ”€β”€ token_tracker.py
β”‚       └── cost_calculator.py
β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ technique_comparison.ipynb
β”‚   β”œβ”€β”€ application_demos.ipynb
β”‚   └── optimization_analysis.ipynb
β”œβ”€β”€ tests/
β”‚   └── test_techniques.py       # Unit tests
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ example_tasks.json       # Test tasks
β”‚   └── results/                 # Experiment results
└── REPORT.md                    # Analysis report

What to IncludeΒΆ

  1. Working Code:

    • All 6 prompting techniques

    • Strategy selector

    • 4 practical applications

    • Tests demonstrating functionality

  2. Analysis Notebook:

    • Technique comparisons

    • Cost/performance analysis

    • Quality evaluation

    • Optimization recommendations

  3. Report (REPORT.md):

    • Methodology explanation

    • Results tables and charts

    • Insights and findings

    • Lessons learned

    • Future improvements

  4. Demo:

    • Video (5 min) or Gradio app showing:

      • Each technique in action

      • Strategy selector working

      • At least 2 applications

      • Cost tracking dashboard

πŸ’‘ Example ImplementationsΒΆ

Example: Chain-of-Thought Implementation
def chain_of_thought(self, task, context=None):
    """
    Implements Chain-of-Thought prompting.
    Encourages step-by-step reasoning.
    """
    prompt = f"""
    Let's solve this step by step.
    
    Task: {task}
    {f"Context: {context}" if context else ""}
    
    Think through this carefully:
    1) First, let's identify what we know
    2) Then, what steps do we need to take?
    3) Finally, what's the answer?
    
    Please show your reasoning for each step.
    """
    
    response = self.client.chat.completions.create(
        model=self.model,
        messages=[{"role": "user", "content": prompt}],
        temperature=0.3  # Lower temp for reasoning tasks
    )
    
    return response.choices[0].message.content
Example: ReAct with Web Search Tool
def react(self, task, tools, max_iterations=5):
    """
    ReAct: Reasoning and Acting.
    Alternates between reasoning and tool use.
    """
    messages = [{
        "role": "system",
        "content": """You are a helpful assistant that uses tools to solve problems.
        
        Available tools:
        - web_search(query): Search the web
        - calculate(expression): Calculate math expressions
        
        Use this format:
        Thought: [your reasoning]
        Action: tool_name(arguments)
        Observation: [tool result]
        ... (repeat as needed)
        Answer: [final answer]
        """
    }]
    
    messages.append({"role": "user", "content": task})
    
    for i in range(max_iterations):
        response = self.client.chat.completions.create(
            model=self.model,
            messages=messages
        )
        
        content = response.choices[0].message.content
        
        # Check if answer provided
        if "Answer:" in content:
            return content.split("Answer:")[1].strip()
        
        # Extract and execute action
        if "Action:" in content:
            action_line = content.split("Action:")[1].split("\n")[0]
            result = self._execute_tool(action_line, tools)
            messages.append({
                "role": "assistant",
                "content": content
            })
            messages.append({
                "role": "user",
                "content": f"Observation: {result}"
            })
        else:
            break
    
    return "Failed to reach conclusion"

πŸ“š ResourcesΒΆ

Essential ReadingΒΆ

Tools & LibrariesΒΆ

VideosΒΆ

πŸŽ“ Learning ObjectivesΒΆ

After completing this assignment, you will:

  • βœ… Master 6+ advanced prompting techniques

  • βœ… Build production-ready prompt systems

  • βœ… Optimize for cost and performance

  • βœ… Evaluate prompt effectiveness systematically

  • βœ… Create adaptive AI applications

πŸ’¬ SupportΒΆ

Happy prompting! 🎨

Remember: Great prompts are iterative. Test, measure, and refine!