yoursdvniel commited on
Commit
b72b771
·
verified ·
1 Parent(s): 600fb13

Update data_planner.py

Browse files
Files changed (1) hide show
  1. data_planner.py +20 -7
data_planner.py CHANGED
@@ -2,18 +2,31 @@ import json
2
  from openai_client import ask_gpt
3
  from schema_map import schema # 👈 Import the full schema
4
 
5
-
6
- def determine_data_requirements(user_prompt: str, company_code: str, user_id: str):
 
 
 
 
 
 
7
 
8
  system_msg = {
9
  "role": "system",
10
  "content": (
11
  "You are a planning assistant for a Firestore chatbot.\n"
12
- "Your job is to analyze the user's question and return ONLY a JSON object with:\n"
13
- "1. 'collections': a list of Firestore collections needed.\n"
14
- "2. 'filters': a dictionary of filters to apply (e.g., companyCode, userId).\n"
15
- "3. 'instruction': a clear summary of what to do with the data (e.g., summarize interventions).\n\n"
16
- f"The current user has companyCode = '{company_code}' and userId = '{user_id}'.\n"
 
 
 
 
 
 
 
17
  "Use this schema for all reasoning. It includes field names, types, and aliases:\n"
18
  f"{json.dumps(schema)}\n\n"
19
  "Strictly return only a valid JSON object with keys: collections, filters, instruction. No explanation."
 
2
  from openai_client import ask_gpt
3
  from schema_map import schema # 👈 Import the full schema
4
 
5
+ def determine_data_requirements(
6
+ user_prompt: str,
7
+ company_code: str,
8
+ user_id: str,
9
+ participant_email: str | None,
10
+ participant_id: str | None,
11
+ ):
12
+ token_participant = "{{{{participantId}}}}" # renders as {{participantId}} inside f-string
13
 
14
  system_msg = {
15
  "role": "system",
16
  "content": (
17
  "You are a planning assistant for a Firestore chatbot.\n"
18
+ "Return ONLY JSON with keys: collections, filters, instruction.\n"
19
+ "Rules:\n"
20
+ "- Always include filters.companyCode set to the current company.\n"
21
+ "- The 'userId' is an Auth UID (users/{uid}).\n"
22
+ "- 'applications.participantId' is the doc ID of /participants/{participantId}.\n"
23
+ "- To reference the current user's participant-linked data, use this participantId.\n"
24
+ f"- If you need the current participant, use token {token_participant} in filters.\n"
25
+ "- If participantId is unavailable, prefer filtering by email where applicable.\n\n"
26
+ f"Current companyCode: '{company_code}'\n"
27
+ f"Current uid: '{user_id}'\n"
28
+ f"Current user email: '{participant_email or ''}'\n"
29
+ f"Current participantId: '{participant_id or ''}'\n"
30
  "Use this schema for all reasoning. It includes field names, types, and aliases:\n"
31
  f"{json.dumps(schema)}\n\n"
32
  "Strictly return only a valid JSON object with keys: collections, filters, instruction. No explanation."