1
1
from __future__ import annotations
2
- import os , time , random , json , uuid , glob , torch , traceback
2
+ import os , time , random , json , uuid , torch , traceback
3
3
4
4
from enum import Enum
5
5
from typing import List , Tuple
@@ -182,7 +182,9 @@ def predict_model(model: Model) -> List[str]:
182
182
183
183
verify_token = uuid .uuid4 ().hex
184
184
185
- with open (f"data/{ user_token } -{ verify_token } .json" , "w+" ) as f :
185
+ user_dir = os .path .join ("data" , user_token )
186
+ os .makedirs (user_dir , exist_ok = True )
187
+ with open (os .path .join (user_dir , f"{ verify_token } .json" ), "w+" ) as f :
186
188
f .write (json .dumps ({
187
189
"completionTimestamp" : datetime .now ().isoformat (),
188
190
"triggerPoint" : values ["triggerPoint" ],
@@ -199,9 +201,8 @@ def predict_model(model: Model) -> List[str]:
199
201
"rightContext" : right_context if store_context else None
200
202
}))
201
203
202
- # # # TODO: disabled surveys temporarily, as we are currently looking through >1M files on every request.
203
- # n_suggestions = len(glob.glob(f"data/{user_token}*.json"))
204
- # survey = n_suggestions >= 100 and n_suggestions % 50 == 0
204
+ n_suggestions = len (os .listdir (user_dir ))
205
+ survey = n_suggestions >= 100 and n_suggestions % 50 == 0
205
206
survey = False
206
207
207
208
return response ({
@@ -230,7 +231,7 @@ def verify():
230
231
return res
231
232
232
233
verify_token = values ["verifyToken" ]
233
- file_path = f "data/ { user_token } - { verify_token } .json"
234
+ file_path = os . path . join ( "data" , user_token , f" { verify_token } .json")
234
235
if not os .path .exists (file_path ):
235
236
return response ({
236
237
"error" : "Invalid verify token"
0 commit comments