Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- __init__.py +3 -0
- __pycache__/__init__.cpython-311.pyc +0 -0
- __pycache__/engine.cpython-311.pyc +0 -0
- engine.py +31 -0
- templates/bert.yaml +11 -0
- templates/flan_t5.yaml +9 -0
- templates/llama.yaml +18 -0
- templates/mistral.yaml +12 -0
__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""PromptGuru: Modular prompt engineering with YAML templates."""
|
| 2 |
+
from .engine import PromptEngine, load_template
|
| 3 |
+
__all__ = ["PromptEngine", "load_template"]
|
__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (353 Bytes). View file
|
|
|
__pycache__/engine.cpython-311.pyc
ADDED
|
Binary file (2.67 kB). View file
|
|
|
engine.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# promptguru/engine.py
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import yaml
|
| 4 |
+
|
| 5 |
+
def load_template(model_type: str) -> dict:
|
| 6 |
+
"""Load a YAML template file for a given model type (e.g., 'mistral', 'bert')."""
|
| 7 |
+
model_type = model_type.lower()
|
| 8 |
+
template_path = Path(__file__).parent / "templates" / f"{model_type}.yaml"
|
| 9 |
+
if not template_path.exists():
|
| 10 |
+
raise FileNotFoundError(f"Template file not found for model: {model_type}")
|
| 11 |
+
with open(template_path, "r", encoding="utf-8") as f:
|
| 12 |
+
return yaml.safe_load(f)
|
| 13 |
+
|
| 14 |
+
class PromptEngine:
|
| 15 |
+
"""Minimal prompt templating engine.
|
| 16 |
+
|
| 17 |
+
Usage:
|
| 18 |
+
engine = PromptEngine(model_type="mistral", mode="eli5")
|
| 19 |
+
prompt = engine.generate_prompt("Explain quantum entanglement")
|
| 20 |
+
"""
|
| 21 |
+
def __init__(self, model_type: str, mode: str):
|
| 22 |
+
self.model_type = model_type.lower()
|
| 23 |
+
self.mode = mode.lower()
|
| 24 |
+
self._template_dict = load_template(self.model_type)
|
| 25 |
+
|
| 26 |
+
def generate_prompt(self, user_input: str) -> str:
|
| 27 |
+
"""Render a template with the given input text."""
|
| 28 |
+
if self.mode not in self._template_dict:
|
| 29 |
+
raise ValueError(f"Mode '{self.mode}' not found in {self.model_type}.yaml")
|
| 30 |
+
template = self._template_dict[self.mode]
|
| 31 |
+
return template.replace("{{input}}", user_input)
|
templates/bert.yaml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
classification: |
|
| 2 |
+
Classify the sentiment of the following text as positive, negative, or neutral.
|
| 3 |
+
Text: {{input}}
|
| 4 |
+
|
| 5 |
+
fill_mask: |
|
| 6 |
+
Fill in the missing word in the following sentence.
|
| 7 |
+
Sentence: {{input}}
|
| 8 |
+
|
| 9 |
+
qa: |
|
| 10 |
+
Extract the answer from the given context.
|
| 11 |
+
Context and Question: {{input}}
|
templates/flan_t5.yaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
eli5: |
|
| 2 |
+
Explain like I'm 5: {{input}}
|
| 3 |
+
|
| 4 |
+
devmode: |
|
| 5 |
+
Summarize technically and list risks: {{input}}
|
| 6 |
+
|
| 7 |
+
explain_and_tag: |
|
| 8 |
+
Summarize this input and assign a risk level (low, medium, high).
|
| 9 |
+
Input: {{input}}
|
templates/llama.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
eli5: |
|
| 2 |
+
<s>[INST] <<SYS>>
|
| 3 |
+
You are a helpful tutor. Explain the user's input simply and clearly.
|
| 4 |
+
<</SYS>>
|
| 5 |
+
{{input}} [/INST]
|
| 6 |
+
|
| 7 |
+
devmode: |
|
| 8 |
+
<s>[INST] <<SYS>>
|
| 9 |
+
You are a senior software engineer. Provide a structured technical analysis.
|
| 10 |
+
Include: context, constraints, assumptions, risks, and next steps.
|
| 11 |
+
<</SYS>>
|
| 12 |
+
{{input}} [/INST]
|
| 13 |
+
|
| 14 |
+
refine: |
|
| 15 |
+
<s>[INST] <<SYS>>
|
| 16 |
+
You are a precise editor. Rewrite the user's text for clarity and brevity while preserving meaning.
|
| 17 |
+
<</SYS>>
|
| 18 |
+
{{input}} [/INST]
|
templates/mistral.yaml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
eli5: |
|
| 2 |
+
You are a helpful assistant. Explain the following like I'm five.
|
| 3 |
+
Input: {{input}}
|
| 4 |
+
|
| 5 |
+
devmode: |
|
| 6 |
+
You are a senior engineer. Provide a concise, technical breakdown of the following content.
|
| 7 |
+
Include assumptions, potential risks, and an action-oriented summary.
|
| 8 |
+
Input: {{input}}
|
| 9 |
+
|
| 10 |
+
refine: |
|
| 11 |
+
You are an expert editor. Improve clarity, reduce jargon, and keep key details.
|
| 12 |
+
Text: {{input}}
|