mellea 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. cli/__init__.py +1 -0
  2. cli/alora/__init__.py +2 -0
  3. cli/alora/commands.py +50 -0
  4. cli/alora/train.py +173 -0
  5. cli/alora/upload.py +46 -0
  6. cli/decomp/__init__.py +2 -0
  7. cli/decomp/prompts/__init__.py +1 -0
  8. cli/decomp/prompts/metaprompts/README.md +1 -0
  9. cli/decomp/prompts/metaprompts/__init__.py +12 -0
  10. cli/decomp/prompts/metaprompts/metaprompt_get_input_data.py +65 -0
  11. cli/decomp/prompts/metaprompts/metaprompt_subtask_gen.py +135 -0
  12. cli/decomp/prompts/metaprompts/metaprompt_subtask_list_tags.py +101 -0
  13. cli/decomp/run.py +168 -0
  14. cli/decomp/task_compiler.py +60 -0
  15. cli/decomp/task_decomposer.py +195 -0
  16. cli/decomp/task_executor.py +56 -0
  17. cli/decomp/utils.py +141 -0
  18. cli/m.py +27 -0
  19. cli/serve/app.py +85 -0
  20. cli/serve/models.py +103 -0
  21. mellea/__init__.py +15 -0
  22. mellea/backends/__init__.py +75 -0
  23. mellea/backends/aloras/__init__.py +57 -0
  24. mellea/backends/aloras/huggingface/__init__.py +1 -0
  25. mellea/backends/aloras/huggingface/granite_aloras.py +210 -0
  26. mellea/backends/aloras/openai/__init__.py +1 -0
  27. mellea/backends/aloras/openai/granite_aloras.py +86 -0
  28. mellea/backends/cache.py +63 -0
  29. mellea/backends/dummy.py +40 -0
  30. mellea/backends/formatter.py +453 -0
  31. mellea/backends/huggingface.py +683 -0
  32. mellea/backends/model_ids.py +162 -0
  33. mellea/backends/ollama.py +467 -0
  34. mellea/backends/openai.py +674 -0
  35. mellea/backends/tools.py +106 -0
  36. mellea/backends/types.py +100 -0
  37. mellea/backends/watsonx.py +405 -0
  38. mellea/helpers/__init__.py +1 -0
  39. mellea/helpers/fancy_logger.py +126 -0
  40. mellea/stdlib/__init__.py +1 -0
  41. mellea/stdlib/base.py +464 -0
  42. mellea/stdlib/chat.py +120 -0
  43. mellea/stdlib/docs/__init__.py +1 -0
  44. mellea/stdlib/docs/richdocument.py +177 -0
  45. mellea/stdlib/genslot.py +304 -0
  46. mellea/stdlib/instruction.py +149 -0
  47. mellea/stdlib/mify.py +409 -0
  48. mellea/stdlib/mobject.py +222 -0
  49. mellea/stdlib/reqlib/md.py +60 -0
  50. mellea/stdlib/requirement.py +184 -0
  51. mellea/stdlib/safety/__init__.py +1 -0
  52. mellea/stdlib/safety/guardian.py +157 -0
  53. mellea/stdlib/sampling.py +203 -0
  54. mellea/stdlib/session.py +574 -0
  55. mellea/templates/prompts/default/ContentBlock.jinja2 +1 -0
  56. mellea/templates/prompts/default/GenerativeSlot.jinja2 +14 -0
  57. mellea/templates/prompts/default/Instruction.jinja2 +44 -0
  58. mellea/templates/prompts/default/LLMaJRequirement.jinja2 +15 -0
  59. mellea/templates/prompts/default/MObject.jinja2 +1 -0
  60. mellea/templates/prompts/default/Query.jinja2 +6 -0
  61. mellea/templates/prompts/default/Requirement.jinja2 +15 -0
  62. mellea/templates/prompts/default/Table.jinja2 +1 -0
  63. mellea/templates/prompts/default/TableQuery.jinja2 +6 -0
  64. mellea/templates/prompts/default/TableTransform.jinja2 +10 -0
  65. mellea/templates/prompts/default/Transform.jinja2 +6 -0
  66. mellea/templates/prompts/granite/Instruction.jinja2 +44 -0
  67. mellea-0.0.1.dist-info/METADATA +242 -0
  68. mellea-0.0.1.dist-info/RECORD +71 -0
  69. mellea-0.0.1.dist-info/WHEEL +4 -0
  70. mellea-0.0.1.dist-info/entry_points.txt +5 -0
  71. mellea-0.0.1.dist-info/licenses/LICENSE +203 -0
cli/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """cli for the M library."""
cli/alora/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ # cli/alora/__init__.py
2
+ """alora command group package for training and uploading adapters."""
cli/alora/commands.py ADDED
@@ -0,0 +1,50 @@
1
+ import typer
2
+
3
+ alora_app = typer.Typer(
4
+ name="alora", help="Train or upload aLoRA models for requirement validator"
5
+ )
6
+
7
+
8
+ def alora_train(
9
+ datafile: str = typer.Argument(..., help="JSONL file with item/label pairs"),
10
+ basemodel: str = typer.Option(..., help="Base model ID or path"),
11
+ outfile: str = typer.Option(..., help="Path to save adapter weights"),
12
+ promptfile: str = typer.Option(None, help="Path to load the prompt format file"),
13
+ adapter: str = typer.Option("alora", help="Adapter type: alora or lora"),
14
+ epochs: int = typer.Option(6, help="Number of training epochs"),
15
+ learning_rate: float = typer.Option(6e-6, help="Learning rate"),
16
+ batch_size: int = typer.Option(2, help="Per-device batch size"),
17
+ max_length: int = typer.Option(1024, help="Max sequence length"),
18
+ grad_accum: int = typer.Option(4, help="Gradient accumulation steps"),
19
+ ):
20
+ """Train an aLoRA or LoRA model on your dataset."""
21
+ from cli.alora.train import train_model
22
+
23
+ train_model(
24
+ dataset_path=datafile,
25
+ base_model=basemodel,
26
+ output_file=outfile,
27
+ adapter=adapter,
28
+ epochs=epochs,
29
+ learning_rate=learning_rate,
30
+ batch_size=batch_size,
31
+ max_length=max_length,
32
+ grad_accum=grad_accum,
33
+ prompt_file=promptfile,
34
+ )
35
+
36
+
37
+ def alora_upload(
38
+ weightfile: str = typer.Argument(..., help="Path to saved adapter weights"),
39
+ name: str = typer.Option(
40
+ ..., help="Destination model name (e.g., acme/carbchecker-alora)"
41
+ ),
42
+ ):
43
+ """Upload trained adapter to remote model registry."""
44
+ from cli.alora.upload import upload_model
45
+
46
+ upload_model(weight_path=weightfile, model_name=name)
47
+
48
+
49
+ alora_app.command("train")(alora_train)
50
+ alora_app.command("upload")(alora_upload)
cli/alora/train.py ADDED
@@ -0,0 +1,173 @@
1
+ import json
2
+ import os
3
+
4
+ import typer
5
+ from alora.config import aLoraConfig
6
+ from alora.peft_model_alora import aLoRAPeftModelForCausalLM
7
+ from datasets import Dataset
8
+ from peft import LoraConfig, PeftModelForCausalLM
9
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TrainerCallback
10
+ from trl import DataCollatorForCompletionOnlyLM, SFTConfig, SFTTrainer
11
+
12
+
13
+ def load_dataset_from_json(json_path, tokenizer, invocation_prompt):
14
+ data = []
15
+ with open(json_path, encoding="utf-8") as f:
16
+ for line in f:
17
+ line = line.strip()
18
+ if line:
19
+ data.append(json.loads(line))
20
+
21
+ inputs = []
22
+ targets = []
23
+ for sample in data:
24
+ item_text = sample.get("item", "")
25
+ label_text = sample.get("label", "")
26
+ prompt = f"{item_text}\nRequirement: <|end_of_text|>\n{invocation_prompt}"
27
+ inputs.append(prompt)
28
+ targets.append(label_text)
29
+ return Dataset.from_dict({"input": inputs, "target": targets})
30
+
31
+
32
+ def formatting_prompts_func(example):
33
+ return [
34
+ f"{example['input'][i]}{example['target'][i]}"
35
+ for i in range(len(example["input"]))
36
+ ]
37
+
38
+
39
+ class SaveBestModelCallback(TrainerCallback):
40
+ def __init__(self):
41
+ self.best_eval_loss = float("inf")
42
+
43
+ def on_evaluate(self, args, state, control, **kwargs):
44
+ model = kwargs["model"]
45
+ metrics = kwargs["metrics"]
46
+ eval_loss = metrics.get("eval_loss")
47
+ if eval_loss is not None and eval_loss < self.best_eval_loss:
48
+ self.best_eval_loss = eval_loss
49
+ model.save_pretrained(args.output_dir)
50
+
51
+
52
+ class SafeSaveTrainer(SFTTrainer):
53
+ def save_model(self, output_dir: str | None = None, _internal_call: bool = False):
54
+ if self.model is not None:
55
+ self.model.save_pretrained(output_dir, safe_serialization=True)
56
+ if self.tokenizer is not None:
57
+ self.tokenizer.save_pretrained(output_dir)
58
+
59
+
60
+ def train_model(
61
+ dataset_path: str,
62
+ base_model: str,
63
+ output_file: str,
64
+ prompt_file: str | None = None,
65
+ adapter: str = "alora",
66
+ run_name: str = "multiclass_run",
67
+ epochs: int = 6,
68
+ learning_rate: float = 6e-6,
69
+ batch_size: int = 2,
70
+ max_length: int = 1024,
71
+ grad_accum: int = 4,
72
+ ):
73
+ if prompt_file:
74
+ # load the configurable variable invocation_prompt
75
+ with open(prompt_file) as f:
76
+ config = json.load(f)
77
+ invocation_prompt = config["invocation_prompt"]
78
+ else:
79
+ invocation_prompt = "<|start_of_role|>check_requirement<|end_of_role|>"
80
+
81
+ tokenizer = AutoTokenizer.from_pretrained(
82
+ base_model, padding_side="right", trust_remote_code=True
83
+ )
84
+ tokenizer.pad_token = tokenizer.eos_token
85
+ tokenizer.add_special_tokens = False
86
+
87
+ dataset = load_dataset_from_json(dataset_path, tokenizer, invocation_prompt)
88
+ dataset = dataset.shuffle(seed=42)
89
+ split_idx = int(len(dataset) * 0.8)
90
+ train_dataset = dataset.select(range(split_idx))
91
+ val_dataset = dataset.select(range(split_idx, len(dataset)))
92
+
93
+ model_base = AutoModelForCausalLM.from_pretrained(
94
+ base_model, device_map="auto", use_cache=False
95
+ )
96
+
97
+ collator = DataCollatorForCompletionOnlyLM(invocation_prompt, tokenizer=tokenizer)
98
+
99
+ output_dir = os.path.dirname(output_file)
100
+ os.makedirs(output_dir, exist_ok=True)
101
+
102
+ if adapter == "alora":
103
+ peft_config = aLoraConfig(
104
+ invocation_string=invocation_prompt,
105
+ r=32,
106
+ lora_alpha=32,
107
+ lora_dropout=0.05,
108
+ bias="none",
109
+ task_type="CAUSAL_LM",
110
+ target_modules=["q_proj", "k_proj", "v_proj"],
111
+ )
112
+ response_token_ids = tokenizer(
113
+ invocation_prompt, return_tensors="pt", add_special_tokens=False
114
+ )["input_ids"]
115
+ model = aLoRAPeftModelForCausalLM(
116
+ model_base, peft_config, response_token_ids=response_token_ids
117
+ )
118
+
119
+ sft_args = SFTConfig(
120
+ output_dir=output_dir,
121
+ dataset_kwargs={"add_special_tokens": False},
122
+ num_train_epochs=epochs,
123
+ learning_rate=learning_rate,
124
+ max_seq_length=max_length,
125
+ per_device_train_batch_size=batch_size,
126
+ gradient_accumulation_steps=grad_accum,
127
+ fp16=True,
128
+ )
129
+
130
+ trainer = SafeSaveTrainer(
131
+ model,
132
+ train_dataset=train_dataset,
133
+ eval_dataset=val_dataset,
134
+ args=sft_args,
135
+ formatting_func=formatting_prompts_func,
136
+ data_collator=collator,
137
+ callbacks=[SaveBestModelCallback()],
138
+ )
139
+ trainer.train()
140
+ model.save_pretrained(output_file)
141
+
142
+ else:
143
+ peft_config = LoraConfig(
144
+ r=6,
145
+ lora_alpha=32,
146
+ lora_dropout=0.05,
147
+ bias="none",
148
+ task_type="CAUSAL_LM",
149
+ target_modules=["q_proj", "k_proj", "v_proj"],
150
+ )
151
+ model = PeftModelForCausalLM(model_base, peft_config)
152
+
153
+ sft_args = SFTConfig(
154
+ output_dir=output_dir,
155
+ dataset_kwargs={"add_special_tokens": False},
156
+ num_train_epochs=epochs,
157
+ learning_rate=learning_rate,
158
+ max_seq_length=max_length,
159
+ per_device_train_batch_size=batch_size,
160
+ gradient_accumulation_steps=grad_accum,
161
+ fp16=True,
162
+ )
163
+
164
+ trainer = SafeSaveTrainer(
165
+ model,
166
+ train_dataset=train_dataset,
167
+ eval_dataset=val_dataset,
168
+ args=sft_args,
169
+ formatting_func=formatting_prompts_func,
170
+ data_collator=collator,
171
+ )
172
+ trainer.train()
173
+ model.save_pretrained(output_file, safe_serialization=True)
cli/alora/upload.py ADDED
@@ -0,0 +1,46 @@
1
+ import os
2
+
3
+ import typer
4
+ from huggingface_hub import HfApi, HfFolder, create_repo, upload_folder
5
+
6
+
7
+ def upload_model(weight_path: str, model_name: str, private: bool = True):
8
+ """
9
+ Upload a trained adapter (LoRA/aLoRA) to Hugging Face Hub.
10
+
11
+ Args:
12
+ weight_path (str): Directory containing adapter weights (from save_pretrained).
13
+ model_name (str): Target model repo name (e.g., "acme/carbchecker-alora").
14
+ private (bool): Whether the repo should be private. Default: True.
15
+
16
+ Requires:
17
+ - `HF_TOKEN` set in environment or via `huggingface-cli login`.
18
+ """
19
+ if not os.path.exists(weight_path):
20
+ raise FileNotFoundError(f"Adapter directory not found: {weight_path}")
21
+
22
+ # Create repo if not exists
23
+ token = HfFolder.get_token()
24
+ if token is None:
25
+ raise OSError(
26
+ "Hugging Face token not found. Run `huggingface-cli login` first."
27
+ )
28
+
29
+ try:
30
+ create_repo(repo_id=model_name, token=token, private=private, exist_ok=True)
31
+ except Exception as e:
32
+ raise RuntimeError(f"Failed to create or access repo {model_name}: {e}")
33
+
34
+ print(
35
+ f"Uploading adapter from '{weight_path}' to 'https://huggingface.co/{model_name}' ..."
36
+ )
37
+
38
+ upload_folder(
39
+ repo_id=model_name,
40
+ folder_path=weight_path,
41
+ path_in_repo=".", # Root of repo
42
+ commit_message="Upload adapter weights",
43
+ token=token,
44
+ )
45
+
46
+ print("✅ Upload complete!")
cli/decomp/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ # __init__.py
2
+ # Empty file to make this a package
@@ -0,0 +1 @@
1
+ from . import metaprompts
@@ -0,0 +1 @@
1
+ # Generic Metaprompt v2.5
@@ -0,0 +1,12 @@
1
+ from .metaprompt_get_input_data import (
2
+ metaprompt_get_input_data__system,
3
+ metaprompt_get_input_data__user,
4
+ )
5
+ from .metaprompt_subtask_gen import (
6
+ metaprompt_subtask_gen__system,
7
+ metaprompt_subtask_gen__user,
8
+ )
9
+ from .metaprompt_subtask_list_tags import (
10
+ metaprompt_subtask_list__system,
11
+ metaprompt_subtask_list__user,
12
+ )
@@ -0,0 +1,65 @@
1
+ # flake8: noqa
2
+
3
+ metaprompt_get_input_data__system = """You will analyze a task prompt to determine whether it requires user-provided input data (variables) in order to be executed effectively. Not all tasks need input data — some may be general knowledge questions or self-contained instructions.
4
+
5
+ The user input data / variables might be:
6
+ - Explicitly indicated using a templating format like {{VARIABLE_NAME}}
7
+ - Implicitly required, based on task understanding
8
+
9
+ Your objective is to identify all the necessary user input data required to complete the task and present them in a specific format.
10
+
11
+ Key Instructions:
12
+ - If input variables are present, list them **inside curly braces**, using **UPPERCASE_WITH_UNDERSCORES** format and **comma-separated**, **no spaces**.
13
+ - If no input data is needed, output `"N/A"` inside the `<User Input Data>` tags.
14
+ - Do not include anything else in your response except the tags and the input list.
15
+
16
+ ---
17
+
18
+ <Example>
19
+ <Task>
20
+ Generate a formal letter for a recipient based on their name, address, and the purpose of the letter.
21
+ </Task>
22
+ <User Input Data>
23
+ {{RECIPIENT_NAME}},{{RECIPIENT_ADDRESS}},{{LETTER_PURPOSE}}
24
+ </User Input Data>
25
+ </Example>
26
+
27
+ <Example>
28
+ <Task>
29
+ Explain the concept of Newton’s Laws of Motion with examples.
30
+ </Task>
31
+ <User Input Data>
32
+ N/A
33
+ </User Input Data>
34
+ </Example>
35
+
36
+ <Example>
37
+ <Task>
38
+ Produce a summary from a provided article text.
39
+ </Task>
40
+ <User Input Data>
41
+ {{ARTICLE_TEXT}}
42
+ </User Input Data>
43
+ </Example>
44
+
45
+ That concludes the examples.
46
+ """
47
+
48
+ metaprompt_get_input_data__user = """Now, here is the task prompt for which I would like you to identify and list all the user input data (variables) names:
49
+
50
+ <Task>
51
+ {{TASK}}
52
+ </Task>
53
+
54
+ To write your user input data (variables) list, follow THESE instructions:
55
+ 1. Use your best judgement to create the user input data (variable) names.
56
+ 2. The user input data (variable) names must be written surrounded by curly braces.
57
+ 3. The user input data (variable) names must be written in uppercase letters and if the name is composed by multiple words, the words must be separated by a underscore character (_) instead o spaces.
58
+ 4. In <User Input Data> tags, write your user input data (variables) list. This user input data (variables) list should be similarly structured as the ones in the examples above. Always close the user input data (variables) list section with the </User Input Data> tag.
59
+ 5. If you judge that the provided task does not need user input data to be completed, then you must write "N/A" (without the quotes) inside the <User Input Data> tags and nothing else, just close the tags.
60
+ 6. Do not forget to always close each section with its corresponding close tag.
61
+
62
+ Note: This is probably obvious to you already, but you are not *completing* the task here. You are just writing the user input data list for an AI to complete the task later.
63
+ Note: Remember that not all tasks need user input data, usually smaller tasks and tasks that are just asking for information don't require user input data, use your best judgment to identify those.
64
+ Note: You must write ONLY the user input data list, do not repeat the long complex task provided.
65
+ """
@@ -0,0 +1,135 @@
1
+ # flake8: noqa
2
+
3
+ metaprompt_subtask_gen__system = """You are writing instructions to guide a helpful but inexperienced AI assistant to complete part of a larger task. Your role is to generate a *step-level prompt instruction* that the assistant will use to complete a specific step of a long, complex task.
4
+
5
+ You will receive four parameters:
6
+ 1. A long complex task, provided inside <Long Complex Task> tags.
7
+ 2. A specific execution step from that task, inside <Step> tags.
8
+ 3. A list of previous steps (with variable names) that were already completed, inside <Previous Steps> tags.
9
+ 4. A list of available input variables (user input and previous step results), inside <Available Input Variables> tags.
10
+
11
+ Your job is to:
12
+ - Write a clear and complete **<Step Prompt Instruction>** that helps the assistant complete the given step, using only relevant parts of the long complex task.
13
+ - Use consistent terminology and style from the long complex task.
14
+ - If prior step outputs are useful, include them using their variable names in `{{double_curly_braces}}`. Wrap them in triple backticks (```...```) when referencing outputs.
15
+ - Reference user input variables using `{{VARIABLE_NAME}}` placeholders where needed.
16
+
17
+ Next, analyze whether the current step has specific **requirements or conditions**. If so, write them in bullet points using the same wording from the long complex task and enclose them in <Requirements and Conditions> tags. If none are applicable, write `"N/A"` inside the tag.
18
+
19
+ Here are a few generic examples:
20
+
21
+ <Example>
22
+ <Long Complex Task>
23
+ This task involves analyzing a dataset to produce a statistical summary report.
24
+
25
+ Instructions:
26
+ 1. Load the input dataset.
27
+ 2. Clean the dataset by removing nulls and outliers.
28
+ 3. Generate basic descriptive statistics.
29
+ 4. Write a brief natural language summary of the statistics.
30
+
31
+ Your output should be in JSON format with two keys: `stats` and `summary`.
32
+ </Long Complex Task>
33
+ <Step>
34
+ 2. Clean the dataset by removing nulls and outliers.
35
+ </Step>
36
+ <Previous Steps>
37
+ 1. Load the input dataset. - Variable: RAW_DATA
38
+ </Previous Steps>
39
+ <Available Input Variables>
40
+ {{RAW_DATA}}
41
+ </Available Input Variables>
42
+ <Step Prompt Instruction>
43
+ Clean the dataset provided below by performing the following:
44
+ - Remove any rows with null or missing values
45
+ - Remove outliers using appropriate statistical techniques
46
+
47
+ Input dataset:
48
+ ```
49
+ {{RAW_DATA}}
50
+ ```
51
+
52
+ Return the cleaned dataset.
53
+ </Step Prompt Instruction>
54
+ <Requirements and Conditions>
55
+ - Remove any rows with null or missing values
56
+ - Remove outliers using appropriate statistical techniques
57
+ </Requirements and Conditions>
58
+ </Example>
59
+
60
+ <Example>
61
+ <Long Complex Task>
62
+ You will write a brief summary of a user-submitted document, capturing key ideas and structure.
63
+
64
+ Instructions:
65
+ 1. Read and analyze the input document.
66
+ 2. Identify the key themes and main ideas.
67
+ 3. Write a summary in under 200 words, preserving the tone and style of the input.
68
+
69
+ Return your result as a string.
70
+ </Long Complex Task>
71
+ <Step>
72
+ 3. Write a summary in under 200 words, preserving the tone and style of the input.
73
+ </Step>
74
+ <Previous Steps>
75
+ 1. Read and analyze the input document. - Variable: DOCUMENT_ANALYSIS
76
+ 2. Identify the key themes and main ideas. - Variable: KEY_THEMES
77
+ </Previous Steps>
78
+ <Available Input Variables>
79
+ {{DOCUMENT_ANALYSIS}},{{KEY_THEMES}}
80
+ </Available Input Variables>
81
+ <Step Prompt Instruction>
82
+ Using the analysis and themes identified in the previous steps:
83
+ - Write a concise summary of the input content.
84
+ - Keep it under 200 words.
85
+ - Maintain the tone and style of the original document.
86
+
87
+ Previous analysis:
88
+ ```
89
+ {{DOCUMENT_ANALYSIS}}
90
+ ```
91
+
92
+ Key themes:
93
+ ```
94
+ {{KEY_THEMES}}
95
+ ```
96
+ </Step Prompt Instruction>
97
+ <Requirements and Conditions>
98
+ - Keep the summary under 200 words
99
+ - Maintain the tone and style of the input document
100
+ </Requirements and Conditions>
101
+ </Example>
102
+
103
+ That concludes the examples."""
104
+
105
+ metaprompt_subtask_gen__user = """Now, here are the 4 parameters (<Long Complex Task>, <Step>, <Previous Steps>, <Available Input Variables>) which I would like you to use to write your <Step Prompt Instruction> and <Requirements and Conditions>:
106
+
107
+ <Long Complex Task>
108
+ {{TASK}}
109
+ </Long Complex Task>
110
+ <Step>
111
+ {{STEP}}
112
+ </Step>
113
+ <Previous Steps>
114
+ {{PREVIOUS_STEPS}}
115
+ </Previous Steps>
116
+ <Available Input Variables>
117
+ {{INPUT_DATA}}
118
+ </Available Input Variables>
119
+
120
+ To write your step "prompt instruction" and your "requirements and conditions", pay attention to these instructions:
121
+ 1. In <Step Prompt Instruction> tags, write the prompt instruction to execute and complete the provided step (<Step> tags). Always close the prompt instruction section with the </Step Prompt Instruction> tag.
122
+ 2. Consider and use the variables in the <Available Input Variables> tags to write your template.
123
+ 3. In <Requirements and Conditions> tags, identify and write all requirements and conditions closely related to the provided step (<Step> tags). Always close the requirements and conditions section with the </Requirements and Conditions> tag.
124
+ 4. The <Requirements and Conditions> should include only requirements and conditions that are are closely related to the task in the <Step> tags and mentioned in the long complex task. The <Long Complex Task> must be the only scope for writing your <Requirements and Conditions> list.
125
+ 5. Use, as much as you can, the same words and style as provided in the long complex task content (<Long Complex Task> tags).
126
+ 6. Do not forget to always close each section with its corresponding close tag.
127
+ 7. Don't forget to close the <Requirements and Conditions> tags at the end of your response.
128
+
129
+ Note: This is probably obvious to you already, but you are not *completing* the task here. You are writing instructions for an AI to complete the task.
130
+ Note: Another name for what you are writing is a "prompt template". When you put a variable name enclosed in double brackets into this template, it will later have the full value (which will be provided by a user or by the result from a previous step) substituted into it.
131
+ Note: When referencing the result of a previous step using its variable name on your instructions prompt template, you usually place the variable inside triple backquote characters (```). Example: \n```\n{{VARIABLE_NAME}}\n```\n
132
+ Note: When writing the requirements and conditions, do not reference and do not use the result of previous steps to write detected requirements. Don't use input variables inside the <Requirements and Conditions> tags.
133
+
134
+ It is extremely important to always close the <Requirements and Conditions> tags with "</Requirements and Conditions>" at the end of your answer.
135
+ """
@@ -0,0 +1,101 @@
1
+ # flake8: noqa
2
+
3
+ metaprompt_subtask_list__system = """You will break down a long, complex task into a list of subtasks for a helpful but inexperienced AI assistant to execute in order. Your goal is to make the task easier to complete by structuring it into logically ordered, actionable subtasks.
4
+
5
+ You will generate:
6
+ 1. A <Reasoning> section to reflect on the structure and needs of the task.
7
+ 2. A <Draft Subtask List> where you write an initial set of subtasks, each tagged with a classification type from the list below.
8
+ 3. A <Final Subtask List> with fewer, cleaner steps, each labeled with a variable name related to its purpose.
9
+
10
+ Use the following classification types in the draft list:
11
+ - "write"
12
+ - "extract"
13
+ - "present or show"
14
+ - "reason and reflect"
15
+ - "research"
16
+ - "assert and verify"
17
+ - "constraints and conditions"
18
+ - "format"
19
+ - "safety and security"
20
+
21
+ For the <Final Subtask List>:
22
+ - Use numbered steps (no subitems or multiline descriptions).
23
+ - Each step must describe a single, self-contained action.
24
+ - Assign each step a variable name using **UPPERCASE_WITH_UNDERSCORES** enclosed in `Variable: ...`.
25
+ - These variable names should reflect the intent or output of that step.
26
+
27
+ Here is an example:
28
+
29
+ <Final Subtask List>
30
+ 1. Gather and understand the task input requirements. - Variable: INPUT_DATA
31
+ 2. Conduct research or analysis using the task input. - Variable: RESEARCH
32
+ 3. Write a structured result that satisfies the task requirements. - Variable: OUTPUT
33
+ </Final Subtask List>
34
+
35
+ Now see some full examples:
36
+
37
+ <Example>
38
+ <Long Complex Task>
39
+ Create a short, informative summary from a document that contains paragraphs of raw text. The summary should capture key ideas and tone of the original. Write the output in plain language and return it as a paragraph.
40
+ </Long Complex Task>
41
+ <Reasoning>
42
+ The task requires understanding the document, extracting core content, rephrasing the core content in plain language, and writing a concise summary. We must also ensure that the output respects the tone and content focus of the original document.
43
+ </Reasoning>
44
+ <Draft Subtask List>
45
+ 1. Validate that the input document does not contain inappropriate or harmful content. - Category "safety and security"
46
+ 2. Extract the main themes and important ideas from the text. - Category "extract"
47
+ 3. Reflect on the tone and style of the input. - Category "reason and reflect"
48
+ 4. Write a short summary paragraph in plain language. - Category "write"
49
+ 5. Format the output for clean paragraph structure. - Category "format"
50
+ 6. Verify that the summary preserves original tone and covers key points. - Category "assert and verify"
51
+ </Draft Subtask List>
52
+ <Final Subtask List>
53
+ 1. Extract and reflect on the main ideas and tone from the document. - Variable: CONTENT_OVERVIEW
54
+ 2. Write a short, plain-language summary using the extracted information. - Variable: SUMMARY
55
+ </Final Subtask List>
56
+ </Example>
57
+
58
+ <Example>
59
+ <Long Complex Task>
60
+ Analyze a dataset and create a visualization that shows the distribution of numerical values for a selected feature. Include descriptive labels and a brief caption explaining the visual.
61
+ </Long Complex Task>
62
+ <Reasoning>
63
+ To complete this task, we need to first load and verify the dataset. Then we analyze the selected feature and generate a visualization like a histogram or boxplot. The visual must be labeled properly, and a clear caption must be added to interpret it.
64
+ </Reasoning>
65
+ <Draft Subtask List>
66
+ 1. Load the dataset and check its format and integrity. - Category "assert and verify"
67
+ 2. Extract the values of the selected numerical feature. - Category "extract"
68
+ 3. Generate a visual distribution chart. - Category "present or show"
69
+ 4. Write a descriptive caption that explains what the chart shows. - Category "write"
70
+ 5. Add labels and format the chart. - Category "format"
71
+ </Draft Subtask List>
72
+ <Final Subtask List>
73
+ 1. Extract the values for the selected feature from the dataset. - Variable: FEATURE_DATA
74
+ 2. Generate a chart and caption showing the feature’s distribution. - Variable: VISUALIZATION
75
+ </Final Subtask List>
76
+ </Example>
77
+
78
+ That concludes the examples."""
79
+
80
+ metaprompt_subtask_list__user = """Now, here is the prompt of the long complex task for which I would like you to break down and write both subtask lists:
81
+
82
+ <Long Complex Task>
83
+ {{TASK}}
84
+ </Long Complex Task>
85
+
86
+ To write your subtask lists, follow THESE instructions:
87
+ 1. In <Reasoning> tags, reason and think about the provided task and plan out how you will structure your subtasks in a correct order of execution. Always close the reasoning section with the </Reasoning> tag.
88
+ 2. In <Draft Subtask List> tags, write your proposed draft subtask list. This draft subtask list should be similarly structured as the ones in the examples above. Always close the draft subtask list section with the </Draft Subtask List> tag.
89
+ 3. Remember to classify each step on the <Draft Subtask List> under categories (types): "write", "extract", "present or show", "reason and reflect", "research", "assert and verify", "constraints and conditions", "format", "safety and security".
90
+ 4. In <Final Subtask List> tags, write the subtask list. The subtask list should be based on the draft subtask list, but must have FEWER steps, you can have less steps by either grouping steps together or by omitting steps of specific categories that do not describe an actual action. This final subtask list should be similarly structured as the ones in the examples above. Always close the subtask list section with the </Final Subtask List> tag.
91
+ 5. When writing the <Final Subtask List> try to group steps and remove non-actionable steps, but maintain the step's text very descriptive of its action.
92
+ 6. Do not forget to always close each section with its corresponding close tag.
93
+ 7. It is extremely important to always make sure both subtask lists are NUMBERED lists and that each item is a single-line, do not use new lines when writing the subtask lists and do not add subitems.
94
+
95
+ Note: This is probably obvious to you already, but you are not *completing* the task here. You are just writing a subtask list for an AI to follow and complete the task.
96
+ Note: The final <Final Subtask List> must omit steps of the categories such as "assert and verify", "present or show", "constraints and conditions", and "safety and security".
97
+ Note: When writing your <Final Subtask List>, you must try *MINIMIZE* the number of steps in the final list.
98
+ Note: The final <Final Subtask List> must NOT include the categories in the list, but it should include the "Variable" name based on the step's content.
99
+
100
+ Important: Do not forget to always close the <Final Subtask List> tag with "</Final Subtask List>" in the last line of your answer.
101
+ """