Spaces:
Runtime error
Runtime error
Update coordinator/task_assigner.py
Browse files- coordinator/task_assigner.py +9 -14
coordinator/task_assigner.py
CHANGED
|
@@ -8,28 +8,23 @@ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
|
| 8 |
|
| 9 |
def assign_tasks_with_reasoning(tasks):
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
-
Returns dict:
|
| 13 |
{
|
| 14 |
-
"reasoning": <
|
| 15 |
"assignments": {task: agent}
|
| 16 |
}
|
| 17 |
"""
|
| 18 |
task_text = "\n".join(f"- {task}" for task in tasks)
|
| 19 |
prompt = f"""
|
| 20 |
-
You are an
|
| 21 |
-
Explain your reasoning step by step.
|
| 22 |
-
Output format:
|
| 23 |
-
Reasoning:
|
| 24 |
-
- Step by step explanation
|
| 25 |
-
Assignments:
|
| 26 |
-
Task -> Agent
|
| 27 |
-
|
| 28 |
-
Tasks:
|
| 29 |
{task_text}
|
|
|
|
|
|
|
|
|
|
| 30 |
"""
|
| 31 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 32 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
| 33 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 34 |
|
| 35 |
if "Assignments:" in decoded:
|
|
@@ -37,10 +32,10 @@ Tasks:
|
|
| 37 |
else:
|
| 38 |
reasoning, assignments_text = decoded, ""
|
| 39 |
|
|
|
|
| 40 |
assignments = {}
|
| 41 |
for line in assignments_text.split("\n"):
|
| 42 |
if "->" in line:
|
| 43 |
task, agent = line.split("->")
|
| 44 |
assignments[task.strip()] = agent.strip()
|
| 45 |
-
|
| 46 |
return {"reasoning": reasoning.strip(), "assignments": assignments}
|
|
|
|
| 8 |
|
| 9 |
def assign_tasks_with_reasoning(tasks):
|
| 10 |
"""
|
| 11 |
+
Assigns tasks to Frontend/Backend agents with reasoning.
|
| 12 |
+
Returns a dict:
|
| 13 |
{
|
| 14 |
+
"reasoning": <str>,
|
| 15 |
"assignments": {task: agent}
|
| 16 |
}
|
| 17 |
"""
|
| 18 |
task_text = "\n".join(f"- {task}" for task in tasks)
|
| 19 |
prompt = f"""
|
| 20 |
+
You are an AI assistant. Given the following technical tasks:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
{task_text}
|
| 22 |
+
|
| 23 |
+
Explain your reasoning step-by-step on whether each task should go to Frontend or Backend agent.
|
| 24 |
+
Then provide the final assignments in the format: Task -> Agent.
|
| 25 |
"""
|
| 26 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 27 |
+
outputs = model.generate(**inputs, max_new_tokens=250)
|
| 28 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 29 |
|
| 30 |
if "Assignments:" in decoded:
|
|
|
|
| 32 |
else:
|
| 33 |
reasoning, assignments_text = decoded, ""
|
| 34 |
|
| 35 |
+
# Parse assignments
|
| 36 |
assignments = {}
|
| 37 |
for line in assignments_text.split("\n"):
|
| 38 |
if "->" in line:
|
| 39 |
task, agent = line.split("->")
|
| 40 |
assignments[task.strip()] = agent.strip()
|
|
|
|
| 41 |
return {"reasoning": reasoning.strip(), "assignments": assignments}
|