Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/decompose/m_decomp_result_v1.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import textwrap

import mellea
{%- if "code" in identified_constraints | map(attribute="val_strategy") %}
from mellea.stdlib.requirement import req
from mellea.stdlib.requirements.requirement import req
{% for c in identified_constraints %}
{%- if c.val_fn %}
from validations.{{ c.val_fn_name }} import validate_input as {{ c.val_fn_name }}
Expand Down
2 changes: 1 addition & 1 deletion cli/decompose/m_decomp_result_v2.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import textwrap

import mellea
{%- if "code" in identified_constraints | map(attribute="val_strategy") %}
from mellea.stdlib.requirement import req
from mellea.stdlib.requirements.requirement import req
{% for c in identified_constraints %}
{%- if c.val_fn %}
from validations.{{ c.val_fn_name }} import validate_input as {{ c.val_fn_name }}
Expand Down
11 changes: 11 additions & 0 deletions cli/decompose/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ def finalize_result(
if log_mode == LogMode.debug:
logger.debug(" prompt_template=%s", subtask_data.prompt_template)

unknown_constraints = [
c for c in subtask_data.constraints if c not in constraint_val_data
]
if unknown_constraints:
logger.warning(
" [%02d] skipping %d unrecognized constraint(s) not in constraint_val_data",
subtask_i,
len(unknown_constraints),
)

subtask_constraints: list[ConstraintResult] = [
{
"constraint": cons_str,
Expand All @@ -433,6 +443,7 @@ def finalize_result(
"val_fn": constraint_val_data[cons_str]["val_fn"],
}
for cons_str in subtask_data.constraints
if cons_str in constraint_val_data
]

parsed_general_instructions: str = general_instructions.generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ def _default_parser(generated_str: str) -> list[SubtaskPromptConstraintsItem]:
subtask_constraint_assign = []
else:
subtask_constraint_assign = [
line.strip()[2:] if line.strip()[:2] == "- " else line.strip()
line.strip()[2:]
if line.strip()[:2] in ("- ", "* ", "• ")
else line.strip()
for line in subtask_constraint_assign_str.splitlines()
if line.strip()
]

result.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ When writing your answer, follow these additional instructions below to be succe
3. Use appropriate Python standard library modules (re, json, etc.) as needed
4. Ensure the function is simple and doesn't have unnecessary complexity
5. The validation logic should directly correspond to the provided constraint/requirement
6. If you use any standard library modules (e.g. `re`, `json`), import them inside the function body before using them

## Common Validation Patterns

Expand Down
35 changes: 34 additions & 1 deletion docs/examples/m_decompose/python/python_decompose_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def generate_python_script(
python_script_content = m_template.render(
subtasks=result["subtasks"],
user_inputs=[], # No user inputs for this simple example
identified_constraints=result["identified_constraints"],
)

# Save the generated Python script
Expand All @@ -107,6 +108,31 @@ def generate_python_script(
return py_output_file


def write_validation_files(result: DecompPipelineResult, output_dir: Path) -> int:
"""
Write validation function files alongside the generated script.

Args:
result: Decomposition results dictionary
output_dir: Directory containing the generated script

Returns:
Number of validation files written
"""
val_fn_dir = output_dir / "validations"
val_fn_dir.mkdir(exist_ok=True)
(val_fn_dir / "__init__.py").touch()

count = 0
for constraint in result["identified_constraints"]:
if constraint["val_fn"] is not None:
count += 1
with open(val_fn_dir / f"{constraint['val_fn_name']}.py", "w") as f:
f.write(constraint["val_fn"] + "\n")

return count


def run_generated_script(
script_path: Path, output_dir: Path, timeout: int = 600
) -> Path | None:
Expand Down Expand Up @@ -216,7 +242,14 @@ def main():
# Step 4: Generate Python script
script_path = generate_python_script(result, output_dir)

# Step 5: Run the generated script (optional)
# Step 5: Write validation function files (required before running the script)
val_count = write_validation_files(result, output_dir)
if val_count:
print(
f"📄 Wrote {val_count} validation file(s) to {output_dir / 'validations'}"
)

# Step 6: Run the generated script (optional)
run_generated_script(script_path, output_dir)

print("\n" + "=" * 70)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,58 @@
=== 12:28:43-INFO ======
=== 10:50:56-INFO ======
Starting Mellea session: backend=ollama, model=granite4:micro, context=SimpleContext
=== 12:28:45-INFO ======
SUCCESS
=== 12:28:47-INFO ======
FAILED. Valid: 0/1
=== 12:28:48-INFO ======
FAILED. Valid: 0/1
=== 12:28:48-INFO ======
=== 10:51:00-INFO ======
FAILED. Valid: 3/4. Failed:
- The post should include an introduction paragraph
=== 10:51:04-INFO ======
FAILED. Valid: 3/4. Failed:
- The post should include an introduction paragraph
=== 10:51:04-INFO ======
Invoking select_from_failure after 2 failed attempts.
=== 12:28:55-INFO ======
=== 10:51:06-INFO ======
SUCCESS
=== 12:28:59-INFO ======
=== 10:51:11-INFO ======
SUCCESS
=== 12:29:10-INFO ======
FAILED. Valid: 3/4
=== 12:29:19-INFO ======
FAILED. Valid: 3/4
=== 12:29:19-INFO ======
=== 10:51:19-INFO ======
FAILED. Valid: 2/4. Failed:
- The blog post must have a catchy title
- The post should include an introduction paragraph
=== 10:51:26-INFO ======
FAILED. Valid: 3/4. Failed:
- The post should include an introduction paragraph
=== 10:51:26-INFO ======
Invoking select_from_failure after 2 failed attempts.
**Title:** Kickstart Your Day: Unleash Morning Exercise's Power!

**Introduction:**
Are you tired of feeling sluggish first thing in the morning? Imagine starting your day with a burst of energy and positivity, setting the tone for everything else to come. Morning exercise isn't just about getting fit; it's a powerful way to enhance mental clarity, boost mood, and set a productive tone for the entire day. This blog post, "Kickstart Your Day: Unleash Morning Exercise's Power!" will explore how incorporating morning workouts into your routine can transform not only your physical health but also significantly impact your overall well-being and productivity.

**Benefits:**
=== 10:51:31-INFO ======
FAILED. Valid: 2/4. Failed:
- The post should include an introduction paragraph
- The blog post must have a catchy title
=== 10:51:34-INFO ======
FAILED. Valid: 2/4. Failed:
- The post should include an introduction paragraph
- The blog post must have a catchy title
=== 10:51:34-INFO ======
Invoking select_from_failure after 2 failed attempts.
=== 10:51:41-INFO ======
FAILED. Valid: 3/4. Failed:
- The post should include an introduction paragraph
=== 10:51:49-INFO ======
FAILED. Valid: 3/4. Failed:
- The post should include an introduction paragraph
=== 10:51:49-INFO ======
Invoking select_from_failure after 2 failed attempts.
**Title**: Revitalize Your Day: Unveiling the Top 3 Benefits of Morning Exercise

#### 1. **Enhanced Mental Clarity and Cognitive Function**
Engaging in morning exercise significantly boosts mental clarity, allowing individuals to approach their day with a focused mind. This heightened sense of awareness can lead to improved decision-making skills throughout the day, enhancing productivity and efficiency at work or school. Research from the *International Journal of Behavioral Nutrition and Physical Activity* indicates that regular morning exercise correlates with lower levels of cortisol, the stress hormone, leading to reduced anxiety and depression symptoms.
**Introduction**

#### 2. **Improved Mood and Reduced Stress Levels**
Morning exercise is known for its ability to elevate mood significantly, reducing symptoms of anxiety and depression. By boosting serotonin levels—often referred to as the "feel-good" hormone—morning workouts can set a positive tone for the entire day, reducing stress and enhancing overall emotional well-being.
Starting your day with a burst of energy and positivity can be achieved through various means, one of which is incorporating morning exercise into your daily routine. The benefits of this simple yet powerful practice are manifold, offering improvements in physical health, mental well-being, and overall productivity.

#### 3. **Boosted Energy Levels Throughout the Day**
Morning exercise is a powerful way to increase energy levels for several hours post-workout, allowing for sustained productivity throughout the day. This surge in energy can lead to improved performance in daily activities, whether it's meeting deadlines at work or spending quality time with family and friends.
**Main Benefits of Morning Exercise**

**Conclusion:**
1. **Boosted Metabolism**: One of the foremost advantages of engaging in morning workouts is the immediate increase in metabolic rate. This kickstarts your body's ability to burn calories more efficiently throughout the day, contributing to better weight management.

Incorporating morning exercise into your daily routine can significantly enhance various aspects of health and well-being, from mental clarity to improved mood and sustained energy levels. As highlighted in the blog post "Kickstart Your Day: Unleash Morning Exercise's Power!", these benefits not only transform physical fitness but also have a profound impact on overall productivity and happiness.
2. **Enhanced Mood and Cognitive Functioning**: Physical activity stimulates the production of endorphins, often known as "feel-good" hormones, leading to an uplift in mood. Additionally, morning exercise has been linked to improved cognitive function, including better focus, memory retention, and problem-solving skills.

The key themes we've explored—enhanced cognitive function, improved emotional health, and boosted vitality—underscore why morning exercise is not merely an activity but a transformative habit. By aligning your physical routine with your body's natural rhythms in the morning, you're essentially equipping yourself to tackle the day head-on, more focused, motivated, and ready to embrace whatever challenges come your way.
3. **Improved Quality of Sleep**: Regular physical activity can significantly enhance sleep quality. By expending energy early in the day, individuals are more likely to fall asleep faster and enjoy deeper stages of rest during the night, thus waking up feeling refreshed and ready to tackle daily challenges.

Now, imagine waking up each day feeling energized, clear-headed, and eager to make a difference. This is not just wishful thinking—it's achievable with consistent morning exercise. So why wait? Let this be the start of your journey towards a more vibrant, productive, and fulfilling life. Embrace the power of mornings, embrace the power within you, and watch as every day transforms into an opportunity to excel.
**Conclusion**

Take that first step today. Whether it's a brisk walk, a yoga session, or a high-intensity workout, the key is starting and making it a part of your daily routine. Your future self will thank you for choosing to wake up not just earlier but also more energized and ready to seize the day. Let morning exercise be the catalyst that propels you towards a healthier, happier, and more productive lifestyle.
Embracing morning exercise is not merely about burning calories or building muscle; it's a holistic approach that revitalizes your body and mind. By understanding these benefits and how they manifest in our daily lives, we are empowered to make informed decisions that align with our health goals. Whether you're aiming to reduce stress, increase productivity, or simply enjoy life more fully, starting your day with exercise can set the foundation for a healthier, happier lifestyle. So why wait? Get moving first thing in the morning and watch as it transforms every aspect of your life.
Loading
Loading