Delete app.py
Browse files
app.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
import subprocess
|
| 2 |
-
import os
|
| 3 |
-
from fastapi import FastAPI, HTTPException
|
| 4 |
-
from pydantic import BaseModel
|
| 5 |
-
|
| 6 |
-
app = FastAPI(title="OpenCode API")
|
| 7 |
-
|
| 8 |
-
class PromptRequest(BaseModel):
|
| 9 |
-
prompt: str
|
| 10 |
-
|
| 11 |
-
@app.post("/ask")
|
| 12 |
-
async def ask_openai(request: PromptRequest):
|
| 13 |
-
try:
|
| 14 |
-
result = subprocess.run(
|
| 15 |
-
["opencode", "-p", request.prompt],
|
| 16 |
-
capture_output=True,
|
| 17 |
-
text=True,
|
| 18 |
-
timeout=60,
|
| 19 |
-
env={**os.environ, "OPENCODE_DATA_DIR": "/data"}
|
| 20 |
-
)
|
| 21 |
-
if result.returncode != 0:
|
| 22 |
-
raise HTTPException(status_code=500, detail=result.stderr)
|
| 23 |
-
return {"response": result.stdout}
|
| 24 |
-
except subprocess.TimeoutExpired:
|
| 25 |
-
raise HTTPException(status_code=504, detail="Request timeout")
|
| 26 |
-
except Exception as e:
|
| 27 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 28 |
-
|
| 29 |
-
@app.get("/")
|
| 30 |
-
def root():
|
| 31 |
-
return {"message": "OpenCode API is running. Use POST /ask with JSON {\"prompt\": \"your question\"}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|