File size: 1,264 Bytes
d3bd55e
3f96a46
 
 
 
 
 
d3bd55e
075c278
d3bd55e
075c278
 
 
 
 
 
d3bd55e
075c278
 
 
 
 
 
 
 
 
 
3f96a46
075c278
3f96a46
 
075c278
3f96a46
075c278
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# coordinator/task_parser.py
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

MODEL_NAME = "facebook/opt-125m"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)

def parse_brief_with_reasoning(brief: str):
    """
    Use LLM to extract tasks and show reasoning step-by-step
    Returns a dict:
        {
            "reasoning": <llm reasoning>,
            "tasks": [list of tasks]
        }
    """
    prompt = f"""
You are an AI assistant. A user gives you a project brief. 
Explain your reasoning step-by-step about what technical tasks you would extract from this brief.
Then provide the final list of tasks.

Project Brief:
{brief}

Reasoning and Tasks:
"""
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=200)
    decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)

    # Split reasoning and final tasks
    if "Tasks:" in decoded:
        reasoning, tasks_text = decoded.split("Tasks:", 1)
    else:
        reasoning, tasks_text = decoded, ""

    tasks = [line.strip("- ").strip() for line in tasks_text.split("\n") if line.strip()]
    return {"reasoning": reasoning.strip(), "tasks": tasks}