From 5df9df23c8b273d8a21c6130daf8a0d0b4bb8b33 Mon Sep 17 00:00:00 2001 From: AngeloDanducci Date: Wed, 1 Apr 2026 10:15:11 -0400 Subject: [PATCH 1/4] decompose updates --- cli/decompose/m_decomp_result_v1.py.jinja2 | 2 +- cli/decompose/m_decomp_result_v2.py.jinja2 | 2 +- cli/decompose/pipeline.py | 11 +++++++++++ .../_subtask_constraint_assign.py | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cli/decompose/m_decomp_result_v1.py.jinja2 b/cli/decompose/m_decomp_result_v1.py.jinja2 index 1f1e3646e..4bc899a61 100644 --- a/cli/decompose/m_decomp_result_v1.py.jinja2 +++ b/cli/decompose/m_decomp_result_v1.py.jinja2 @@ -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 }} diff --git a/cli/decompose/m_decomp_result_v2.py.jinja2 b/cli/decompose/m_decomp_result_v2.py.jinja2 index 9b1bb13c6..0341460c8 100644 --- a/cli/decompose/m_decomp_result_v2.py.jinja2 +++ b/cli/decompose/m_decomp_result_v2.py.jinja2 @@ -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 }} diff --git a/cli/decompose/pipeline.py b/cli/decompose/pipeline.py index 91fa8abfb..ef6eb1b4a 100644 --- a/cli/decompose/pipeline.py +++ b/cli/decompose/pipeline.py @@ -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, @@ -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( diff --git a/cli/decompose/prompt_modules/subtask_constraint_assign/_subtask_constraint_assign.py b/cli/decompose/prompt_modules/subtask_constraint_assign/_subtask_constraint_assign.py index 45f56df0a..56dc09751 100644 --- a/cli/decompose/prompt_modules/subtask_constraint_assign/_subtask_constraint_assign.py +++ b/cli/decompose/prompt_modules/subtask_constraint_assign/_subtask_constraint_assign.py @@ -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( From efc0f5ecce23cb9c4a7d9aa7fa90f8860c90cf67 Mon Sep 17 00:00:00 2001 From: AngeloDanducci Date: Wed, 1 Apr 2026 10:17:03 -0400 Subject: [PATCH 2/4] update decompose tutorial --- .../python/python_decompose_example.py | 35 ++- .../python/python_decompose_final_output.txt | 74 ++--- .../python/python_decompose_result.json | 189 ++++++++---- .../python/python_decompose_result.py | 281 +++++++++--------- .../python/validations/__init__.py | 0 .../python/validations/val_fn_2.py | 23 ++ 6 files changed, 380 insertions(+), 222 deletions(-) create mode 100644 docs/examples/m_decompose/python/validations/__init__.py create mode 100644 docs/examples/m_decompose/python/validations/val_fn_2.py diff --git a/docs/examples/m_decompose/python/python_decompose_example.py b/docs/examples/m_decompose/python/python_decompose_example.py index 757296b56..de6fc2609 100644 --- a/docs/examples/m_decompose/python/python_decompose_example.py +++ b/docs/examples/m_decompose/python/python_decompose_example.py @@ -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 @@ -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: @@ -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) diff --git a/docs/examples/m_decompose/python/python_decompose_final_output.txt b/docs/examples/m_decompose/python/python_decompose_final_output.txt index 76ac65b58..04933353f 100644 --- a/docs/examples/m_decompose/python/python_decompose_final_output.txt +++ b/docs/examples/m_decompose/python/python_decompose_final_output.txt @@ -1,45 +1,49 @@ -=== 12:28:43-INFO ====== +=== 10:06: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:07:00-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:07:03-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:07:03-INFO ====== Invoking select_from_failure after 2 failed attempts. -=== 12:28:55-INFO ====== +=== 10:07:05-INFO ====== SUCCESS -=== 12:28:59-INFO ====== +=== 10:07:11-INFO ====== SUCCESS -=== 12:29:10-INFO ====== -FAILED. Valid: 3/4 -=== 12:29:19-INFO ====== -FAILED. Valid: 3/4 -=== 12:29:19-INFO ====== +=== 10:07:18-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:07:25-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:07:25-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:** - -#### 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. - -#### 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. - -#### 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. +=== 10:07:33-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:07:41-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:07:41-INFO ====== +Invoking select_from_failure after 2 failed attempts. +=== 10:07:51-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:08:01-INFO ====== +FAILED. Valid: 3/4. Failed: + - The post should include an introduction paragraph +=== 10:08:01-INFO ====== +Invoking select_from_failure after 2 failed attempts. +**Morning Exercise Magic: Unleashing the Power of Your Day** -**Conclusion:** +Waking up before the sun does not mean you're depriving yourself of daylight; it means embracing a lifestyle full of vitality and positivity. Engaging in morning exercises offers more than just physical fitness—it transforms your entire day, enhancing mood, energy levels, and sleep quality. Let's explore how starting your day with exercise can significantly impact your well-being. -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. +Starting your day with a burst of activity sets the stage for an uplifting mood throughout the rest of the day. Physical movement stimulates endorphins—the body's natural feel-good chemicals—helping to alleviate stress and elevate your spirits. A study published in *Psychological Science* highlights that those who exercise first thing in the morning report a noticeable reduction in symptoms related to depression and anxiety compared to late-day exercisers (Smith et al., 2020). For instance, Sarah, an accountant, often feels drained by mid-morning due to work-related stress. Since adopting a simple yoga routine at sunrise, she notices her mood improves significantly during her workday, allowing her to tackle tasks with calm and focus. -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. +Morning exercise is like giving your body the perfect energy boost it needs for the day ahead. This increase in vigor comes from better circulation, oxygen flow, and metabolic activity triggered by physical activity. Research from the *Journal of Strength and Conditioning* found that individuals who work out in the morning report higher levels of energy throughout their daily activities compared to those who prefer exercising later (Johnson & Lee, 2021). Mark, a teacher, frequently battles fatigue through long shifts. Since adding a brisk jog before school starts, he's noticed not only increased energy during lessons but also an easier time staying alert and engaged throughout the day. -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. +Engaging in morning exercise can significantly enhance the quality of your sleep at night. This improvement is largely due to how exercising in the morning helps regulate your circadian rhythms, promoting deeper, more restorative sleep. A study from *Sleep Medicine* demonstrated that those who exercise in the morning experience longer periods of deep sleep and fewer interruptions throughout the night compared to late-day exercisers (Brown & Green, 2022). Lisa, a mother of two, has observed her children's sleep patterns improve after she began an early morning swimming routine. She wakes up feeling refreshed and ready for each new day without feeling sluggish. -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. +The benefits of morning exercise extend far beyond just physical health—they set the foundation for a more positive, energetic, and well-rested life. Whether you're looking to uplift your mood, stay energized throughout your tasks, or simply improve your rest, incorporating morning workouts into your routine can make all the difference. Take that first step today and experience the transformation for yourself! diff --git a/docs/examples/m_decompose/python/python_decompose_result.json b/docs/examples/m_decompose/python/python_decompose_result.json index 8a2903782..31a074e32 100644 --- a/docs/examples/m_decompose/python/python_decompose_result.json +++ b/docs/examples/m_decompose/python/python_decompose_result.json @@ -1,119 +1,202 @@ { "original_task_prompt": "Write a short blog post about the benefits of morning exercise.\nInclude a catchy title, an introduction paragraph, three main benefits\nwith explanations, and a conclusion that encourages readers to start\ntheir morning exercise routine.", "subtask_list": [ - "1. Create a catchy title for the blog post about the benefits of morning exercise. -", - "2. Write an introduction paragraph that sets the stage for the blog post. -", - "3. Identify and explain three main benefits of morning exercise with detailed explanations. -", - "4. Write a conclusion that encourages readers to start their morning exercise routine. -", - "5. Compile the title, introduction, three main benefits, and conclusion into a single cohesive blog post. -" + "1. Brainstorm and select a catchy title related to the benefits of morning exercise. -", + "2. Write an introduction paragraph that engages readers and introduces the topic of morning exercise. -", + "3. Identify three main benefits of morning exercise, then write detailed explanations for each benefit. -", + "4. Compile the identified benefits with their explanations into a structured format for the blog post. -", + "5. Write a conclusion paragraph that encourages readers to start incorporating morning exercise into their routine. -", + "6. Combine all parts (title, introduction, benefits explanation, and conclusion) into a cohesive short blog post. -" ], "identified_constraints": [ { - "constraint": "Include a catchy title", - "validation_strategy": "llm" + "constraint": "The blog post must have a catchy title", + "val_strategy": "llm", + "val_fn": null, + "val_fn_name": "val_fn_1" }, { - "constraint": "Include an introduction paragraph", - "validation_strategy": "llm" + "constraint": "The post should include an introduction paragraph", + "val_strategy": "code", + "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False", + "val_fn_name": "val_fn_2" }, { - "constraint": "Include three main benefits with explanations", - "validation_strategy": "llm" + "constraint": "Three main benefits of morning exercise with explanations are required", + "val_strategy": "llm", + "val_fn": null, + "val_fn_name": "val_fn_3" }, { - "constraint": "Include a conclusion that encourages readers to start their morning exercise routine", - "validation_strategy": "llm" + "constraint": "A conclusion that encourages readers to start their morning exercise routine is necessary", + "val_strategy": "llm", + "val_fn": null, + "val_fn_name": "val_fn_4" } ], "subtasks": [ { - "subtask": "1. Create a catchy title for the blog post about the benefits of morning exercise. -", + "subtask": "1. Brainstorm and select a catchy title related to the benefits of morning exercise. -", "tag": "BLOG_TITLE", "constraints": [ { - "constraint": "Include a catchy title", - "validation_strategy": "llm" + "constraint": "The blog post must have a catchy title", + "val_strategy": "llm", + "val_fn_name": "val_fn_1", + "val_fn": null + }, + { + "constraint": "The post should include an introduction paragraph", + "val_strategy": "code", + "val_fn_name": "val_fn_2", + "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + }, + { + "constraint": "Three main benefits of morning exercise with explanations are required", + "val_strategy": "llm", + "val_fn_name": "val_fn_3", + "val_fn": null + }, + { + "constraint": "A conclusion that encourages readers to start their morning exercise routine is necessary", + "val_strategy": "llm", + "val_fn_name": "val_fn_4", + "val_fn": null } ], - "prompt_template": "Your task is to create a catchy title for a blog post about the benefits of morning exercise. Follow these steps to accomplish your task:\n\n1. **Understand the Topic**: The blog post will focus on the benefits of morning exercise. The title should be engaging and clearly convey the main topic of the post.\n\n2. **Identify Key Elements**: Consider the key elements that make morning exercise beneficial. These could include improved mood, increased energy, better focus, and enhanced metabolism.\n\n3. **Use Power Words**: Incorporate power words that evoke curiosity, excitement, or a sense of urgency. Examples include \"Boost,\" \"Transform,\" \"Unlock,\" \"Energize,\" and \"Revitalize.\"\n\n4. **Keep It Concise**: The title should be short and to the point, ideally between 5 to 10 words. It should be easy to read and remember.\n\n5. **Make It Action-Oriented**: Use verbs that encourage action, such as \"Start,\" \"Jumpstart,\" \"Kickstart,\" or \"Ignite.\"\n\n6. **Consider SEO**: Think about common search terms related to morning exercise. Including relevant keywords can help improve the post's visibility.\n\n7. **Examples for Inspiration**:\n - \"Jumpstart Your Day: The Power of Morning Exercise\"\n - \"Energize Your Mornings: Unlock the Benefits of Morning Exercise\"\n - \"Transform Your Day with Morning Exercise\"\n - \"Boost Your Energy: The Magic of Morning Workouts\"\n - \"Revitalize Your Mornings: The Benefits of Morning Exercise\"\n\n8. **Create the Title**: Based on the above guidelines, create a catchy and engaging title for the blog post. Ensure it captures the essence of the topic and entices readers to click and read more.\n\nYour final answer should be only the title text.", + "prompt_template": "Your task is to brainstorm and select a catchy title related to the benefits of morning exercise for a blog post. Follow these steps to accomplish your task:\n\n1. **Understand the Topic**:\n Begin by reflecting on the topic, which is the benefits of morning exercise. Consider what makes morning workouts unique and advantageous.\n\n2. **Brainstorm Title Ideas**:\n Generate several title options that are catchy, engaging, and clearly indicate the content of your blog post. The titles should pique readers' interest and accurately represent the topic.\n\n3. **Select the Best Title**:\n From your brainstormed list, choose the most compelling and relevant title for a blog post about the benefits of morning exercise. Ensure it is concise, informative, and appealing to your target audience.\n\n4. **Finalize Your Choice**:\n Once you've selected the best title, prepare to use it as the basis for your blog post. This chosen title will be referenced in subsequent steps for compiling the complete blog post content.\n\nRemember, your goal is to create a title that effectively communicates the value of morning exercise and encourages readers to continue reading the blog post.", + "general_instructions": "1. Reflect on the topic of benefits of morning exercise to understand its unique aspects.\n2. Generate multiple catchy, engaging, and informative title options that accurately represent the content of a blog post about this topic.\n3. From the brainstormed titles, select the most compelling and relevant one for the target audience, ensuring it is concise and appealing.\n4. Finalize the chosen title to be used as the basis for the blog post content compilation.", "input_vars_required": [], "depends_on": [] }, { - "subtask": "2. Write an introduction paragraph that sets the stage for the blog post. -", + "subtask": "2. Write an introduction paragraph that engages readers and introduces the topic of morning exercise. -", "tag": "INTRODUCTION", - "constraints": [ - { - "constraint": "Include an introduction paragraph", - "validation_strategy": "llm" - } - ], - "prompt_template": "Your task is to write an engaging introduction paragraph for a blog post about the benefits of morning exercise. The introduction should set the stage for the blog post, capturing the reader's attention and providing a brief overview of what will be discussed.\n\nTo accomplish this, follow these steps:\n\n1. **Understand the Context**:\n - The blog post is about the benefits of morning exercise.\n - The title of the blog post is: {{BLOG_TITLE}}\n\n2. **Craft the Introduction**:\n - Start with a hook that grabs the reader's attention. This could be a question, a surprising fact, or a relatable scenario.\n - Briefly introduce the topic of morning exercise and why it is important.\n - Provide a smooth transition to the main benefits that will be discussed in the blog post.\n\n3. **Ensure Engagement**:\n - Use a conversational and engaging tone to connect with the readers.\n - Keep the introduction concise and to the point, ideally between 3 to 5 sentences.\n\nHere is an example structure to guide your writing:\n- **Sentence 1**: Hook to grab the reader's attention.\n- **Sentence 2**: Introduce the topic of morning exercise.\n- **Sentence 3**: Briefly mention the benefits that will be discussed.\n- **Sentence 4**: Transition to the main content of the blog post.\n\nEnsure that the introduction flows naturally and sets the stage for the rest of the blog post. You should write only the introduction paragraph, do not include the guidance structure.", + "constraints": [], + "prompt_template": "Your task is to write an introduction paragraph for a blog post about the benefits of morning exercise. This paragraph should be engaging, capture the reader's attention, and introduce the topic effectively. Follow these steps:\n\n1. **Understand the Topic**:\n Begin by reviewing the overall theme of the blog post, which focuses on the benefits of morning exercise. Keep this in mind as you craft your introduction.\n\n2. **Engage Readers**:\n Start with a hook to draw readers into the topic. This could be an intriguing question, a surprising fact, or a relatable scenario related to mornings and exercise.\n\n3. **Introduce Morning Exercise**:\n After capturing attention, briefly introduce morning exercise as the subject of your blog post. Mention that you will explore its benefits in detail throughout the article.\n\n4. **Set Expectations**:\n Conclude the introduction by hinting at what readers can expect to learn from the rest of the post. This should create anticipation and encourage them to continue reading.\n\nWrite a concise yet compelling introduction paragraph (approximately 5-7 sentences) that adheres to these guidelines, ensuring it sets the stage for the detailed exploration of morning exercise benefits in subsequent sections of your blog post.", + "general_instructions": "1. Begin by understanding the overarching theme of the blog post, which centers on the advantages of morning exercise.\n2. Craft an engaging hook to captivate readers' interest, using a compelling question, surprising fact, or relatable morning scenario related to exercise.\n3. Introduce morning exercise as the topic of discussion, indicating that its benefits will be explored in detail throughout the article.\n4. Conclude the introduction by providing a sneak peek into what readers can anticipate learning from the rest of the post, fostering curiosity and encouraging further reading.\n5. Ensure the introduction is concise yet compelling, consisting of approximately 5-7 sentences, setting the stage for an in-depth examination of morning exercise benefits in subsequent sections.", "input_vars_required": [], - "depends_on": [ - "BLOG_TITLE" - ] + "depends_on": [] + }, + { + "subtask": "3. Identify three main benefits of morning exercise, then write detailed explanations for each benefit. -", + "tag": "BENEFITS_EXPLANATION", + "constraints": [], + "prompt_template": "Your task is to identify three main benefits of morning exercise and provide detailed explanations for each. Follow these steps to accomplish your task:\n\n1. **Research Morning Exercise Benefits**: Begin by researching the advantages associated with morning workouts. Focus on finding credible sources that highlight key benefits. Some common benefits include improved mood, increased energy levels throughout the day, and better sleep quality.\n\n2. **Select Three Key Benefits**: From your research, choose three of the most significant benefits to focus on for this blog post. Ensure these benefits are well-supported by evidence from reliable sources.\n\n3. **Write Detailed Explanations**: For each selected benefit, write a detailed explanation. Each explanation should include:\n - A clear statement of the benefit.\n - Scientific or empirical evidence supporting the benefit.\n - Practical examples or anecdotes to illustrate how this benefit manifests in real life.\n\n4. **Format for Blog Post**: Structure your explanations in a way that they can be easily integrated into the blog post format. Consider using bullet points or numbered lists for clarity if needed.\n\n5. **Compile Explanations**: Compile these detailed explanations into a structured format, ready to be combined with other parts of the blog post (title and conclusion) in the next steps.\n\nEnsure that your explanations are clear, informative, and engaging, maintaining a tone suitable for a health and wellness blog audience.", + "general_instructions": "1. Conduct research to identify advantages of morning exercise, focusing on credible sources that highlight key benefits such as improved mood, increased energy levels, and better sleep quality.\n2. From the gathered information, select three most significant benefits relevant for a blog post, ensuring they are well-supported by evidence from reliable sources.\n3. For each selected benefit, craft detailed explanations including:\n - A clear statement of the benefit.\n - Scientific or empirical evidence supporting the benefit.\n - Practical examples or anecdotes to illustrate real-life manifestation of this benefit.\n4. Structure these explanations in a format suitable for a blog post, using bullet points or numbered lists if necessary for clarity.\n5. Compile the detailed explanations into a cohesive and organized format, ready for integration with other components of the blog post like title and conclusion.\nEnsure all explanations are clear, informative, engaging, and tailored to a health and wellness audience.", + "input_vars_required": [], + "depends_on": [] }, { - "subtask": "3. Identify and explain three main benefits of morning exercise with detailed explanations. -", - "tag": "BENEFITS", + "subtask": "4. Compile the identified benefits with their explanations into a structured format for the blog post. -", + "tag": "STRUCTURED_BENEFITS", "constraints": [ { - "constraint": "Include three main benefits with explanations", - "validation_strategy": "llm" + "constraint": "The blog post must have a catchy title", + "val_strategy": "llm", + "val_fn_name": "val_fn_1", + "val_fn": null + }, + { + "constraint": "The post should include an introduction paragraph", + "val_strategy": "code", + "val_fn_name": "val_fn_2", + "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + }, + { + "constraint": "Three main benefits of morning exercise with explanations are required", + "val_strategy": "llm", + "val_fn_name": "val_fn_3", + "val_fn": null + }, + { + "constraint": "A conclusion that encourages readers to start their morning exercise routine is necessary", + "val_strategy": "llm", + "val_fn_name": "val_fn_4", + "val_fn": null } ], - "prompt_template": "Your task is to identify and explain three main benefits of morning exercise with detailed explanations. Follow these steps to accomplish your task:\n\nFirst, review the title and introduction created in the previous steps to understand the context and tone of the blog post:\n\n{{BLOG_TITLE}}\n\n\n{{INTRODUCTION}}\n\n\nNext, research and identify three main benefits of morning exercise. These benefits should be supported by evidence or expert opinions to ensure credibility.\n\nFor each benefit, provide a detailed explanation that includes:\n- The specific benefit of morning exercise\n- How this benefit positively impacts health, well-being, or daily life\n- Any relevant studies, expert opinions, or personal anecdotes that support the benefit\n\nEnsure that the explanations are clear, concise, and engaging to keep the reader interested.\n\nFinally, present the three main benefits with their detailed explanations in a structured format that can be easily integrated into the blog post.", + "prompt_template": "Your task is to compile the identified benefits of morning exercise and their detailed explanations into a structured format suitable for a blog post. Follow these steps to accomplish your task:\n\nFirst, review the benefits of morning exercise that have been identified and explained in the previous step:\n\n{{BENEFITS_EXPLANATION}}\n\n\nNext, organize these benefits into a clear and logical structure for the blog post. A common format for presenting benefits is to list each benefit as a distinct point or heading, followed by an explanation of that benefit.\n\nFor example, you might structure your compiled benefits like this:\n\n### Benefit 1: [Benefit Name]\n[Detailed Explanation of the benefit]\n\n### Benefit 2: [Benefit Name]\n[Detailed Explanation of the benefit]\n\n### Benefit 3: [Benefit Name]\n[Detailed Explanation of the benefit]\n\nEnsure that each benefit is presented clearly and concisely, with a heading that accurately reflects the nature of the benefit. The explanation should be comprehensive yet easy to understand, providing readers with valuable insights into why morning exercise is beneficial.\n\nFinally, ensure this structured format aligns with the overall flow and style of the blog post being created. This compiled version will be used in conjunction with other parts of the blog post (title, introduction, conclusion) to form a cohesive piece of content.", + "general_instructions": "Review the identified benefits of morning exercise and their detailed explanations from the previous step.\n\nOrganize these benefits into a clear and logical structure for a blog post, listing each benefit as a distinct point or heading followed by an explanation. Ensure that each benefit is presented clearly and concisely with an accurate heading reflecting its nature, and provide comprehensive yet easy-to-understand explanations.\n\nAlign this structured format with the overall flow and style of the intended blog post to create cohesive content when combined with other parts like title, introduction, and conclusion.", "input_vars_required": [], "depends_on": [ - "BLOG_TITLE", - "INTRODUCTION" + "BENEFITS_EXPLANATION" ] }, { - "subtask": "4. Write a conclusion that encourages readers to start their morning exercise routine. -", + "subtask": "5. Write a conclusion paragraph that encourages readers to start incorporating morning exercise into their routine. -", "tag": "CONCLUSION", "constraints": [ { - "constraint": "Include a conclusion that encourages readers to start their morning exercise routine", - "validation_strategy": "llm" + "constraint": "The blog post must have a catchy title", + "val_strategy": "llm", + "val_fn_name": "val_fn_1", + "val_fn": null + }, + { + "constraint": "The post should include an introduction paragraph", + "val_strategy": "code", + "val_fn_name": "val_fn_2", + "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + }, + { + "constraint": "Three main benefits of morning exercise with explanations are required", + "val_strategy": "llm", + "val_fn_name": "val_fn_3", + "val_fn": null + }, + { + "constraint": "A conclusion that encourages readers to start their morning exercise routine is necessary", + "val_strategy": "llm", + "val_fn_name": "val_fn_4", + "val_fn": null } ], - "prompt_template": "Your task is to write a compelling conclusion for a blog post about the benefits of morning exercise. The conclusion should encourage readers to start their morning exercise routine. Follow these steps to accomplish your task:\n\nFirst, review the title and introduction of the blog post to understand the context and tone:\n\n{{BLOG_TITLE}}\n\n\n{{INTRODUCTION}}\n\n\nNext, consider the three main benefits of morning exercise that have been previously identified and explained:\n\n{{BENEFITS}}\n\n\nUse the information from the title, introduction, and benefits to craft a conclusion that:\n1. Summarizes the key points discussed in the blog post.\n2. Reinforces the importance of morning exercise.\n3. Encourages readers to take action and start their morning exercise routine.\n4. Maintains a positive and motivating tone.\n\nEnsure the conclusion is concise, engaging, and leaves readers feeling inspired to make a change in their daily routine.\n\nFinally, write the conclusion paragraph that encourages readers to start their morning exercise routine.", + "prompt_template": "Your task is to write a conclusion paragraph that encourages readers to start incorporating morning exercise into their routine for the blog post about the benefits of morning exercise. Follow these steps:\n\n1. **Review Previous Steps**:\n Begin by reviewing the structured benefits and explanations from previous steps, which can be found here:\n \n {{STRUCTURED_BENEFITS}}\n \n\n This will help you understand the key points that have already been covered in the blog post.\n\n2. **Summarize Key Benefits**:\n Briefly summarize the main benefits of morning exercise as discussed earlier to remind readers of their significance. You can refer to {{BENEFITS_EXPLANATION}} for specifics on each benefit.\n\n3. **Craft an Encouraging Message**:\n Write a paragraph that motivates readers to start their own morning exercise routine. Use persuasive language and emphasize the positive impact of making this change.\n\n4. **Structure the Conclusion**:\n Ensure your conclusion is concise, engaging, and effectively encourages action from the reader. It should wrap up the blog post by reinforcing the importance of morning exercise and inspiring readers to take the first step towards integrating it into their daily routine.\n\nHere's a suggested structure for your conclusion paragraph:\n - Briefly restate or reference one or two key benefits discussed in the body of the blog post.\n - Use motivational language to encourage readers to adopt morning exercise.\n - Provide a clear, actionable call to action (e.g., \"Start today with a short walk around your neighborhood\").\n\n5. **Finalize and Output**:\n Once you have written the conclusion paragraph, ensure it is polished and ready for integration into the final blog post. Do not include any additional information or explanation beyond the requested conclusion text.", + "general_instructions": "Review structured benefits of morning exercise from previous steps to understand key points.\n\nSummarize main benefits, referring to specific explanations if needed.\n\nCraft an encouraging message using persuasive language to motivate readers to start a morning exercise routine. Emphasize positive impacts of this change.\n\nStructure the conclusion in a concise and engaging manner, reinforcing importance of morning exercise and inspiring action from the reader. Include a clear call to action, such as \"Start today with a short walk around your neighborhood\".\n\nEnsure the final conclusion paragraph is polished and ready for integration into the blog post without additional information or explanation beyond the requested text.", "input_vars_required": [], "depends_on": [ - "BLOG_TITLE", - "INTRODUCTION", - "BENEFITS" + "STRUCTURED_BENEFITS", + "BENEFITS_EXPLANATION" ] }, { - "subtask": "5. Compile the title, introduction, three main benefits, and conclusion into a single cohesive blog post. -", + "subtask": "6. Combine all parts (title, introduction, benefits explanation, and conclusion) into a cohesive short blog post. -", "tag": "FINAL_BLOG_POST", "constraints": [ { - "constraint": "Include a catchy title", - "validation_strategy": "llm" + "constraint": "The blog post must have a catchy title", + "val_strategy": "llm", + "val_fn_name": "val_fn_1", + "val_fn": null }, { - "constraint": "Include an introduction paragraph", - "validation_strategy": "llm" + "constraint": "The post should include an introduction paragraph", + "val_strategy": "code", + "val_fn_name": "val_fn_2", + "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" }, { - "constraint": "Include three main benefits with explanations", - "validation_strategy": "llm" + "constraint": "Three main benefits of morning exercise with explanations are required", + "val_strategy": "llm", + "val_fn_name": "val_fn_3", + "val_fn": null }, { - "constraint": "Include a conclusion that encourages readers to start their morning exercise routine", - "validation_strategy": "llm" + "constraint": "A conclusion that encourages readers to start their morning exercise routine is necessary", + "val_strategy": "llm", + "val_fn_name": "val_fn_4", + "val_fn": null } ], - "prompt_template": "Your task is to compile the title, introduction, three main benefits, and conclusion into a single cohesive blog post about the benefits of morning exercise.\n\nTo accomplish this, follow these steps:\n\n1. **Review the Components**:\n Carefully review the title, introduction, three main benefits, and conclusion that have been generated in the previous steps. These components are provided below:\n\n \n {{BLOG_TITLE}}\n \n\n \n {{INTRODUCTION}}\n \n\n \n {{BENEFITS}}\n \n\n \n {{CONCLUSION}}\n \n\n2. **Structure the Blog Post**:\n Organize the components into a well-structured blog post. The structure should include:\n - The catchy title at the beginning.\n - The introduction paragraph that sets the stage for the blog post.\n - The three main benefits with detailed explanations.\n - The conclusion that encourages readers to start their morning exercise routine.\n\n3. **Ensure Cohesion**:\n Make sure the blog post flows smoothly from one section to the next. The transitions between the introduction, benefits, and conclusion should be natural and logical.\n\n4. **Check for Consistency**:\n Verify that the tone and style are consistent throughout the blog post. Ensure that the language used in the title, introduction, benefits, and conclusion aligns with the overall theme of the blog post.\n\n5. **Final Review**:\n Read through the entire blog post to ensure it is cohesive, well-organized, and free of any grammatical or spelling errors. Make any necessary adjustments to improve clarity and readability.\n\n6. **Output the Blog Post**:\n Provide the final compiled blog post as your answer. Ensure that the output includes only the blog post text without any additional information or instructions.\n\nBy following these steps, you will create a single cohesive blog post that effectively communicates the benefits of morning exercise.", + "prompt_template": "Your task is to combine all the identified parts\u2014the catchy title, engaging introduction, detailed explanations of three main benefits, and an encouraging conclusion\u2014into a cohesive short blog post about the benefits of morning exercise. Follow these steps to accomplish your task:\n\nFirst, review the components you have already generated for this subtask:\n\n{{BLOG_TITLE}}\n{{INTRODUCTION}}\n{{BENEFITS_EXPLANATION}}\n{{STRUCTURED_BENEFITS}}\n{{CONCLUSION}}\n\n\nNext, structure the blog post by arranging these components in a logical order. A typical structure for a short blog post would be:\n1. **Title**: Start with your catchy title related to morning exercise benefits.\n2. **Introduction**: Follow the title with an engaging introduction paragraph that sets the stage and introduces the topic of morning exercise.\n3. **Main Benefits Section**: Present the three main benefits of morning exercise, each accompanied by a detailed explanation as you have generated in {{BENEFITS_EXPLANATION}}. Ensure these explanations are clear, concise, and supported by the structured information in {{STRUCTURED_BENEFITS}}.\n4. **Conclusion**: End with an encouraging conclusion that motivates readers to start or continue their morning exercise routine. Use the provided {{CONCLUSION}} for this purpose.\n\nWrite a cohesive blog post by weaving these components together, ensuring smooth transitions between sections. Maintain a friendly and informative tone throughout the post, keeping it concise yet comprehensive.\n\nFinally, present only the completed short blog post as your answer without any additional information or explanation.", + "general_instructions": "1. Review the components generated for this subtask: catchy title, engaging introduction, detailed explanations of three main benefits, and an encouraging conclusion related to morning exercise.\n2. Structure the blog post with a logical order:\n - **Title**: Start with the catchy title.\n - **Introduction**: Follow the title with an engaging paragraph introducing the topic of morning exercise.\n - **Main Benefits Section**: Present three main benefits, each accompanied by a detailed explanation supported by structured information.\n - **Conclusion**: End with an encouraging conclusion motivating readers to adopt or maintain a morning exercise routine.\n3. Weave these components together into a cohesive blog post, ensuring smooth transitions between sections.\n4. Maintain a friendly and informative tone throughout the post, keeping it concise yet comprehensive.\n5. Present only the completed short blog post as the final answer without additional information or explanation.", "input_vars_required": [], "depends_on": [ "BLOG_TITLE", "INTRODUCTION", - "BENEFITS", + "BENEFITS_EXPLANATION", + "STRUCTURED_BENEFITS", "CONCLUSION" ] } diff --git a/docs/examples/m_decompose/python/python_decompose_result.py b/docs/examples/m_decompose/python/python_decompose_result.py index e4f77c9e3..25a2fe4ac 100644 --- a/docs/examples/m_decompose/python/python_decompose_result.py +++ b/docs/examples/m_decompose/python/python_decompose_result.py @@ -1,214 +1,229 @@ -# pytest: skip_always import textwrap -import mellea - -# Note: This is an example of an intermediary result from using decompose in python_decompose_example.py, not an example of how to use decompose. +from validations.val_fn_2 import validate_input as val_fn_2 +import mellea +from mellea.stdlib.requirements.requirement import req m = mellea.start_session() -# 1. Create a catchy title for the blog post about the benefits of morning exercise. - - BLOG_TITLE +# 1. Brainstorm and select a catchy title related to the benefits of morning exercise. - - BLOG_TITLE blog_title = m.instruct( textwrap.dedent( R""" - Your task is to create a catchy title for a blog post about the benefits of morning exercise. Follow these steps to accomplish your task: - - 1. **Understand the Topic**: The blog post will focus on the benefits of morning exercise. The title should be engaging and clearly convey the main topic of the post. - - 2. **Identify Key Elements**: Consider the key elements that make morning exercise beneficial. These could include improved mood, increased energy, better focus, and enhanced metabolism. - - 3. **Use Power Words**: Incorporate power words that evoke curiosity, excitement, or a sense of urgency. Examples include "Boost," "Transform," "Unlock," "Energize," and "Revitalize." + Your task is to brainstorm and select a catchy title related to the benefits of morning exercise for a blog post. Follow these steps to accomplish your task: - 4. **Keep It Concise**: The title should be short and to the point, ideally between 5 to 10 words. It should be easy to read and remember. + 1. **Understand the Topic**: + Begin by reflecting on the topic, which is the benefits of morning exercise. Consider what makes morning workouts unique and advantageous. - 5. **Make It Action-Oriented**: Use verbs that encourage action, such as "Start," "Jumpstart," "Kickstart," or "Ignite." + 2. **Brainstorm Title Ideas**: + Generate several title options that are catchy, engaging, and clearly indicate the content of your blog post. The titles should pique readers' interest and accurately represent the topic. - 6. **Consider SEO**: Think about common search terms related to morning exercise. Including relevant keywords can help improve the post's visibility. + 3. **Select the Best Title**: + From your brainstormed list, choose the most compelling and relevant title for a blog post about the benefits of morning exercise. Ensure it is concise, informative, and appealing to your target audience. - 7. **Examples for Inspiration**: - - "Jumpstart Your Day: The Power of Morning Exercise" - - "Energize Your Mornings: Unlock the Benefits of Morning Exercise" - - "Transform Your Day with Morning Exercise" - - "Boost Your Energy: The Magic of Morning Workouts" - - "Revitalize Your Mornings: The Benefits of Morning Exercise" + 4. **Finalize Your Choice**: + Once you've selected the best title, prepare to use it as the basis for your blog post. This chosen title will be referenced in subsequent steps for compiling the complete blog post content. - 8. **Create the Title**: Based on the above guidelines, create a catchy and engaging title for the blog post. Ensure it captures the essence of the topic and entices readers to click and read more. - - Your final answer should be only the title text. + Remember, your goal is to create a title that effectively communicates the value of morning exercise and encourages readers to continue reading the blog post. """.strip() ), - requirements=["Include a catchy title"], + requirements=[ + "The blog post must have a catchy title", + req( + "The post should include an introduction paragraph", validation_fn=val_fn_2 + ), + "Three main benefits of morning exercise with explanations are required", + "A conclusion that encourages readers to start their morning exercise routine is necessary", + ], ) assert blog_title.value is not None, 'ERROR: task "blog_title" execution failed' -# 2. Write an introduction paragraph that sets the stage for the blog post. - - INTRODUCTION +# 2. Write an introduction paragraph that engages readers and introduces the topic of morning exercise. - - INTRODUCTION introduction = m.instruct( textwrap.dedent( R""" - Your task is to write an engaging introduction paragraph for a blog post about the benefits of morning exercise. The introduction should set the stage for the blog post, capturing the reader's attention and providing a brief overview of what will be discussed. + Your task is to write an introduction paragraph for a blog post about the benefits of morning exercise. This paragraph should be engaging, capture the reader's attention, and introduce the topic effectively. Follow these steps: - To accomplish this, follow these steps: + 1. **Understand the Topic**: + Begin by reviewing the overall theme of the blog post, which focuses on the benefits of morning exercise. Keep this in mind as you craft your introduction. - 1. **Understand the Context**: - - The blog post is about the benefits of morning exercise. - - The title of the blog post is: {{BLOG_TITLE}} + 2. **Engage Readers**: + Start with a hook to draw readers into the topic. This could be an intriguing question, a surprising fact, or a relatable scenario related to mornings and exercise. - 2. **Craft the Introduction**: - - Start with a hook that grabs the reader's attention. This could be a question, a surprising fact, or a relatable scenario. - - Briefly introduce the topic of morning exercise and why it is important. - - Provide a smooth transition to the main benefits that will be discussed in the blog post. + 3. **Introduce Morning Exercise**: + After capturing attention, briefly introduce morning exercise as the subject of your blog post. Mention that you will explore its benefits in detail throughout the article. - 3. **Ensure Engagement**: - - Use a conversational and engaging tone to connect with the readers. - - Keep the introduction concise and to the point, ideally between 3 to 5 sentences. + 4. **Set Expectations**: + Conclude the introduction by hinting at what readers can expect to learn from the rest of the post. This should create anticipation and encourage them to continue reading. - Here is an example structure to guide your writing: - - **Sentence 1**: Hook to grab the reader's attention. - - **Sentence 2**: Introduce the topic of morning exercise. - - **Sentence 3**: Briefly mention the benefits that will be discussed. - - **Sentence 4**: Transition to the main content of the blog post. - - Ensure that the introduction flows naturally and sets the stage for the rest of the blog post. You should write only the introduction paragraph, do not include the guidance structure. + Write a concise yet compelling introduction paragraph (approximately 5-7 sentences) that adheres to these guidelines, ensuring it sets the stage for the detailed exploration of morning exercise benefits in subsequent sections of your blog post. """.strip() ), - requirements=["Include an introduction paragraph"], - user_variables={"BLOG_TITLE": blog_title.value}, + requirements=None, + user_variables={}, ) assert introduction.value is not None, 'ERROR: task "introduction" execution failed' -# 3. Identify and explain three main benefits of morning exercise with detailed explanations. - - BENEFITS -benefits = m.instruct( +# 3. Identify three main benefits of morning exercise, then write detailed explanations for each benefit. - - BENEFITS_EXPLANATION +benefits_explanation = m.instruct( textwrap.dedent( R""" - Your task is to identify and explain three main benefits of morning exercise with detailed explanations. Follow these steps to accomplish your task: + Your task is to identify three main benefits of morning exercise and provide detailed explanations for each. Follow these steps to accomplish your task: - First, review the title and introduction created in the previous steps to understand the context and tone of the blog post: - - {{BLOG_TITLE}} - - - {{INTRODUCTION}} - + 1. **Research Morning Exercise Benefits**: Begin by researching the advantages associated with morning workouts. Focus on finding credible sources that highlight key benefits. Some common benefits include improved mood, increased energy levels throughout the day, and better sleep quality. + + 2. **Select Three Key Benefits**: From your research, choose three of the most significant benefits to focus on for this blog post. Ensure these benefits are well-supported by evidence from reliable sources. - Next, research and identify three main benefits of morning exercise. These benefits should be supported by evidence or expert opinions to ensure credibility. + 3. **Write Detailed Explanations**: For each selected benefit, write a detailed explanation. Each explanation should include: + - A clear statement of the benefit. + - Scientific or empirical evidence supporting the benefit. + - Practical examples or anecdotes to illustrate how this benefit manifests in real life. - For each benefit, provide a detailed explanation that includes: - - The specific benefit of morning exercise - - How this benefit positively impacts health, well-being, or daily life - - Any relevant studies, expert opinions, or personal anecdotes that support the benefit + 4. **Format for Blog Post**: Structure your explanations in a way that they can be easily integrated into the blog post format. Consider using bullet points or numbered lists for clarity if needed. - Ensure that the explanations are clear, concise, and engaging to keep the reader interested. + 5. **Compile Explanations**: Compile these detailed explanations into a structured format, ready to be combined with other parts of the blog post (title and conclusion) in the next steps. - Finally, present the three main benefits with their detailed explanations in a structured format that can be easily integrated into the blog post. + Ensure that your explanations are clear, informative, and engaging, maintaining a tone suitable for a health and wellness blog audience. """.strip() ), - requirements=["Include three main benefits with explanations"], - user_variables={"BLOG_TITLE": blog_title.value, "INTRODUCTION": introduction.value}, + requirements=None, + user_variables={}, +) +assert benefits_explanation.value is not None, ( + 'ERROR: task "benefits_explanation" execution failed' ) -assert benefits.value is not None, 'ERROR: task "benefits" execution failed' -# 4. Write a conclusion that encourages readers to start their morning exercise routine. - - CONCLUSION -conclusion = m.instruct( +# 4. Compile the identified benefits with their explanations into a structured format for the blog post. - - STRUCTURED_BENEFITS +structured_benefits = m.instruct( textwrap.dedent( R""" - Your task is to write a compelling conclusion for a blog post about the benefits of morning exercise. The conclusion should encourage readers to start their morning exercise routine. Follow these steps to accomplish your task: + Your task is to compile the identified benefits of morning exercise and their detailed explanations into a structured format suitable for a blog post. Follow these steps to accomplish your task: - First, review the title and introduction of the blog post to understand the context and tone: - - {{BLOG_TITLE}} - - - {{INTRODUCTION}} - + First, review the benefits of morning exercise that have been identified and explained in the previous step: + + {{BENEFITS_EXPLANATION}} + + + Next, organize these benefits into a clear and logical structure for the blog post. A common format for presenting benefits is to list each benefit as a distinct point or heading, followed by an explanation of that benefit. + + For example, you might structure your compiled benefits like this: - Next, consider the three main benefits of morning exercise that have been previously identified and explained: - - {{BENEFITS}} - + ### Benefit 1: [Benefit Name] + [Detailed Explanation of the benefit] - Use the information from the title, introduction, and benefits to craft a conclusion that: - 1. Summarizes the key points discussed in the blog post. - 2. Reinforces the importance of morning exercise. - 3. Encourages readers to take action and start their morning exercise routine. - 4. Maintains a positive and motivating tone. + ### Benefit 2: [Benefit Name] + [Detailed Explanation of the benefit] - Ensure the conclusion is concise, engaging, and leaves readers feeling inspired to make a change in their daily routine. + ### Benefit 3: [Benefit Name] + [Detailed Explanation of the benefit] - Finally, write the conclusion paragraph that encourages readers to start their morning exercise routine. + Ensure that each benefit is presented clearly and concisely, with a heading that accurately reflects the nature of the benefit. The explanation should be comprehensive yet easy to understand, providing readers with valuable insights into why morning exercise is beneficial. + + Finally, ensure this structured format aligns with the overall flow and style of the blog post being created. This compiled version will be used in conjunction with other parts of the blog post (title, introduction, conclusion) to form a cohesive piece of content. """.strip() ), requirements=[ - "Include a conclusion that encourages readers to start their morning exercise routine" + "The blog post must have a catchy title", + req( + "The post should include an introduction paragraph", validation_fn=val_fn_2 + ), + "Three main benefits of morning exercise with explanations are required", + "A conclusion that encourages readers to start their morning exercise routine is necessary", ], - user_variables={ - "BLOG_TITLE": blog_title.value, - "INTRODUCTION": introduction.value, - "BENEFITS": benefits.value, - }, + user_variables={"BENEFITS_EXPLANATION": benefits_explanation.value}, +) +assert structured_benefits.value is not None, ( + 'ERROR: task "structured_benefits" execution failed' ) -assert conclusion.value is not None, 'ERROR: task "conclusion" execution failed' -# 5. Compile the title, introduction, three main benefits, and conclusion into a single cohesive blog post. - - FINAL_BLOG_POST -final_blog_post = m.instruct( +# 5. Write a conclusion paragraph that encourages readers to start incorporating morning exercise into their routine. - - CONCLUSION +conclusion = m.instruct( textwrap.dedent( R""" - Your task is to compile the title, introduction, three main benefits, and conclusion into a single cohesive blog post about the benefits of morning exercise. + Your task is to write a conclusion paragraph that encourages readers to start incorporating morning exercise into their routine for the blog post about the benefits of morning exercise. Follow these steps: - To accomplish this, follow these steps: + 1. **Review Previous Steps**: + Begin by reviewing the structured benefits and explanations from previous steps, which can be found here: + + {{STRUCTURED_BENEFITS}} + - 1. **Review the Components**: - Carefully review the title, introduction, three main benefits, and conclusion that have been generated in the previous steps. These components are provided below: + This will help you understand the key points that have already been covered in the blog post. - - {{BLOG_TITLE}} - + 2. **Summarize Key Benefits**: + Briefly summarize the main benefits of morning exercise as discussed earlier to remind readers of their significance. You can refer to {{BENEFITS_EXPLANATION}} for specifics on each benefit. - - {{INTRODUCTION}} - + 3. **Craft an Encouraging Message**: + Write a paragraph that motivates readers to start their own morning exercise routine. Use persuasive language and emphasize the positive impact of making this change. - - {{BENEFITS}} - + 4. **Structure the Conclusion**: + Ensure your conclusion is concise, engaging, and effectively encourages action from the reader. It should wrap up the blog post by reinforcing the importance of morning exercise and inspiring readers to take the first step towards integrating it into their daily routine. - - {{CONCLUSION}} - + Here's a suggested structure for your conclusion paragraph: + - Briefly restate or reference one or two key benefits discussed in the body of the blog post. + - Use motivational language to encourage readers to adopt morning exercise. + - Provide a clear, actionable call to action (e.g., "Start today with a short walk around your neighborhood"). - 2. **Structure the Blog Post**: - Organize the components into a well-structured blog post. The structure should include: - - The catchy title at the beginning. - - The introduction paragraph that sets the stage for the blog post. - - The three main benefits with detailed explanations. - - The conclusion that encourages readers to start their morning exercise routine. + 5. **Finalize and Output**: + Once you have written the conclusion paragraph, ensure it is polished and ready for integration into the final blog post. Do not include any additional information or explanation beyond the requested conclusion text. + """.strip() + ), + requirements=[ + "The blog post must have a catchy title", + req( + "The post should include an introduction paragraph", validation_fn=val_fn_2 + ), + "Three main benefits of morning exercise with explanations are required", + "A conclusion that encourages readers to start their morning exercise routine is necessary", + ], + user_variables={ + "STRUCTURED_BENEFITS": structured_benefits.value, + "BENEFITS_EXPLANATION": benefits_explanation.value, + }, +) +assert conclusion.value is not None, 'ERROR: task "conclusion" execution failed' - 3. **Ensure Cohesion**: - Make sure the blog post flows smoothly from one section to the next. The transitions between the introduction, benefits, and conclusion should be natural and logical. +# 6. Combine all parts (title, introduction, benefits explanation, and conclusion) into a cohesive short blog post. - - FINAL_BLOG_POST +final_blog_post = m.instruct( + textwrap.dedent( + R""" + Your task is to combine all the identified parts—the catchy title, engaging introduction, detailed explanations of three main benefits, and an encouraging conclusion—into a cohesive short blog post about the benefits of morning exercise. Follow these steps to accomplish your task: - 4. **Check for Consistency**: - Verify that the tone and style are consistent throughout the blog post. Ensure that the language used in the title, introduction, benefits, and conclusion aligns with the overall theme of the blog post. + First, review the components you have already generated for this subtask: + + {{BLOG_TITLE}} + {{INTRODUCTION}} + {{BENEFITS_EXPLANATION}} + {{STRUCTURED_BENEFITS}} + {{CONCLUSION}} + - 5. **Final Review**: - Read through the entire blog post to ensure it is cohesive, well-organized, and free of any grammatical or spelling errors. Make any necessary adjustments to improve clarity and readability. + Next, structure the blog post by arranging these components in a logical order. A typical structure for a short blog post would be: + 1. **Title**: Start with your catchy title related to morning exercise benefits. + 2. **Introduction**: Follow the title with an engaging introduction paragraph that sets the stage and introduces the topic of morning exercise. + 3. **Main Benefits Section**: Present the three main benefits of morning exercise, each accompanied by a detailed explanation as you have generated in {{BENEFITS_EXPLANATION}}. Ensure these explanations are clear, concise, and supported by the structured information in {{STRUCTURED_BENEFITS}}. + 4. **Conclusion**: End with an encouraging conclusion that motivates readers to start or continue their morning exercise routine. Use the provided {{CONCLUSION}} for this purpose. - 6. **Output the Blog Post**: - Provide the final compiled blog post as your answer. Ensure that the output includes only the blog post text without any additional information or instructions. + Write a cohesive blog post by weaving these components together, ensuring smooth transitions between sections. Maintain a friendly and informative tone throughout the post, keeping it concise yet comprehensive. - By following these steps, you will create a single cohesive blog post that effectively communicates the benefits of morning exercise. + Finally, present only the completed short blog post as your answer without any additional information or explanation. """.strip() ), requirements=[ - "Include a catchy title", - "Include an introduction paragraph", - "Include three main benefits with explanations", - "Include a conclusion that encourages readers to start their morning exercise routine", + "The blog post must have a catchy title", + req( + "The post should include an introduction paragraph", validation_fn=val_fn_2 + ), + "Three main benefits of morning exercise with explanations are required", + "A conclusion that encourages readers to start their morning exercise routine is necessary", ], user_variables={ "BLOG_TITLE": blog_title.value, "INTRODUCTION": introduction.value, - "BENEFITS": benefits.value, + "BENEFITS_EXPLANATION": benefits_explanation.value, + "STRUCTURED_BENEFITS": structured_benefits.value, "CONCLUSION": conclusion.value, }, ) diff --git a/docs/examples/m_decompose/python/validations/__init__.py b/docs/examples/m_decompose/python/validations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/docs/examples/m_decompose/python/validations/val_fn_2.py b/docs/examples/m_decompose/python/validations/val_fn_2.py new file mode 100644 index 000000000..8a0333b50 --- /dev/null +++ b/docs/examples/m_decompose/python/validations/val_fn_2.py @@ -0,0 +1,23 @@ +def validate_input(input: str) -> bool: + """ + Validates that the input contains an introduction paragraph. + + An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow. + + Args: + input (str): The input to validate + + Returns: + bool: True if the input contains an introduction paragraph, False otherwise + """ + try: + # Splitting the input into sentences for analysis + sentences = re.split("[.!?]", input) + + # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start + return any( + sentence.strip() and not sentence.lower().startswith("rephrased from") + for sentence in sentences[:3] + ) + except Exception: + return False From 213e27e3b0d3a0f4783eb846ac01d81999fa021b Mon Sep 17 00:00:00 2001 From: AngeloDanducci Date: Wed, 1 Apr 2026 11:06:04 -0400 Subject: [PATCH 3/4] update templating --- .../_prompt/system_template.jinja2 | 1 + .../python/python_decompose_final_output.txt | 61 +++++++++++-------- .../python/python_decompose_result.json | 10 +-- .../python/validations/val_fn_2.py | 21 ++++--- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/cli/decompose/prompt_modules/validation_code_generator/_prompt/system_template.jinja2 b/cli/decompose/prompt_modules/validation_code_generator/_prompt/system_template.jinja2 index 7b414d0d5..01579128f 100644 --- a/cli/decompose/prompt_modules/validation_code_generator/_prompt/system_template.jinja2 +++ b/cli/decompose/prompt_modules/validation_code_generator/_prompt/system_template.jinja2 @@ -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 diff --git a/docs/examples/m_decompose/python/python_decompose_final_output.txt b/docs/examples/m_decompose/python/python_decompose_final_output.txt index 04933353f..2998a9e78 100644 --- a/docs/examples/m_decompose/python/python_decompose_final_output.txt +++ b/docs/examples/m_decompose/python/python_decompose_final_output.txt @@ -1,49 +1,58 @@ -=== 10:06:56-INFO ====== +=== 10:50:56-INFO ====== Starting Mellea session: backend=ollama, model=granite4:micro, context=SimpleContext -=== 10:07:00-INFO ====== +=== 10:51:00-INFO ====== FAILED. Valid: 3/4. Failed: - The post should include an introduction paragraph -=== 10:07:03-INFO ====== +=== 10:51:04-INFO ====== FAILED. Valid: 3/4. Failed: - The post should include an introduction paragraph -=== 10:07:03-INFO ====== +=== 10:51:04-INFO ====== Invoking select_from_failure after 2 failed attempts. -=== 10:07:05-INFO ====== +=== 10:51:06-INFO ====== SUCCESS -=== 10:07:11-INFO ====== +=== 10:51:11-INFO ====== SUCCESS -=== 10:07:18-INFO ====== -FAILED. Valid: 3/4. Failed: +=== 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:07:25-INFO ====== +=== 10:51:26-INFO ====== FAILED. Valid: 3/4. Failed: - The post should include an introduction paragraph -=== 10:07:25-INFO ====== +=== 10:51:26-INFO ====== Invoking select_from_failure after 2 failed attempts. -=== 10:07:33-INFO ====== -FAILED. Valid: 3/4. Failed: - - The post should include an introduction paragraph -=== 10:07:41-INFO ====== -FAILED. Valid: 3/4. Failed: - - The post should include an introduction paragraph -=== 10:07:41-INFO ====== +=== 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:07:51-INFO ====== +=== 10:51:41-INFO ====== FAILED. Valid: 3/4. Failed: - The post should include an introduction paragraph -=== 10:08:01-INFO ====== +=== 10:51:49-INFO ====== FAILED. Valid: 3/4. Failed: - The post should include an introduction paragraph -=== 10:08:01-INFO ====== +=== 10:51:49-INFO ====== Invoking select_from_failure after 2 failed attempts. -**Morning Exercise Magic: Unleashing the Power of Your Day** +**Title**: Revitalize Your Day: Unveiling the Top 3 Benefits of Morning Exercise + +**Introduction** + +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. + +**Main Benefits of Morning Exercise** -Waking up before the sun does not mean you're depriving yourself of daylight; it means embracing a lifestyle full of vitality and positivity. Engaging in morning exercises offers more than just physical fitness—it transforms your entire day, enhancing mood, energy levels, and sleep quality. Let's explore how starting your day with exercise can significantly impact your well-being. +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. -Starting your day with a burst of activity sets the stage for an uplifting mood throughout the rest of the day. Physical movement stimulates endorphins—the body's natural feel-good chemicals—helping to alleviate stress and elevate your spirits. A study published in *Psychological Science* highlights that those who exercise first thing in the morning report a noticeable reduction in symptoms related to depression and anxiety compared to late-day exercisers (Smith et al., 2020). For instance, Sarah, an accountant, often feels drained by mid-morning due to work-related stress. Since adopting a simple yoga routine at sunrise, she notices her mood improves significantly during her workday, allowing her to tackle tasks with calm and focus. +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. -Morning exercise is like giving your body the perfect energy boost it needs for the day ahead. This increase in vigor comes from better circulation, oxygen flow, and metabolic activity triggered by physical activity. Research from the *Journal of Strength and Conditioning* found that individuals who work out in the morning report higher levels of energy throughout their daily activities compared to those who prefer exercising later (Johnson & Lee, 2021). Mark, a teacher, frequently battles fatigue through long shifts. Since adding a brisk jog before school starts, he's noticed not only increased energy during lessons but also an easier time staying alert and engaged throughout the day. +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. -Engaging in morning exercise can significantly enhance the quality of your sleep at night. This improvement is largely due to how exercising in the morning helps regulate your circadian rhythms, promoting deeper, more restorative sleep. A study from *Sleep Medicine* demonstrated that those who exercise in the morning experience longer periods of deep sleep and fewer interruptions throughout the night compared to late-day exercisers (Brown & Green, 2022). Lisa, a mother of two, has observed her children's sleep patterns improve after she began an early morning swimming routine. She wakes up feeling refreshed and ready for each new day without feeling sluggish. +**Conclusion** -The benefits of morning exercise extend far beyond just physical health—they set the foundation for a more positive, energetic, and well-rested life. Whether you're looking to uplift your mood, stay energized throughout your tasks, or simply improve your rest, incorporating morning workouts into your routine can make all the difference. Take that first step today and experience the transformation for yourself! +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. diff --git a/docs/examples/m_decompose/python/python_decompose_result.json b/docs/examples/m_decompose/python/python_decompose_result.json index 31a074e32..1ee6cc74e 100644 --- a/docs/examples/m_decompose/python/python_decompose_result.json +++ b/docs/examples/m_decompose/python/python_decompose_result.json @@ -18,7 +18,7 @@ { "constraint": "The post should include an introduction paragraph", "val_strategy": "code", - "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False", + "val_fn": "import re\n\ndef validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that starts with the first sentence and ends with a period, question mark, or exclamation point.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Check if the input is not None or empty string\n if not input or input.strip() == \"\":\n return False\n \n # Split the input into sentences using regular expressions\n sentences = re.split('[.!?]', input)\n \n # The first sentence should be the introduction\n if len(sentences) > 1 and sentences[0].strip():\n return True\n else:\n return False\n except Exception:\n return False", "val_fn_name": "val_fn_2" }, { @@ -49,7 +49,7 @@ "constraint": "The post should include an introduction paragraph", "val_strategy": "code", "val_fn_name": "val_fn_2", - "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + "val_fn": "import re\n\ndef validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that starts with the first sentence and ends with a period, question mark, or exclamation point.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Check if the input is not None or empty string\n if not input or input.strip() == \"\":\n return False\n \n # Split the input into sentences using regular expressions\n sentences = re.split('[.!?]', input)\n \n # The first sentence should be the introduction\n if len(sentences) > 1 and sentences[0].strip():\n return True\n else:\n return False\n except Exception:\n return False" }, { "constraint": "Three main benefits of morning exercise with explanations are required", @@ -101,7 +101,7 @@ "constraint": "The post should include an introduction paragraph", "val_strategy": "code", "val_fn_name": "val_fn_2", - "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + "val_fn": "import re\n\ndef validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that starts with the first sentence and ends with a period, question mark, or exclamation point.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Check if the input is not None or empty string\n if not input or input.strip() == \"\":\n return False\n \n # Split the input into sentences using regular expressions\n sentences = re.split('[.!?]', input)\n \n # The first sentence should be the introduction\n if len(sentences) > 1 and sentences[0].strip():\n return True\n else:\n return False\n except Exception:\n return False" }, { "constraint": "Three main benefits of morning exercise with explanations are required", @@ -137,7 +137,7 @@ "constraint": "The post should include an introduction paragraph", "val_strategy": "code", "val_fn_name": "val_fn_2", - "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + "val_fn": "import re\n\ndef validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that starts with the first sentence and ends with a period, question mark, or exclamation point.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Check if the input is not None or empty string\n if not input or input.strip() == \"\":\n return False\n \n # Split the input into sentences using regular expressions\n sentences = re.split('[.!?]', input)\n \n # The first sentence should be the introduction\n if len(sentences) > 1 and sentences[0].strip():\n return True\n else:\n return False\n except Exception:\n return False" }, { "constraint": "Three main benefits of morning exercise with explanations are required", @@ -174,7 +174,7 @@ "constraint": "The post should include an introduction paragraph", "val_strategy": "code", "val_fn_name": "val_fn_2", - "val_fn": "def validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Splitting the input into sentences for analysis\n sentences = re.split('[.!?]', input)\n \n # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start\n return any(sentence.strip() and not sentence.lower().startswith('rephrased from') for sentence in sentences[:3])\n except Exception:\n return False" + "val_fn": "import re\n\ndef validate_input(input: str) -> bool:\n \"\"\"\n Validates that the input contains an introduction paragraph.\n \n An introduction paragraph is defined as a block of text that starts with the first sentence and ends with a period, question mark, or exclamation point.\n \n Args:\n input (str): The input to validate\n \n Returns:\n bool: True if the input contains an introduction paragraph, False otherwise\n \"\"\"\n try:\n # Check if the input is not None or empty string\n if not input or input.strip() == \"\":\n return False\n \n # Split the input into sentences using regular expressions\n sentences = re.split('[.!?]', input)\n \n # The first sentence should be the introduction\n if len(sentences) > 1 and sentences[0].strip():\n return True\n else:\n return False\n except Exception:\n return False" }, { "constraint": "Three main benefits of morning exercise with explanations are required", diff --git a/docs/examples/m_decompose/python/validations/val_fn_2.py b/docs/examples/m_decompose/python/validations/val_fn_2.py index 8a0333b50..6bf032627 100644 --- a/docs/examples/m_decompose/python/validations/val_fn_2.py +++ b/docs/examples/m_decompose/python/validations/val_fn_2.py @@ -1,8 +1,11 @@ +import re + + def validate_input(input: str) -> bool: """ Validates that the input contains an introduction paragraph. - An introduction paragraph is defined as a block of text that appears at the beginning of a document and provides context or overview of the content to follow. + An introduction paragraph is defined as a block of text that starts with the first sentence and ends with a period, question mark, or exclamation point. Args: input (str): The input to validate @@ -11,13 +14,17 @@ def validate_input(input: str) -> bool: bool: True if the input contains an introduction paragraph, False otherwise """ try: - # Splitting the input into sentences for analysis + # Check if the input is not None or empty string + if not input or input.strip() == "": + return False + + # Split the input into sentences using regular expressions sentences = re.split("[.!?]", input) - # An introduction paragraph is typically the first sentence or a group of closely related sentences at the start - return any( - sentence.strip() and not sentence.lower().startswith("rephrased from") - for sentence in sentences[:3] - ) + # The first sentence should be the introduction + if len(sentences) > 1 and sentences[0].strip(): + return True + else: + return False except Exception: return False From 58f72516d4f94d50c19bbd28e940c77899c4a4b0 Mon Sep 17 00:00:00 2001 From: AngeloDanducci Date: Tue, 7 Apr 2026 15:10:32 -0400 Subject: [PATCH 4/4] add skip tag to generated result script --- docs/examples/m_decompose/python/python_decompose_result.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/examples/m_decompose/python/python_decompose_result.py b/docs/examples/m_decompose/python/python_decompose_result.py index 25a2fe4ac..079336af1 100644 --- a/docs/examples/m_decompose/python/python_decompose_result.py +++ b/docs/examples/m_decompose/python/python_decompose_result.py @@ -1,3 +1,5 @@ +# pytest: skip_always + import textwrap from validations.val_fn_2 import validate_input as val_fn_2