Skip to content

Commit

Permalink
first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrisaberi committed Nov 6, 2023
1 parent f9b99ec commit 62ca281
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
76 changes: 56 additions & 20 deletions api/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,69 @@
import json
from concurrent.futures import ThreadPoolExecutor
from human_eval.execution import check_correctness
from flask import Flask, request, jsonify


app = Flask(__name__)

executor = ThreadPoolExecutor(max_workers=5)


def handler(request, response):
if request.method == "POST":
try:
data = json.loads(request.body)
@app.route("/execute", methods=["POST"])
def execute():
data = request.json

problem = data.get("problem", "")
completion = data.get("completion", "")
timeout = data.get("timeout", 5.0)
args = (problem, completion, timeout)

if not completion:
response = jsonify({"error": "No completion provided"})
response.status_code = HTTPStatus.BAD_REQUEST
return response

try:
future = executor.submit(check_correctness, problem, completion, timeout)
result = future.result()
return jsonify({"result": result})
except Exception as e:
response = jsonify({"error": str(e)})
response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR
return response


@app.errorhandler(500)
def internal_error(error):
return "500 error: {}".format(str(error)), 500


# executor = ThreadPoolExecutor(max_workers=5)

# class
# def handler(request, response):
# if request.method == "POST":
# try:
# data = json.loads(request.body)

problem = data.get("problem", "")
completion = data.get("completion", "")
timeout = data.get("timeout", 3.0)
args = (problem, completion, timeout)
# problem = data.get("problem", "")
# completion = data.get("completion", "")
# timeout = data.get("timeout", 3.0)
# args = (problem, completion, timeout)

if not completion:
response.statusCode = HTTPStatus.BAD_REQUEST
return json.dumps({"error": "No completion provided"})
# if not completion:
# response.statusCode = HTTPStatus.BAD_REQUEST
# return json.dumps({"error": "No completion provided"})

future = executor.submit(check_correctness, *args)
result = future.result()
# future = executor.submit(check_correctness, *args)
# result = future.result()

return json.dumps({"result": result})
# return json.dumps({"result": result})

except Exception as e:
response.statusCode = HTTPStatus.INTERNAL_SERVER_ERROR
return json.dumps({"error": str(e)})
# except Exception as e:
# response.statusCode = HTTPStatus.INTERNAL_SERVER_ERROR
# return json.dumps({"error": str(e)})

else:
response.statusCode = HTTPStatus.METHOD_NOT_ALLOWED
return json.dumps({"error": "Method not allowed"})
# else:
# response.statusCode = HTTPStatus.METHOD_NOT_ALLOWED
# return json.dumps({"error": "Method not allowed"})
3 changes: 2 additions & 1 deletion api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
openai
git+https://github.com/arunpatro/human-eval.git@pipgit
git+https://github.com/arunpatro/human-eval.git@pipgit
Flask
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ function App() {
console.log("data", JSON.stringify(data));

// Sending a POST request to the server
let url = "/api/execute"; // Replace with your server's URL
let url = "/execute"; // Replace with your server's URL
let response = await fetch(url, {
method: "POST",
headers: {
Expand Down

0 comments on commit 62ca281

Please sign in to comment.