-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
67 lines (54 loc) · 1.5 KB
/
Copy pathmain.py
File metadata and controls
67 lines (54 loc) · 1.5 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Main entry point for the application.
"""
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from app.routes import execution, general
# Configure logging
# Log to both console and file
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
date_format = "%Y-%m-%d %H:%M:%S"
# Create logs directory if it doesn't exist
import os
os.makedirs("logs", exist_ok=True)
# Configure logging with both file and console handlers
logging.basicConfig(
level=logging.INFO,
format=log_format,
datefmt=date_format,
handlers=[
logging.FileHandler("logs/app.log", encoding="utf-8"),
logging.StreamHandler() # Console output
]
)
logger = logging.getLogger(__name__)
# Create FastAPI application
app = FastAPI(
title="Python Execution Agent",
description="A minimal execution agent that can receive Python code, run it safely in an isolated environment and return output and errors.",
version="1.0.0"
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers
app.include_router(general.router)
app.include_router(execution.router)
def main():
"""Main function to run the application."""
logger.info("Starting Python Execution Agent...")
uvicorn.run(
app,
host="0.0.0.0",
port=8000,
log_level="info"
)
if __name__ == "__main__":
main()