Spaces:
Runtime error
Runtime error
Update coordinator/task_parser.py
Browse files- coordinator/task_parser.py +22 -10
coordinator/task_parser.py
CHANGED
|
@@ -2,13 +2,14 @@
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 8 |
|
| 9 |
def parse_brief_with_reasoning(brief: str):
|
| 10 |
"""
|
| 11 |
-
Use LLM to extract tasks and
|
| 12 |
Returns a dict:
|
| 13 |
{
|
| 14 |
"reasoning": <llm reasoning>,
|
|
@@ -16,24 +17,35 @@ def parse_brief_with_reasoning(brief: str):
|
|
| 16 |
}
|
| 17 |
"""
|
| 18 |
prompt = f"""
|
| 19 |
-
You are an
|
| 20 |
-
Explain your reasoning step
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
Project Brief:
|
| 24 |
{brief}
|
| 25 |
-
|
| 26 |
-
Reasoning and Tasks:
|
| 27 |
"""
|
| 28 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 29 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
| 30 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
|
| 32 |
-
# Split reasoning and
|
| 33 |
if "Tasks:" in decoded:
|
| 34 |
reasoning, tasks_text = decoded.split("Tasks:", 1)
|
| 35 |
else:
|
| 36 |
reasoning, tasks_text = decoded, ""
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
return {"reasoning": reasoning.strip(), "tasks": tasks}
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Use a larger model for better reasoning
|
| 6 |
+
MODEL_NAME = "facebook/opt-1.3b"
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 9 |
|
| 10 |
def parse_brief_with_reasoning(brief: str):
|
| 11 |
"""
|
| 12 |
+
Use LLM to extract tasks and reasoning
|
| 13 |
Returns a dict:
|
| 14 |
{
|
| 15 |
"reasoning": <llm reasoning>,
|
|
|
|
| 17 |
}
|
| 18 |
"""
|
| 19 |
prompt = f"""
|
| 20 |
+
You are an expert project manager. Given the project brief, list the distinct technical tasks needed to implement it.
|
| 21 |
+
Explain your reasoning step by step.
|
| 22 |
+
Output format:
|
| 23 |
+
Reasoning:
|
| 24 |
+
- Explain step 1
|
| 25 |
+
- Explain step 2
|
| 26 |
+
Tasks:
|
| 27 |
+
1. First task
|
| 28 |
+
2. Second task
|
| 29 |
+
Do not repeat the project brief.
|
| 30 |
|
| 31 |
Project Brief:
|
| 32 |
{brief}
|
|
|
|
|
|
|
| 33 |
"""
|
| 34 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 35 |
+
outputs = model.generate(**inputs, max_new_tokens=300)
|
| 36 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 37 |
|
| 38 |
+
# Split reasoning and tasks
|
| 39 |
if "Tasks:" in decoded:
|
| 40 |
reasoning, tasks_text = decoded.split("Tasks:", 1)
|
| 41 |
else:
|
| 42 |
reasoning, tasks_text = decoded, ""
|
| 43 |
|
| 44 |
+
# Deduplicate tasks
|
| 45 |
+
tasks = []
|
| 46 |
+
for line in tasks_text.split("\n"):
|
| 47 |
+
task = line.strip("-123. ").strip()
|
| 48 |
+
if task and task not in tasks:
|
| 49 |
+
tasks.append(task)
|
| 50 |
+
|
| 51 |
return {"reasoning": reasoning.strip(), "tasks": tasks}
|