update
This commit is contained in:
@@ -3,7 +3,8 @@ from pathlib import Path
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
TEMPLATES_DIR = PROJECT_ROOT / "templates"
|
||||
STORAGE_DIR = PROJECT_ROOT / "storage"
|
||||
DB_PATH = PROJECT_ROOT / "guides.db"
|
||||
FRONTEND_DIST = PROJECT_ROOT / "frontend" / "dist"
|
||||
DB_PATH = STORAGE_DIR / "guides.db"
|
||||
|
||||
ALLOWED_FORMATS = [
|
||||
"OnePager",
|
||||
@@ -24,15 +25,15 @@ FORMAT_META = {
|
||||
}
|
||||
|
||||
GENERATION_TIMEOUTS = {
|
||||
"OnePager": 600,
|
||||
"Cheatsheet": 600,
|
||||
"MiniGuide": 600,
|
||||
"BeginnerGuide": 900,
|
||||
"IntermediateGuide": 1200,
|
||||
"ExtendedGuide": 1500,
|
||||
"OnePager": 900,
|
||||
"Cheatsheet": 900,
|
||||
"MiniGuide": 1200,
|
||||
"BeginnerGuide": 1800,
|
||||
"IntermediateGuide": 2400,
|
||||
"ExtendedGuide": 3000,
|
||||
}
|
||||
|
||||
MAX_CONCURRENT_GENERATIONS = 10
|
||||
MAX_CONCURRENT_GENERATIONS = 6
|
||||
MAX_ITERATIONS = {
|
||||
"OnePager": 3,
|
||||
"Cheatsheet": 3,
|
||||
|
||||
@@ -46,10 +46,18 @@ async def _run_claude(guide_id: str, prompt: str, timeout: int) -> tuple[int, st
|
||||
)
|
||||
_active_processes[guide_id] = process
|
||||
try:
|
||||
stdout, stderr = await asyncio.wait_for(
|
||||
process.communicate(input=prompt.encode("utf-8")),
|
||||
timeout=timeout,
|
||||
)
|
||||
try:
|
||||
stdout, stderr = await asyncio.wait_for(
|
||||
process.communicate(input=prompt.encode("utf-8")),
|
||||
timeout=timeout,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
process.kill()
|
||||
try:
|
||||
await asyncio.wait_for(process.wait(), timeout=5)
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
raise
|
||||
return process.returncode, stdout.decode("utf-8", errors="replace"), stderr.decode("utf-8", errors="replace")
|
||||
finally:
|
||||
_active_processes.pop(guide_id, None)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from config import STORAGE_DIR
|
||||
from config import FRONTEND_DIST, STORAGE_DIR
|
||||
from database import init_db, close_db
|
||||
from routes import router
|
||||
|
||||
@@ -20,11 +20,7 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
app = FastAPI(title="Guides Generator", lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(router)
|
||||
|
||||
if FRONTEND_DIST.exists():
|
||||
app.mount("/", StaticFiles(directory=FRONTEND_DIST, html=True), name="frontend")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
fastapi
|
||||
uvicorn[standard]
|
||||
aiosqlite
|
||||
weasyprint
|
||||
pdf2image
|
||||
|
||||
Reference in New Issue
Block a user