|
| 1 | +""" |
| 2 | +Advanced template usage example for Promptix library. |
| 3 | +
|
| 4 | +This example demonstrates advanced templating features: |
| 5 | +1. Conditional blocks (if/else/elif) |
| 6 | +2. Loops and list handling (for loops) |
| 7 | +3. Nested conditional logic |
| 8 | +4. Numeric comparisons |
| 9 | +5. Dynamic content generation |
| 10 | +6. Custom data structures |
| 11 | +""" |
| 12 | + |
| 13 | +from typing import Any, Dict, List, Optional |
| 14 | + |
| 15 | +from promptix import Promptix |
| 16 | + |
| 17 | + |
| 18 | +def generate_rpg_scenario( |
| 19 | + game_style: str, |
| 20 | + party_level: int, |
| 21 | + party_classes: List[str], |
| 22 | + environment: str, |
| 23 | + quest_type: str, |
| 24 | + difficulty: str, |
| 25 | + magical_elements: Optional[List[str]] = None, |
| 26 | + environment_details: Optional[Dict[str, Any]] = None, |
| 27 | + special_conditions: Optional[List[str]] = None, |
| 28 | +) -> str: |
| 29 | + """ |
| 30 | + Generate a dynamic RPG scenario using advanced template features. |
| 31 | + """ |
| 32 | + env_details = environment_details or {} |
| 33 | + |
| 34 | + context = { |
| 35 | + "game_style": game_style, |
| 36 | + "party_level": party_level, |
| 37 | + "party_classes": party_classes, |
| 38 | + "environment": environment, |
| 39 | + "quest_type": quest_type, |
| 40 | + "difficulty": difficulty, |
| 41 | + "magical_elements": magical_elements, |
| 42 | + # environment-specific flags |
| 43 | + "has_traps": env_details.get("has_traps", False), |
| 44 | + "has_crime": env_details.get("has_crime", False), |
| 45 | + "has_monsters": env_details.get("has_monsters", False), |
| 46 | + # environment details |
| 47 | + "city_type": env_details.get("city_type", "medieval"), |
| 48 | + "atmosphere": env_details.get("atmosphere", "mysterious"), |
| 49 | + "terrain_type": env_details.get("terrain_type", "forest"), |
| 50 | + # special conditions in custom data |
| 51 | + "custom_data": {"special_conditions": special_conditions} if special_conditions else {}, |
| 52 | + } |
| 53 | + |
| 54 | + return Promptix.get_prompt(prompt_template="DungeonMaster", **context) |
| 55 | + |
| 56 | +def main(): |
| 57 | + print("Advanced Template Usage Examples\n") |
| 58 | + |
| 59 | + # Example 1: Beginner dungeon crawl |
| 60 | + print("\nExample 1: Beginner Dungeon Crawl") |
| 61 | + print("-" * 50) |
| 62 | + prompt1 = generate_rpg_scenario( |
| 63 | + game_style="heroic", |
| 64 | + party_level=3, |
| 65 | + party_classes=["Warrior", "Cleric", "Rogue"], |
| 66 | + environment="dungeon", |
| 67 | + quest_type="combat", |
| 68 | + difficulty="easy", |
| 69 | + environment_details={"has_traps": True}, |
| 70 | + magical_elements=["Ancient Runes", "Magical Barriers"], |
| 71 | + ) |
| 72 | + print(prompt1) |
| 73 | + |
| 74 | + # Example 2: Complex city intrigue |
| 75 | + print("\nExample 2: Complex City Intrigue") |
| 76 | + print("-" * 50) |
| 77 | + prompt2 = generate_rpg_scenario( |
| 78 | + game_style="mystery", |
| 79 | + party_level=8, |
| 80 | + party_classes=["Bard", "Rogue", "Wizard", "Paladin"], |
| 81 | + environment="city", |
| 82 | + quest_type="diplomacy", |
| 83 | + difficulty="hard", |
| 84 | + environment_details={ |
| 85 | + "has_crime": True, |
| 86 | + "city_type": "merchant", |
| 87 | + "atmosphere": "tense", |
| 88 | + }, |
| 89 | + magical_elements=["Dark Magic", "Illusion Magic", "Forbidden Arts"], |
| 90 | + special_conditions=[ |
| 91 | + "Political uprising imminent", |
| 92 | + "Hidden cult influence", |
| 93 | + "Corrupt city guard", |
| 94 | + ], |
| 95 | + ) |
| 96 | + print(prompt2) |
| 97 | + |
| 98 | + # Example 3: Epic wilderness adventure |
| 99 | + print("\nExample 3: Epic Wilderness Adventure") |
| 100 | + print("-" * 50) |
| 101 | + prompt3 = generate_rpg_scenario( |
| 102 | + game_style="epic", |
| 103 | + party_level=15, |
| 104 | + party_classes=["Druid", "Ranger", "Barbarian", "Shaman"], |
| 105 | + environment="wilderness", |
| 106 | + quest_type="mystery", |
| 107 | + difficulty="medium", |
| 108 | + environment_details={"has_monsters": True, "terrain_type": "mountain"}, |
| 109 | + magical_elements=["Ancient Ley Lines", "Natural Magic", "Elemental Powers"], |
| 110 | + ) |
| 111 | + print(prompt3) |
| 112 | + |
| 113 | + # Example 4: Minimal configuration |
| 114 | + print("\nExample 4: Minimal Required Configuration") |
| 115 | + print("-" * 50) |
| 116 | + prompt4 = generate_rpg_scenario( |
| 117 | + game_style="gritty", |
| 118 | + party_level=1, |
| 119 | + party_classes=["Fighter"], |
| 120 | + environment="city", |
| 121 | + quest_type="combat", |
| 122 | + difficulty="medium", |
| 123 | + magical_elements=["Street Magic", "Common Spells"] |
| 124 | + ) |
| 125 | + print(prompt4) |
| 126 | + |
| 127 | + |
| 128 | +if __name__ == "__main__": |
| 129 | + main() |
0 commit comments