yoursdvniel commited on
Commit
44d7acc
·
verified ·
1 Parent(s): ad2bd73

Update data_planner.py

Browse files
Files changed (1) hide show
  1. data_planner.py +8 -13
data_planner.py CHANGED
@@ -1,4 +1,3 @@
1
- # 🔧 data_planner.py
2
  import json
3
  from openai_client import ask_gpt
4
 
@@ -10,10 +9,8 @@ def determine_data_requirements(user_prompt: str, company_code: str):
10
  "1. 'collections': a list of Firestore collections needed.\n"
11
  "2. 'filters': a dictionary of filters to apply, such as companyCode.\n"
12
  "3. 'instruction': a clear summary of what to do with the data (e.g., summarize interventions, count tasks).\n"
13
- "Always include the filter 'companyCode': '<provided>' in your output.\n"
14
- "Strictly return only a valid JSON object with keys: collections, filters, instruction.\n"
15
- "Never return markdown, explanations, or preamble.\n"
16
- "Return ONLY a raw JSON object."
17
  )
18
  }
19
 
@@ -24,13 +21,11 @@ def determine_data_requirements(user_prompt: str, company_code: str):
24
 
25
  try:
26
  result = ask_gpt([system_msg, user_msg])
27
- print("🧠 Raw planning response from Gemini:")
28
- print(result)
29
 
30
- parsed = json.loads(result)
31
- if "collections" not in parsed:
32
- raise ValueError("Response JSON missing 'collections'")
33
- return parsed
34
  except Exception as e:
35
- print(" Planning error:", str(e))
36
- return {"error": f"Planning failed: {str(e)}"}
 
 
1
  import json
2
  from openai_client import ask_gpt
3
 
 
9
  "1. 'collections': a list of Firestore collections needed.\n"
10
  "2. 'filters': a dictionary of filters to apply, such as companyCode.\n"
11
  "3. 'instruction': a clear summary of what to do with the data (e.g., summarize interventions, count tasks).\n"
12
+ f"Always include the filter 'companyCode': '{company_code}' in your output.\n"
13
+ "Strictly return only a valid JSON object with keys: collections, filters, instruction."
 
 
14
  )
15
  }
16
 
 
21
 
22
  try:
23
  result = ask_gpt([system_msg, user_msg])
24
+ print("🧠 Raw planning response from Gemini:\n", result)
 
25
 
26
+ # Strip markdown formatting (``` or ```json)
27
+ cleaned = result.strip().removeprefix("```json").removeprefix("```").removesuffix("```").strip()
28
+
29
+ return json.loads(cleaned)
30
  except Exception as e:
31
+ return {"error": f"Planning failed: {str(e)}"}