yoursdvniel commited on
Commit
a216aa1
·
verified ·
1 Parent(s): ae85c35

Update data_planner.py

Browse files
Files changed (1) hide show
  1. data_planner.py +10 -8
data_planner.py CHANGED
@@ -1,16 +1,20 @@
1
  import json
2
  from openai_client import ask_gpt
 
3
 
4
  def determine_data_requirements(user_prompt: str, company_code: str):
5
  system_msg = {
6
  "role": "system",
7
  "content": (
8
- "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"
 
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
 
@@ -23,9 +27,7 @@ def determine_data_requirements(user_prompt: str, company_code: str):
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)}"}
 
1
  import json
2
  from openai_client import ask_gpt
3
+ from schema_map import schema # 👈 Import the full schema
4
 
5
  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.\n"
10
+ "Your job is to analyze the user's question and return ONLY a JSON object with:\n"
11
  "1. 'collections': a list of Firestore collections needed.\n"
12
+ "2. 'filters': a dictionary of filters to apply (e.g., companyCode).\n"
13
+ "3. 'instruction': a clear summary of what to do with the data (e.g., summarize interventions).\n\n"
14
+ f"Always include the filter 'companyCode': '{company_code}'.\n"
15
+ "Use this schema for all reasoning. It includes field names, types, and aliases:\n"
16
+ f"{json.dumps(schema)}\n\n"
17
+ "Strictly return only a valid JSON object with keys: collections, filters, instruction. No explanation."
18
  )
19
  }
20
 
 
27
  result = ask_gpt([system_msg, user_msg])
28
  print("🧠 Raw planning response from Gemini:\n", result)
29
 
 
30
  cleaned = result.strip().removeprefix("```json").removeprefix("```").removesuffix("```").strip()
 
31
  return json.loads(cleaned)
32
  except Exception as e:
33
+ return {"error": f"Planning failed: {str(e)}"}