yoursdvniel commited on
Commit
38c90b6
·
verified ·
1 Parent(s): 1483182

Update data_planner.py

Browse files
Files changed (1) hide show
  1. data_planner.py +17 -13
data_planner.py CHANGED
@@ -6,17 +6,14 @@ def determine_data_requirements(user_prompt: str, company_code: str):
6
  system_msg = {
7
  "role": "system",
8
  "content": (
9
- "You are a planning assistant for a Firestore chatbot. Your job is to analyze the user's question and return ONLY a JSON object with:
10
- "
11
- "1. 'collections': a list of Firestore collections needed.
12
- "
13
- "2. 'filters': a dictionary of filters to apply, such as companyCode.
14
- "
15
- "3. 'instruction': a clear summary of what to do with the data (e.g., summarize interventions, count tasks).
16
- "
17
- "Always include the filter 'companyCode': '<provided>' in your output.
18
- "
19
- "Strictly return only a valid JSON object with keys: collections, filters, instruction."
20
  )
21
  }
22
 
@@ -27,6 +24,13 @@ def determine_data_requirements(user_prompt: str, company_code: str):
27
 
28
  try:
29
  result = ask_gpt([system_msg, user_msg])
30
- return json.loads(result)
 
 
 
 
 
 
31
  except Exception as e:
32
- return {"error": str(e)}
 
 
6
  system_msg = {
7
  "role": "system",
8
  "content": (
9
+ "You are a planning assistant for a Firestore chatbot. Your job is to analyze the user's question and return ONLY a JSON object with:\n"
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
 
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)}"}