ciyidogan commited on
Commit
6ce332f
·
verified ·
1 Parent(s): fe4f0b2

Update project_controller.py

Browse files
Files changed (1) hide show
  1. project_controller.py +34 -0
project_controller.py CHANGED
@@ -198,3 +198,37 @@ def clear_all():
198
  json.dump(service_config, f, indent=2)
199
 
200
  return {"message": "All projects cleared"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  json.dump(service_config, f, indent=2)
199
 
200
  return {"message": "All projects cleared"}
201
+
202
+ @router.post("/update_intent")
203
+ async def update_intent(request: Request):
204
+ data = await request.json()
205
+ project_name = data.get("project_name")
206
+ intent_name = data.get("intent_name")
207
+ intent_data = data.get("intent_data")
208
+
209
+ if not project_name or not intent_name or not intent_data:
210
+ raise HTTPException(status_code=400, detail="project_name, intent_name, and intent_data are required")
211
+
212
+ project = service_config.projects.get(project_name)
213
+ if not project:
214
+ raise HTTPException(status_code=404, detail="Project not found")
215
+
216
+ latest = max(project["versions"], key=lambda v: v["version_number"])
217
+
218
+ updated = False
219
+ for intent in latest.get("intents", []):
220
+ if intent.get("name") == intent_name:
221
+ intent.update(intent_data)
222
+ updated = True
223
+ break
224
+
225
+ if not updated:
226
+ raise HTTPException(status_code=404, detail="Intent not found in project")
227
+
228
+ project["last_updated"] = get_utc_now()
229
+
230
+ with open(service_config.config_path, "w", encoding="utf-8") as f:
231
+ json.dump(service_config, f, indent=2)
232
+
233
+ return {"message": f"Intent {intent_name} updated in project {project_name}"}
234
+