Study Notes - Advanced Prompt Engineering Generative AI

Advanced Prompt Engineering for Generative AI
Introduction to Google’s LLM Tools
  • Google Gemini and AI Studio are primary platforms for AI experimentation.

  • Gemini offers user-friendly access to AI models for text generation and data analysis.

  • AI Studio is aimed at developers wanting to integrate AI into applications through API.

Key Concepts Covered
  • Temperature and Top-p Settings: Adjusting randomness in model outputs.

  • Search-Grounded Prompts: Enhancing factual accuracy with external knowledge.

  • Prompting for Structured Output: Designing queries to get organized responses.

  • Function Calling: Making models more interactive with specific action triggers.

Exercise: Google Gemini vs. Google AI Studio
  • Log into Google and explore:

    • Gemini: Visit https://gemini.google.com

    • Enter queries and observe variations in responses, e.g., "Write a few sentences about electric vehicles."

    • AI Studio: Visit https://aistudio.google.com

    • Review different models and comparisons.

Understanding API Access in AI Studio
  • Set up an API key using Google Cloud Console to access models programmatically.

    • Steps include creating a project, obtaining an API key, and configuring Google Colab for access.

Temperature and Top-p Settings Explained
  • Temperature: Higher values allow more randomness;

    • Low Temperature (0) → Consistent outputs.

    • Standard Temperature (1) → Balanced outputs.

    • High Temperature (1.5) → Increased diversity, potential inconsistency.

  • Top-p (Nucleus Sampling): Controls the range of words the model considers based on cumulative probability.

    • Example: (top-p = 0.9) includes a word set that reaches 90% cumulative probability.

Exercise: Observing Temperature & Top-p Effects
  • Conduct a series of experiments to observe the output variability with different combinations of temperature and top-p settings.

  • Use a spreadsheet to record results from Gemini.

Functionality of System Instructions
  • System instructions guide the model's response behavior:

    1. Behavior: Sets tone and style.

    2. Context: Clarifies purpose of interaction.

    3. Response Guidance: Restricts or guides output content.

    4. Task Optimization: Tailors model performance based on task type.

    5. Consistency Maintenance: Ensures continuity across multi-turn interactions.

Exploring Code Execution in AI Studio
  • Code execution can be triggered with prompts to perform actions:

    • Examples:

    • Generating schedules, simulating processes, and calculating financial metrics.

Structured Output in Responses
  • Enabling structured outputs allows for JSON formatted responses, improving clarity, reliability, and usability for data integration and analysis.

    • Benefits for business applications include automation and easy data extraction.

Exercises for Structured Output
  1. Basic Example: "Tell me about the last 10 Super Bowls" with structured output.

    • Review Responses: Compare regular vs. structured output.

  2. Batch Processing: Upload menu or invoices and extract data in structured formats.

  • Application scenarios include handling various file types and integrating with business workflows.

Practical Implementation with Sample Code
  • Use Colab notebooks for structured data extraction in batch processes:

    • Upload and process invoices with defined data schemas (e.g., Receipt and ReceiptItem), refining outputs according to specifications.