|
|
|
|
|
|
|
from threading import Lock |
|
|
|
import falcon |
|
from engine import evaluate_solution |
|
|
|
|
|
class RootResource: |
|
def __init__(self): |
|
self.main_lock = Lock() |
|
self.task_locks = {} |
|
|
|
def on_get(self, request, response): |
|
response.body = 'HESS: HumanEval for Solidity Server v1.2409.0' |
|
|
|
def on_post(self, request, response): |
|
payload = request.media |
|
|
|
bad_request = ('task_id' not in payload or 'solution' not in payload) |
|
if bad_request: |
|
response.status = falcon.HTTP_400 |
|
response.media = { |
|
'error': 'task_id or solution are missing', |
|
} |
|
return |
|
|
|
task_id = payload['task_id'] |
|
solution = payload['solution'] |
|
|
|
with self.main_lock: |
|
if task_id not in self.task_locks: |
|
self.task_locks[task_id] = Lock() |
|
|
|
with self.task_locks[task_id]: |
|
passed = evaluate_solution(task_id, solution) |
|
|
|
response.media = {'passed': passed} |
|
|