3.6 Design Grounded Prompt¶
1. Add Grounded Chat Prompty¶
Let's copy over the grounded_chat.prompty
prompt template into our assets folder.
- Make sure you are in the root directory of the repo.
-
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 |
|
3. Chat With Products - Relevant¶
Run the script with a test query (from the src/api
folder).
-
Change to the
src/api
folder1
cd src/api
-
Run the script:
1
python chat_with_products.py --query "I need a new tent for 4 people, what would you recommend?"
-
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:
-
Verify you are still in the
src/api
folder. -
Then run this script:
1
python chat_with_products.py --query "I am looking for a recipe for spicy bean burgers"
-
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?