Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Improve API error handling
Tomas Valenta240bd97ada80
diff --git a/api-service/app.py b/api-service/app.pyindex 6316af31b..0a92c6a1f 100644--- a/api-service/app.py+++ b/api-service/app.py@@ -5,13 +5,15 @@ from pprint import pprintfrom dotenv import load_dotenvfrom typing import Listfrom playground_client.exceptions import NotFoundException-from quart import Quart, config, request+from quart import Quart, request, abortfrom quart_cors import cors+from logging.config import dictConfigfrom codegen import Codegenfrom codegen.tools.playground import create_playground_toolsfrom database import Database, DeploymentStatefrom codegen.tools.human.tools import create_human_tools+from werkzeug.exceptions import HTTPExceptionload_dotenv()@@ -27,6 +29,17 @@ app = Quart(__name__)app.config.from_prefixed_env()app = cors(app, allow_origin="*")+dictConfig({+ 'version': 1,+ 'loggers': {+ 'quart.app': {+ 'level': 'INFO',+ },+ 'quart.serving': {+ 'level': 'INFO',+ },+ },+})def get_request_body_template(blocks: List[dict[str, str]]):request_body_blocks = [@@ -38,6 +51,16 @@ def get_request_body_template(blocks: List[dict[str, str]]):return request_body_template[email protected](TimeoutError)+def timeout_handler(e):+ return abort(408, e)+[email protected](Exception)+def exception_handler(e):+ if isinstance(e, HTTPException):+ return e+ return abort(500, str(e))+@app.route("/health", methods=["GET"])async def health():return "OK"@@ -84,14 +107,18 @@ async def generate():database=db,)- # Generate the code- print("Generating...", flush=True)- await cg.generate(- run_id=run_id,- route=route,- method=method,- blocks=blocks,- )+ try:+ # Generate the code+ print("Generating...", flush=True)+ await cg.generate(+ run_id=run_id,+ route=route,+ method=method,+ blocks=blocks,+ )+ except Exception as e:+ print('Error while generating code:', e)+ raise eurl: str | None = None# Disable deployment if there AWS creds are not present