Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from google import genai
|
| 7 |
from google.genai import types
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
-
# --- CORS SETTING (Isse mobile app aur browser me Failed to Fetch nahi aayega) ---
|
| 12 |
app.add_middleware(
|
| 13 |
CORSMiddleware,
|
| 14 |
-
allow_origins=["*"],
|
| 15 |
allow_credentials=True,
|
| 16 |
-
allow_methods=["*"],
|
| 17 |
allow_headers=["*"],
|
| 18 |
)
|
| 19 |
|
|
@@ -25,7 +24,6 @@ class ChatRequest(BaseModel):
|
|
| 25 |
|
| 26 |
def execute_in_sandbox(command: str):
|
| 27 |
try:
|
| 28 |
-
# /tmp directory me user ko bina sudo ke full write access milti hai
|
| 29 |
full_command = f"cd /tmp && {command}"
|
| 30 |
|
| 31 |
result = subprocess.run(
|
|
@@ -33,7 +31,7 @@ def execute_in_sandbox(command: str):
|
|
| 33 |
shell=True,
|
| 34 |
capture_output=True,
|
| 35 |
text=True,
|
| 36 |
-
timeout=
|
| 37 |
)
|
| 38 |
return {
|
| 39 |
"stdout": result.stdout,
|
|
@@ -47,12 +45,13 @@ def execute_in_sandbox(command: str):
|
|
| 47 |
async def agent_chat(request: ChatRequest):
|
| 48 |
user_prompt = request.message
|
| 49 |
|
| 50 |
-
# AI ko strictly bol rahe hain ki sudo use na kare, balki /tmp me local tools setup kare
|
| 51 |
system_instruction = (
|
| 52 |
"You are an AI Agent Builder operating inside a limited Linux sandbox. "
|
| 53 |
-
"You CANNOT use 'sudo' or root commands
|
| 54 |
-
"
|
| 55 |
-
"
|
|
|
|
|
|
|
| 56 |
"If you want to execute any bash setup, return the exact script inside a triple backtick block starting with 'bash'."
|
| 57 |
)
|
| 58 |
|
|
@@ -76,3 +75,4 @@ async def agent_chat(request: ChatRequest):
|
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from pydantic import BaseModel
|
| 6 |
from google import genai
|
| 7 |
from google.genai import types
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
|
|
|
| 11 |
app.add_middleware(
|
| 12 |
CORSMiddleware,
|
| 13 |
+
allow_origins=["*"],
|
| 14 |
allow_credentials=True,
|
| 15 |
+
allow_methods=["*"],
|
| 16 |
allow_headers=["*"],
|
| 17 |
)
|
| 18 |
|
|
|
|
| 24 |
|
| 25 |
def execute_in_sandbox(command: str):
|
| 26 |
try:
|
|
|
|
| 27 |
full_command = f"cd /tmp && {command}"
|
| 28 |
|
| 29 |
result = subprocess.run(
|
|
|
|
| 31 |
shell=True,
|
| 32 |
capture_output=True,
|
| 33 |
text=True,
|
| 34 |
+
timeout=900 # 15 Mins global timeout
|
| 35 |
)
|
| 36 |
return {
|
| 37 |
"stdout": result.stdout,
|
|
|
|
| 45 |
async def agent_chat(request: ChatRequest):
|
| 46 |
user_prompt = request.message
|
| 47 |
|
|
|
|
| 48 |
system_instruction = (
|
| 49 |
"You are an AI Agent Builder operating inside a limited Linux sandbox. "
|
| 50 |
+
"You CANNOT use 'sudo' or root commands. Always use `/tmp` for your file operations. "
|
| 51 |
+
"IMPORTANT SYSTEM INFO: OpenJDK 17, xz-utils, git, curl, and unzip are ALREADY fully installed and available in the system path. "
|
| 52 |
+
"Do NOT attempt to download or extract Java. You can directly use 'java -version'. "
|
| 53 |
+
"To build Flutter apps, you only need to curl the stable Flutter tar.xz into `/tmp`, extract it, set up the android-cmdline-tools/sdkmanager inside `/tmp`, and run the build. "
|
| 54 |
+
"Always clean up heavy deployment folders from `/tmp` AFTER successfully uploading the compiled APK to gofile.io to save disk space. "
|
| 55 |
"If you want to execute any bash setup, return the exact script inside a triple backtick block starting with 'bash'."
|
| 56 |
)
|
| 57 |
|
|
|
|
| 75 |
|
| 76 |
except Exception as e:
|
| 77 |
raise HTTPException(status_code=500, detail=str(e))
|
| 78 |
+
|