Bhaskar2611 commited on
Commit
91efcfe
·
verified ·
1 Parent(s): ee9409b

Update planner.py

Browse files
Files changed (1) hide show
  1. planner.py +39 -60
planner.py CHANGED
@@ -1,75 +1,54 @@
1
  # planner.py
2
  import os
3
- import re
4
  from huggingface_hub import InferenceClient
5
 
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
- client = InferenceClient(model="Qwen/Qwen2.5-Coder-7B-Instruct", token=HF_TOKEN)
8
-
9
- def extract_total_days(goal: str) -> int:
10
- """Extract number of days from goal like 'in 3 weeks' → 21"""
11
- goal_lower = goal.lower()
12
- # Match "X days", "X weeks", etc.
13
- if m := re.search(r'(\d+)\s*days?', goal_lower):
14
- return int(m.group(1))
15
- if m := re.search(r'(\d+)\s*weeks?', goal_lower):
16
- return int(m.group(1)) * 7
17
- # Default to 14 if unclear
18
- return 14
19
 
20
  def generate_task_plan(goal: str) -> str:
21
- total_days = extract_total_days(goal)
22
-
23
- prompt = f"""You are a professional project manager. Break down the goal into a STRICT task list.
24
-
25
- GOAL: "{goal}"
26
- TOTAL DAYS AVAILABLE: {total_days}
27
-
28
- RULES (VIOLATING ANY = FAILURE):
29
- 1. Output ONLY a numbered list of tasks (1., 2., 3., ...). NO introduction, NO summary, NO extra text.
30
- 2. Every task must have:
31
- - Task name
32
- - "Due: Day N" where 1 N {total_days}
33
- - "Depends on: [Task # or 'None']"
34
- - "Description: [one-sentence explanation]"
35
- 3. Distribute work across all {total_days} days do NOT cram everything into early days.
36
- 4. Allow parallel work (e.g., marketing can start while dev is ongoing).
37
- 5. Final launch and post-launch must happen ON or BEFORE Day {total_days}.
38
- 6. NEVER say "Day 14" if total days is {total_days}. Use the correct max day.
39
-
40
- FORMAT EXAMPLE (for 5-day goal):
41
- 1. Draft requirements - Due: Day 1 - Depends on: None
42
- Description: Define core features and user stories.
43
- 2. Design UI - Due: Day 3 - Depends on: Task 1
44
- Description: Create mockups for main screens.
45
- 3. Develop backend - Due: Day 4 - Depends on: Task 1
46
- Description: Build API and database.
47
- 4. Launch - Due: Day 5 - Depends on: Tasks 2 and 3
48
- Description: Deploy and announce product.
49
-
50
- NOW GENERATE THE PLAN FOR {total_days} DAYS. OUTPUT ONLY THE NUMBERED LIST:"""
 
51
 
52
  try:
53
  response = client.chat.completions.create(
54
  model="Qwen/Qwen2.5-Coder-7B-Instruct",
55
  messages=[{"role": "user", "content": prompt}],
56
- max_tokens=2048,
57
- temperature=0.2, # Very low for precision
58
- top_p=0.9,
59
  stream=False
60
  )
61
- raw = response.choices[0].message.content.strip()
62
-
63
- # Optional: Remove any leading/trailing prose (safety net)
64
- lines = raw.split('\n')
65
- cleaned = []
66
- for line in lines:
67
- if line.strip() and (line.strip()[0].isdigit() or line.strip().startswith(('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.'))):
68
- cleaned.append(line)
69
- elif cleaned: # Stop if we've started and hit non-task text
70
- break
71
-
72
- return '\n'.join(cleaned) if cleaned else raw
73
-
74
  except Exception as e:
75
- raise Exception(f"Planning failed: {str(e)}")
 
1
  # planner.py
2
  import os
 
3
  from huggingface_hub import InferenceClient
4
 
5
  HF_TOKEN = os.getenv("HF_TOKEN")
6
+ client = InferenceClient(
7
+ model="Qwen/Qwen2.5-Coder-7B-Instruct",
8
+ token=HF_TOKEN
9
+ )
 
 
 
 
 
 
 
 
10
 
11
  def generate_task_plan(goal: str) -> str:
12
+ """
13
+ Generate a realistic task plan that respects the timeline in the goal.
14
+ Example: "Launch a product in 4 weeks" use up to Day 28.
15
+ """
16
+ # Simple, clear prompt — no over-engineering
17
+ prompt = f"""
18
+ You are an experienced product manager. Break down the following goal into a clear, practical list of tasks.
19
+
20
+ Goal: "{goal}"
21
+
22
+ Important:
23
+ - If the goal mentions a timeframe (e.g., "in 4 weeks"), convert it to days (4 weeks = 28 days).
24
+ - All tasks must be completed within that total number of days.
25
+ - Distribute work realistically across the full timeline — don’t cram everything early.
26
+ - Include key phases: planning, design, development, testing, marketing, launch, and post-launch.
27
+ - For each task, specify:
28
+ A short name
29
+ A due date as "Due: Day N" (N must be total days)
30
+ • Dependencies (e.g., "Depends on: Task 3" or "None")
31
+ A one-sentence description
32
+
33
+ Output only a numbered list like this:
34
+
35
+ 1. Define product requirements - Due: Day 2 - Depends on: None
36
+ Description: Finalize core features and target users.
37
+ 2. Design user interface - Due: Day 6 - Depends on: Task 1
38
+ Description: Create wireframes and high-fidelity mockups.
39
+ ...
40
+
41
+ Now generate the plan for the goal above. Use the full available time wisely.
42
+ """
43
 
44
  try:
45
  response = client.chat.completions.create(
46
  model="Qwen/Qwen2.5-Coder-7B-Instruct",
47
  messages=[{"role": "user", "content": prompt}],
48
+ max_tokens=800,
49
+ temperature=0.4, # Balanced: clear but not robotic
 
50
  stream=False
51
  )
52
+ return response.choices[0].message.content.strip()
 
 
 
 
 
 
 
 
 
 
 
 
53
  except Exception as e:
54
+ return f"Error: {str(e)}"