Spaces:
Sleeping
Sleeping
Create data_planner.py
Browse files- data_planner.py +32 -0
data_planner.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🔧 data_planner.py
|
| 2 |
+
import json
|
| 3 |
+
from openai_client import ask_gpt
|
| 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. 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 |
+
|
| 23 |
+
user_msg = {
|
| 24 |
+
"role": "user",
|
| 25 |
+
"content": f"User question: {user_prompt}\n\nCompanyCode: {company_code}"
|
| 26 |
+
}
|
| 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)}
|