File size: 1,087 Bytes
5fe2042
 
 
 
 
87f281a
5fe2042
 
 
bbf81ab
c8c3ee1
bbf81ab
5fe2042
 
 
87f281a
5fe2042
 
 
 
 
 
 
 
 
87f281a
fa58e66
 
 
 
 
8868fea
6008bf2
 
8868fea
87f281a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import falcon
from engine import evaluate_solution
import logging


class RootResource:
    def on_get(self, request, response):
        response.text = 'HumanEval for Solidity Server'

    def on_post(self, request, response):
        payload = request.media

        if 'task_id' not in payload or 'solution' not in payload:
            response.status = falcon.HTTP_400
            response.media = {
                'error': 'task_id or solution are missing',
            }
            return

        task_id = payload['task_id']
        solution = payload['solution']

        try:
            passed, output = evaluate_solution(task_id, solution)
            response.media = {
                'passed': passed,
                'output': output,
            }
        except FileNotFoundError:
            response.status = falcon.HTTP_404
            response.media = {'error': 'Task not found'}
        except Exception:
            response.status = falcon.HTTP_500
            response.media = {'error': 'Internal server error'}