Skip to content

3.3: Add Instructions & Data

ITERATION STEP 1: Let's update the frontmatter to configure model parameters and shape our data context

1. Create chat-1.prompty

Let's reflect the start of a new iteration by copying our prompty asset to a new version. Make sure you are still in the sandbox/ folder - then run this command:

cp chat-0.prompty chat-1.prompty

Open or reload the chat-1.prompty file in your editor!


2. Before → Identify Fixes

Let's open this file in the Visual Studio Code editor and identify changes for this iteration:

  • Add Model Parameters: Adding temperature can help us modify response creativity.
  • Update System Persona: Personalize greetings using the customer data.
  • Define Data Inputs: We need to represent data for RAG (e.g. customer orders)
  • Use Sample File: Support more complex object formats (e.g., "shape" RAG data)
  • Update System Context Lines 20-23 should reflect customer service scenario.
  • Update Template Content Add instructions for scenario, use new inputs

    chat-1.prompty (before)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    ---
    name: Contoso Chat Prompt
    description: A retail assistant for Contoso Outdoors products retailer.
    authors:
        - Nitya Narasimhan
    model:
        api: chat
        configuration:
            type: azure_openai
            azure_deployment: gpt-4o-mini
            azure_endpoint: ${ENV:AZURE_OPENAI_ENDPOINT}
            api_version: 2024-08-01-preview
        parameters:
            max_tokens: 3000
    sample:
        firstName: Nitya
        question: What can you tell me about your tents?
    ---
    
    system:
    You are an AI assistant who helps people find information. As the assistant, 
    you answer questions briefly, succinctly, and in a personable manner using 
    markdown and even add some personal flair with appropriate emojis.
    
    # Customer
    You are helping {{firstName}} to find answers to their questions.
    Use their name to address them in your responses.
    
    # user
    {{question}}
    

Let's make these changes, next - and then run the modified asset!


3. After → Apply Fixes

  1. As before, let's copy over the prompty asset with these fixes applied:

    cp ../docs/workshop/src/1-build/chat-1.prompty .
    
  2. But this time, we also need to copy over the sample data file associated with it:

    cp ../docs/workshop/src/1-build/chat-1.json .
    
  3. This is what our second iteration looks like.

    • Study the sample data and the prompty asset below
    • See how asset "input" (customer) maps to sample object
    • The customer data can now be used in template (customer.firstName)
    • Note the # Previous Orders section - provides grounding context
    • Note the Instructions - clarifies usage of grounding context (RAG)

    chat-1.json (Sample data file)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    {
        "customer": {
        "id": "1",
        "firstName": "John",
        "lastName": "Smith",
        "age": 35,
        "email": "johnsmith@example.com",
        "phone": "555-123-4567",
        "address": "123 Main St,  Anytown USA, 12345",
        "membership": "Base",
        "orders": [
            {
            "id": 29,
            "productId": 8,
            "quantity": 2,
            "total": 700.0,
            "date": "2/10/2023",
            "name": "Alpine Explorer Tent",
            "unitprice": 350.0,
            "category": "Tents",
            "brand": "AlpineGear",
            "description": "Welcome to the joy of camping with the Alpine Explorer Tent! This robust, 8-person, 3-season marvel is from the responsible hands of the AlpineGear brand. Promising an enviable setup that is as straightforward as counting sheep, your camping experience is transformed into a breezy pastime. Looking for privacy? The detachable divider provides separate spaces at a moment's notice. Love a tent that breathes? The numerous mesh windows and adjustable vents fend off any condensation dragon trying to dampen your adventure fun. The waterproof assurance keeps you worry-free during unexpected rain dances. With a built-in gear loft to stash away your outdoor essentials, the Alpine Explorer Tent emerges as a smooth balance of privacy, comfort, and convenience. Simply put, this tent isn't just a shelter - it's your second home in the heart of nature! Whether you're a seasoned camper or a nature-loving novice, this tent makes exploring the outdoors a joyous journey."
            }
        ]
        },
        "question": "What cold-weather sleeping bag would go well with what I have already purchased?",
        "chat_history": []
    }
    

    chat-1.prompty (after)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    ---
    name: Contoso Chat Prompt
    description: A retail assistant for Contoso Outdoors products retailer.
    authors:
        - Nitya Narasimhan
    model:
        api: chat
        configuration:
            type: azure_openai
            azure_deployment: gpt-4o-mini
            azure_endpoint: ${ENV:AZURE_OPENAI_ENDPOINT}
            api_version: 2024-08-01-preview
        parameters:
            max_tokens: 3000
            temperature: 0.2
    inputs:
        customer:
            type: object
        question:
            type: string
    sample: ${file:chat-1.json}
    ---
    
    system:
    You are an AI agent for the Contoso Outdoors products retailer. 
    As the agent, you answer questions briefly, succinctly,
    and in a personable manner using markdown, the customers name 
    and even add some personal flair with appropriate emojis. 
    
    # Previous Orders
    Use their orders as context to the question they are asking.
    {% for item in customer.orders %}
    name: {{item.name}}
    description: {{item.description}}
    {% endfor %} 
    
    # Customer Context
    The customer's name is {{customer.firstName}} {{customer.lastName}} and is {{customer.age}} years old.
    {{customer.firstName}} {{customer.lastName}} has a "{{customer.membership}}" membership status.
    
    # user
    {{question}}
    
    # Instructions
    Reference other items purchased specifically by name and description that 
    would go well with the items found above. Be brief and concise and use appropriate emojis.
    

4. Run The Prompty

  1. Reload chat-1.prompty in the VS Code editor to refresh it.
  2. Run the refreshed prompty (using the play icon or by clicking F5)

    You should see a valid response (like this) in the Visual Studio Code terminal

    Hey John! 😊 
    
    To complement your **Alpine Explorer Tent**, I recommend the **AlpineGear Cold-Weather Sleeping Bag**. 
    This sleeping bag is designed for chilly nights, ensuring you stay warm and cozy while camping. 
    Its lightweight design makes it easy to pack, and it fits perfectly inside your tent. 
    
    Happy camping! 🏕️✨
    

Let's compare this to the previous step:

  • Do you see how the greeting is influenced by system context?
  • Do you see how the response is now grounded in customer data?
  • Do you see how response format is influenceed by the instructions?

CONGRATULATIONS. You just saw basic RAG in action, with responses grounded in sample data!