Gen-AI Developer Classroom notes 26/Mar/2025

Setting up OpenAI Account

  • Refer This Article
  • Note: Also watch classroom video for detailed steps
  • Accessing OpenAI Playground:
    • Directly through the OpenAI website:
      • Go to the OpenAI website via url
      • Click on the Playground button in the navigation bar.
      • This will take you directly to the OpenAI Playground interface.

Role of Prompt Engineering

  • A prompt is a text that contains set of instructions or requests that are sent to AI Model, usually referred as Large Language Model
  • Prompt Engineering is process of designing and refining prompts that guide the behavior of an AI model to produce that desired outputs or responses

Basic Prompting Rules

  • Here are 5 Basic prompting rules to write effective Prompts
    • Assign a Persona
    • Core task and subtasks
    • Provide Context
    • Explain expected output
    • Describe any Potential Limitations
  • Example:
You are an expert personal finance advisor. Explain different types of investment options available in india. Assume the audience have basic banking schemes knowledge. Provide the explanation and give me the tabular output of all options. Focus on the data from last 5 years.

Prompting Techniques


1. Zero-shot Prompting

Definition:
In zero-shot prompting, you ask the model to complete a task or answer a question without providing any examples or prior context. The model relies solely on its training to understand and generate a response.

Example:

  • Prompt: “What is the capital of Japan?”

  • Explanation:
    This is a zero-shot prompt because you didn’t provide any examples or additional context. You simply asked the model a question, and it is expected to know the answer (which is Tokyo).

  • Expected Output:
    “Tokyo”


2. Few-shot Prompting

Definition:
In few-shot prompting, you give the model a few examples to show how to perform a task before asking it to do something similar. These examples guide the model and help it understand the pattern or format of the task.

Example:

  • Prompt:
    _”Here are some translations from English to French:
  • English: ‘Good morning.’ → French: ‘Bonjour.’
  • English: ‘How are you?’ → French: ‘Comment ça va?’
    Translate this sentence to French: ‘What is your name?'”_

  • Explanation:
    This is a few-shot prompt because you provided a couple of examples (translations) to show the model how to perform the task (translation). The model can now use these examples to understand how to translate the new sentence.

  • Expected Output:
    “Quel est ton nom?”


3. Chain-of-thought Prompting

Definition:
In chain-of-thought prompting, you ask the model to reason through a problem step by step. This approach helps the model to break down complex tasks into smaller, logical steps, making the reasoning process more transparent.

Example:

  • Prompt:
    “Solve this math problem step by step:
    What is 12 multiplied by 9?”

  • Explanation:
    This is a chain-of-thought prompt because you are explicitly asking the model to go through the problem step by step. The model will not just give the final answer but will work through the process of solving it.

  • Expected Output:

  • Step 1: “First, let’s recall that 12 times 9 means adding 12, nine times.”
  • Step 2: “So, 12 + 12 + 12 + 12 + 12 + 12 + 12 + 12 + 12 = 108.”
  • Final answer: “12 multiplied by 9 is 108.”

Summary of Differences:

  • Zero-shot: The model does the task without examples. It’s like giving it a question and expecting it to know the answer.
    Example: “What is the capital of France?”

  • Few-shot: You give a few examples to guide the model. This helps it understand the task better before asking for a new output.
    Example: “Translate ‘Good morning’ to French” (followed by examples).

  • Chain-of-thought: You ask the model to work through the task step by step, which is especially useful for solving problems logically.
    Example: “Solve this math problem step by step.”


Prompt Design

  • Prompt Design refers to the process of creating and structuring the input given to a language model to achieve a desired output. It focuses on how you phrase and format your prompts to get the best results.

Prompt Design vs Prompt Engineering


1. Prompt Design Examples:

Goal: Crafting clear, simple, and direct prompts to get the desired output from the model.

Example 1: Simple Question

  • Prompt Design:
    “What is the capital of France?”

  • Explanation:
    This is a simple and direct prompt. The model is asked for specific information—the capital of France. It’s clear and leaves no room for ambiguity. The model will likely respond with “Paris.”


Example 2: Task-Oriented Instruction

  • Prompt Design:
    “Write a short paragraph about the benefits of exercise.”

  • Explanation:
    This prompt is clearly worded, asking the model to write a short paragraph. It’s a straightforward instruction with no complex reasoning or multi-step thinking required.


2. Prompt Engineering Examples:

Goal: Using more sophisticated techniques to refine the prompt and control the model’s behavior. This includes things like few-shot, chain-of-thought, system instructions, and controlling output randomness.

Example 1: Few-shot Prompting

  • Prompt Engineering (Few-shot):
    “Translate the following English sentences to French.
    English: ‘I am going to the store.’
    French: ‘Je vais au magasin.’
    English: ‘She is reading a book.’
    French: ‘Elle lit un livre.’
    English: ‘How are you today?'”

  • Explanation:
    In this case, you’re providing examples (few-shot learning) to the model to help it understand how to translate sentences. By showing the pattern of English to French translation, the model is better equipped to translate the final sentence correctly. This technique improves the model’s ability to follow a specific pattern or task.


Example 2: Chain-of-Thought Prompting

  • Prompt Engineering (Chain-of-Thought):
    “Solve this math problem step by step:
    What is 256 divided by 8?”

  • Explanation:
    In this example, you’re asking the model to think through the problem step by step (chain-of-thought). Instead of just asking for the answer, you’re guiding the model to break down the solution process. The model might respond with:

  • Step 1: 256 ÷ 8 = 32

  • Final answer: 32

This approach ensures the model doesn’t skip any important steps, which is especially useful for more complex tasks like math or reasoning problems.


Example 3: System Prompting (Instruction for Behavior)

  • Prompt Engineering (System Prompting):
    “You are an expert nutritionist. Your task is to give healthy eating advice based on someone’s age and lifestyle. Please respond in a friendly, supportive tone.”

  • Explanation:
    Here, you’re setting the context for how the model should behave by using a system prompt. You’re telling the model to act as an “expert nutritionist” and to maintain a “friendly, supportive tone” in its response. This controls the model’s behavior, ensuring that it not only provides accurate information but also does so in a manner appropriate for the situation.


Example 4: Temperature Control (Adjusting Creativity)

  • Prompt Engineering (Temperature Control):
  • Prompt: “Write a creative story about a time-traveling cat.”
  • Temperature setting: 0.8 (Higher creativity)

  • Explanation:
    By setting the temperature to 0.8, you’re telling the model to be more creative in its response. If you set the temperature lower (e.g., 0.2), the model’s responses would be more predictable and formal. A higher temperature encourages a more varied and imaginative output, making it suitable for tasks like creative writing.


Comparison of Design vs. Engineering Using the Same Task:

Task: Generate a Business Idea for a Startup

  • Prompt Design (Simple):
    “Give me a business idea for a tech startup.”

  • Expected Output:
    “A software platform that helps businesses manage their projects more efficiently.”

  • Explanation:
    This is a basic prompt asking for a business idea. It’s clear, simple, and direct but might not yield highly innovative or specific results.


  • Prompt Engineering (Few-Shot + Chain of Thought):
    _”Here are some examples of successful tech startup ideas:

    1. A platform that connects freelancers with businesses.
    2. An app that helps users learn new skills via micro-courses.
      Based on these, give me a new business idea in the tech industry that focuses on improving remote team collaboration.”_
  • Expected Output:
    “A cloud-based tool that uses AI to automate team task management and enhance communication for remote teams.”

  • Explanation:
    This approach is more sophisticated. You’re providing examples (few-shot), narrowing down the context to tech startups (industry-specific), and using the chain-of-thought method to guide the model into thinking about the task in a particular way. This yields a more tailored and focused business idea.


Key Takeaways:

  • Prompt Design focuses on clarity and simplicity, ensuring the model understands exactly what you’re asking for.
  • Prompt Engineering is more advanced, involving optimization techniques, such as few-shot learning, chain-of-thought reasoning, and adjusting parameters like temperature to control output creativity.

In simple terms, Prompt Design is about creating clear and effective prompts, while Prompt Engineering is about optimizing those prompts to guide the model’s behavior and improve results.


Image Prompting

  • Image prompting is a form of prompt engineering to guide an image generation model to generate a specific image output
  • An image prompt consists of three main parts—the image content, the art form and style, and the additional details—and generally follows the following pattern:
[main subject of the image, description of action, state, mood],
[art form, art style, artist references, if any],
[additional settings, such as lighting, colors, framing].
  • Many permutations and combinations are available depending on the AI model being used, and it won’t be useful to mention all of them here, but the following list provides some of the areas to think about:
    • Art medium —Drawing, painting, ink, origami, mosaic, pottery, Realistic and glazed
    • Camera —Lens and perspective, camera settings
    • Display and resolution —8K, 4K, HD, 256 × 256, 512 × 512, 768 × 768
    • Lighting —Types, display
    • Material —Metal, cloth, glass, wood, liquids
Lion Roaring in a dense forest, angry mood, Other Animals in the distant background, realistic, colorful, 8K

preview

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading