Monday, May 18, 2026

4.2 Prompt Pt 2 - Course Notes

 

4.2 Prompt Pt 2 - Gen AI: Building LLM Apps

Sun, 17 May 26

Course Overview & Lab Setup Issues

  • Advanced prompt engineering techniques (Part 2) for building LLM applications

  • Multiple lab access problems across students

    • API key failures in Colab

    • Virtual environment setup difficulties

    • Missing demo files (Demo 5 unavailable for some students)

  • Instructor using alternative lab instance due to access issues

Chain of Thought (CoT) Prompting

  • Breaks complex problems into sequential subtasks vs direct input-output

  • Benefits over zero/few-shot approaches:

    • Easier reasoning for lightweight models

    • Better context window utilization

    • Reduces hallucination risk

  • Implementation signals:

    • “Think through the problem step by step”

    • “Break down into steps”

  • Modern LLMs automatically implement CoT internally

  • Can combine with zero-shot or few-shot prompting

Self-Consistency Prompting

  • Built on CoT to improve reasoning consistency

  • Process:

    • Ask same question multiple times

    • Model takes diverse reasoning paths

    • Apply majority voting to final answers

  • Addresses probabilistic nature of LLMs

  • Benefits:

    • Improved accuracy through multiple perspectives

    • Reduced bias via diverse reasoning

    • Enhanced critical thinking

Tree of Thought (ToT) Prompting

  • Multiple chain-of-thought branches like tree structure

  • Key features:

    • Different strategies per branch

    • Backtracking capability to previous steps

    • Graph traversal approach to problem solving

  • More robust than sequential CoT

  • Example: Finding number 24 using digits 4, 9, 10, 13

    • Multiple arithmetic operation combinations

    • Different starting number pairs per branch

LangChain Prompt Templates

  • Reusable, parameterized prompt structures

  • Template types:

    • Basic PromptTemplate - simple variable substitution

    • ChatPromptTemplate - structured chat interactions

    • Custom templates using string formatting

  • Benefits:

    • Consistency across applications

    • Dynamic variable insertion

    • Structured predefined formats

Jinja2 Template Integration

  • Advanced templating engine for dynamic content generation

  • Features:

    • Conditional logic support

    • Variable substitution

    • Age-appropriate content adaptation (kids vs adult events)

  • Use cases:

    • Automated report generation

    • Personalized invitations

    • Flask/Django web applications

Lab Environment Setup Requirements

  • Virtual environment creation: python3 -m venv myenv

  • Activation: source myenv/bin/activate

  • Install requirements.txt (contains all dependencies)

  • Kernel selection: Must use “myenv” not default Python 3

  • API key setup only needed for Colab users

  • Simply Learn platform provides pre-configured API access

Next Steps & Resources

  • No class next Saturday (May 24, 2026)

  • Next session: May 30, 2026

  • Students should practice demos independently

  • Experiment with different:

    • Temperature settings (0 for deterministic, 0.7 for creative)

    • Model types (GPT-3.5-turbo vs GPT-4o-mini)

    • Custom prompts and variables

  • Use AI (Gemini) to learn AI - ask for parameter explanations and improvements

No comments:

Post a Comment