Adibrino commited on
Commit
dd2994a
·
1 Parent(s): b31d7cd
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -159,16 +159,25 @@ async def analyze( # type: ignore
159
 
160
  required_keys = ["title", "category", "priority", "service_code"]
161
  missing_keys = [key for key in required_keys if key not in ai_content]
 
162
  if missing_keys:
163
  raise ValueError(f"Missing keys in JSON: {missing_keys}")
 
 
 
164
 
165
  service_code = ai_content["service_code"]
166
  if service_code not in SERVICE_MAP:
167
- print(f"Warning: Service code {service_code} unknown.")
168
-
 
 
 
 
169
  priority = str(ai_content["priority"]).lower()
170
  if priority not in ['high', 'medium', 'low']:
171
- priority = 'medium'
 
172
  ai_content["priority"] = priority
173
 
174
  data = { # type: ignore
 
159
 
160
  required_keys = ["title", "category", "priority", "service_code"]
161
  missing_keys = [key for key in required_keys if key not in ai_content]
162
+
163
  if missing_keys:
164
  raise ValueError(f"Missing keys in JSON: {missing_keys}")
165
+
166
+ if not str(ai_content["title"]).strip():
167
+ raise ValueError("AI returned empty title")
168
 
169
  service_code = ai_content["service_code"]
170
  if service_code not in SERVICE_MAP:
171
+ raise ValueError(f"Invalid service_code: {service_code}. Not found in SERVICE_MAP.")
172
+
173
+ expected_category = SERVICE_MAP[service_code]
174
+ if ai_content["category"] != expected_category:
175
+ raise ValueError(f"Category mismatch. Got '{ai_content['category']}', expected '{expected_category}' for code {service_code}")
176
+
177
  priority = str(ai_content["priority"]).lower()
178
  if priority not in ['high', 'medium', 'low']:
179
+ raise ValueError(f"Invalid priority: {priority}")
180
+
181
  ai_content["priority"] = priority
182
 
183
  data = { # type: ignore