Spaces:
Sleeping
Sleeping
Commit ·
ad218ef
1
Parent(s): a1cc5c5
update the request url
Browse files- app/deployer.py +45 -0
- app/llm.py +5 -0
- app/main.py +23 -5
- app/models.py +12 -0
- app/rounds.py +29 -0
- evaluation/__init__.py +0 -0
- evaluation/server.py +14 -0
- requirements.txt +1 -1
app/deployer.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import httpx
|
| 2 |
+
import os
|
| 3 |
+
import logging
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
|
| 9 |
+
GITHUB_API_URL = "https://api.github.com/"
|
| 10 |
+
logger = logging.getLogger(__name__)
|
| 11 |
+
|
| 12 |
+
async def create_github_repo(repo_name: str) -> dict:
|
| 13 |
+
headers = {"Authorization":f"Bearer {GITHUB_TOKEN}",
|
| 14 |
+
'Accept': 'application/vnd.github+json'
|
| 15 |
+
}
|
| 16 |
+
payload = {"name": repo_name}
|
| 17 |
+
|
| 18 |
+
async with httpx.AsyncClient() as client:
|
| 19 |
+
try:
|
| 20 |
+
response = await client.post(f"{GITHUB_API_URL}user/repos", headers=headers, json=payload)
|
| 21 |
+
response.raise_for_status()
|
| 22 |
+
logger.info(f"GitHub repo '{repo_name}' created successfully.")
|
| 23 |
+
return response.json()
|
| 24 |
+
except httpx.HTTPError as e:
|
| 25 |
+
logger.error(f"Failed to create GitHub repo: {e}")
|
| 26 |
+
raise RuntimeError(f"GitHub repo creation failed: {e}") from e
|
| 27 |
+
|
| 28 |
+
def push_to_repo():
|
| 29 |
+
return
|
| 30 |
+
|
| 31 |
+
def get_latest_sha():
|
| 32 |
+
return
|
| 33 |
+
|
| 34 |
+
def enable_github_pages():
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
async def notify_evaluation_url(evaluation_url: str, payload: dict):
|
| 39 |
+
async with httpx.AsyncClient() as client:
|
| 40 |
+
try:
|
| 41 |
+
response = await client.post(evaluation_url, json=payload, timeout=10.0)
|
| 42 |
+
response.raise_for_status()
|
| 43 |
+
except httpx.HTTPError as e:
|
| 44 |
+
# Log error or handle failure as needed
|
| 45 |
+
print(f"Failed to notify evaluation URL: {e}")
|
app/llm.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def genereate_code_with_llm():
|
| 2 |
+
pass
|
| 3 |
+
|
| 4 |
+
#might have to use pydantic ai
|
| 5 |
+
#we might need to fetch data from specific attachments
|
app/main.py
CHANGED
|
@@ -1,19 +1,37 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException, status, Request
|
|
|
|
| 2 |
from .models import TaskRequest
|
| 3 |
from .utils import validate_secret
|
|
|
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
if not validate_secret(request.secret):
|
| 9 |
raise HTTPException(
|
| 10 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 11 |
detail="Invalid secret",
|
| 12 |
headers={"WWW-Authenticate": "Bearer"},
|
| 13 |
)
|
| 14 |
-
# Proceed with further task processing here
|
| 15 |
-
return {"status": "success"}
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, status, Request,BackgroundTasks
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
from .models import TaskRequest
|
| 4 |
from .utils import validate_secret
|
| 5 |
+
from .rounds import round1,round2
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
|
| 9 |
+
@app.post("/handle-task",status_code=status.HTTP_200_OK)
|
| 10 |
+
async def handle_task(request: TaskRequest, background_tasks: BackgroundTasks):
|
| 11 |
+
# Validate secret
|
| 12 |
if not validate_secret(request.secret):
|
| 13 |
raise HTTPException(
|
| 14 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 15 |
detail="Invalid secret",
|
| 16 |
headers={"WWW-Authenticate": "Bearer"},
|
| 17 |
)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# Respond immediately
|
| 20 |
+
response = JSONResponse(
|
| 21 |
+
status_code=status.HTTP_200_OK,
|
| 22 |
+
content={
|
| 23 |
+
"status": "success",
|
| 24 |
+
"message": "Secret validated, task accepted for processing."
|
| 25 |
+
}
|
| 26 |
+
)
|
| 27 |
+
if request.round == 1 or request.round =="1":
|
| 28 |
+
print("in round 1")
|
| 29 |
+
background_tasks.add_task(round1, request)
|
| 30 |
+
elif request.round ==2 or request.round =="2":
|
| 31 |
+
background_tasks.add_task(round2)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
return response
|
| 35 |
|
| 36 |
|
| 37 |
|
app/models.py
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
|
|
| 1 |
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
class TaskRequest(BaseModel):
|
|
|
|
| 4 |
secret: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
class Attachment(BaseModel):
|
| 4 |
+
name: str
|
| 5 |
+
url: str
|
| 6 |
|
| 7 |
class TaskRequest(BaseModel):
|
| 8 |
+
email: str
|
| 9 |
secret: str
|
| 10 |
+
task: str
|
| 11 |
+
round: int
|
| 12 |
+
nonce: str
|
| 13 |
+
brief: str
|
| 14 |
+
checks: List[str]
|
| 15 |
+
evaluation_url: str
|
| 16 |
+
attachments: Optional[List[Attachment]] = None
|
app/rounds.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .models import TaskRequest
|
| 2 |
+
from .deployer import create_github_repo,notify_evaluation_url
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def round2():
|
| 6 |
+
print("inside round 2")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
async def round1(request: TaskRequest):
|
| 10 |
+
try:
|
| 11 |
+
repo_response = await create_github_repo(repo_name=request.task)
|
| 12 |
+
repo_url = repo_response.get("html_url", "")
|
| 13 |
+
# Temporary placeholders for commit_sha and pages_url
|
| 14 |
+
commit_sha = ""
|
| 15 |
+
pages_url = ""
|
| 16 |
+
|
| 17 |
+
# Prepare payload
|
| 18 |
+
payload = {
|
| 19 |
+
"email": request.email,
|
| 20 |
+
"task": request.task,
|
| 21 |
+
"round": request.round,
|
| 22 |
+
"nonce": request.nonce,
|
| 23 |
+
"repo_url": repo_url,
|
| 24 |
+
"commit_sha": commit_sha,
|
| 25 |
+
"pages_url": pages_url,
|
| 26 |
+
}
|
| 27 |
+
await notify_evaluation_url(request.evaluation_url, payload)
|
| 28 |
+
except Exception as e:
|
| 29 |
+
print(f"Error in background task: {e}")
|
evaluation/__init__.py
ADDED
|
File without changes
|
evaluation/server.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
import uvicorn
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
@app.post("/notify")
|
| 7 |
+
async def receive_evaluation(request: Request):
|
| 8 |
+
data = await request.json()
|
| 9 |
+
print("Received evaluation data:")
|
| 10 |
+
print(data)
|
| 11 |
+
return {"status": "received"}
|
| 12 |
+
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
uvicorn.run(app, host="0.0.0.0", port=8001)
|
requirements.txt
CHANGED
|
@@ -2,6 +2,6 @@ fastapi==0.104.1
|
|
| 2 |
uvicorn[standard]==0.24.0
|
| 3 |
python-multipart==0.0.6
|
| 4 |
pydantic
|
| 5 |
-
|
| 6 |
|
| 7 |
python-dotenv==1.0.0
|
|
|
|
| 2 |
uvicorn[standard]==0.24.0
|
| 3 |
python-multipart==0.0.6
|
| 4 |
pydantic
|
| 5 |
+
httpx
|
| 6 |
|
| 7 |
python-dotenv==1.0.0
|