Skip to content

3.6 Design Grounded Prompt

1. Add Grounded Chat Prompty

Let's copy over the grounded_chat.prompty prompt template into our assets folder.

  1. Make sure you are in the root directory of the repo.
  2. Then run this command:

    1
    cp src.sample/api/assets/grounded_chat.prompty src/api/assets/.
    

2. Understand Grounding Context

Explore the contents of this template. Notice how the system context provides clear instructions and guidance to ensure quality responses. This includes grounding responses in context (when query is relevant) and declining to provide responses (when query is irrelevant).

Click to expand and view Grounded Chat Prompty
src/api/assets/grounded_chat.prompty
 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
    ---
    name: Chat with documents
    description: Uses a chat completions model to respond to queries grounded in relevant documents
    model:
        api: chat
        configuration:
            azure_deployment: gpt-4o
    inputs:
        conversation:
            type: array
    ---
    system:
    You are an AI assistant helping users with queries related to outdoor outdooor/camping gear and clothing.
    If the question is not related to outdoor/camping gear and clothing, just say 'Sorry, I only can answer queries related to outdoor/camping gear and clothing. So, how can I help?'
    Don't try to make up any answers.
    If the question is related to outdoor/camping gear and clothing but vague, ask for clarifying questions instead of referencing documents. If the question is general, for example it uses "it" or "they", ask the user to specify what product they are asking about.
    Use the following pieces of context to answer the questions about outdoor/camping gear and clothing as completely, correctly, and concisely as possible.
    Do not add documentation reference in the response.

    # Documents

    {{#documents}}

    ## Document {{id}}: {{title}}
    {{content}}
    {{/documents}}

3. Chat With Products - Relevant

Run the script with a test query (from the src/api folder).

  1. Change to the src/api folder

    1
    cd src/api
    
  2. Run the script:

    1
    python chat_with_products.py --query "I need a new tent for 4 people, what would you recommend?"
    
  3. Observe the response. It may look like this:

    1
    💬 Response: {'content': "I recommend the TrailMaster X4 Tent. It is specifically designed to accommodate four occupants comfortably. The tent features durable water-resistant construction, multiple doors for easy access, and mesh panels for ventilation and bug protection. Additionally, it has a freestanding design for easy setup and relocation, as well as interior pockets for organization. It's a great choice for your camping adventures!", 'role': 'assistant'}
    

Is the response grounded in product data from the catalog?


4. Chat With Products - Irrelevant

Try asking a question that does not relate to the hiking and camping topic:

  1. Verify you are still in the src/api folder.

  2. Then run this script:

    1
    python chat_with_products.py --query "I am looking for a recipe for spicy bean burgers"
    
  3. Observe the response. It may look like this:

    1
    💬 Response: {'content': 'Sorry, I only can answer queries related to outdoor/camping gear and clothing. So, how can I help?', 'role': 'assistant'}
    

Is this response relevant and grounded in the context for this application?