namberino commited on
Commit
fee5e22
·
1 Parent(s): bfd59d7

Update generator

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -147,6 +147,7 @@ async def generate_saved_endpoint(
147
  }
148
 
149
  all_mcqs = {}
 
150
 
151
  for difficulty, n_questions in difficulty_counts.items():
152
  try:
@@ -161,14 +162,27 @@ async def generate_saved_endpoint(
161
  enable_fiddler=enable_fiddler,
162
  target_difficulty=difficulty,
163
  )
164
- for qid, qobj in mcqs.items():
165
- if qid not in all_mcqs:
166
- all_mcqs[qid] = qobj
167
- else:
168
- if isinstance(all_mcqs[qid], list):
169
- all_mcqs[qid].append(qobj)
170
  else:
171
- all_mcqs[qid] = [all_mcqs[qid], qobj]
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  except Exception as e:
174
  raise HTTPException(status_code=500, detail=f"Generation from saved file failed: {e}")
 
147
  }
148
 
149
  all_mcqs = {}
150
+ counter = 1
151
 
152
  for difficulty, n_questions in difficulty_counts.items():
153
  try:
 
162
  enable_fiddler=enable_fiddler,
163
  target_difficulty=difficulty,
164
  )
165
+ questions_list = []
166
+ if isinstance(mcqs, dict):
167
+ # if dict values are lists or single objects, collect them
168
+ for v in mcqs.values():
169
+ if isinstance(v, list):
170
+ questions_list.extend(v)
171
  else:
172
+ questions_list.append(v)
173
+ elif isinstance(mcqs, list):
174
+ questions_list = mcqs
175
+ else:
176
+ # unexpected shape — skip or handle as needed
177
+ continue
178
+
179
+ # assign sequential ids (as strings). use `counter` for numeric keys if preferred.
180
+ for qobj in questions_list:
181
+ if isinstance(qobj, dict):
182
+ # optional: keep which difficulty the question came from
183
+ qobj["_difficulty"] = difficulty
184
+ all_mcqs[str(counter)] = qobj
185
+ counter += 1
186
 
187
  except Exception as e:
188
  raise HTTPException(status_code=500, detail=f"Generation from saved file failed: {e}")