-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
5,816 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
MOATLESS_DIR=/tmp/moatless | ||
|
||
REPO_DIR=/tmp/repos | ||
INDEX_STORE_DIR=/tmp/moatless/index-store | ||
|
||
DEFAULT_MODEL=gpt-4o-2024-05-13 | ||
CHEAP_MODEL=gpt-4o-mini-2024-07-18 | ||
VOYAGE_API_KEY= | ||
OPENAI_API_KEY= | ||
ANTHROPIC_API_KEY= | ||
|
||
INDEX_STORE_DIR=/tmp/moatless/index-store | ||
INDEX_STORE_URL="https://stmoatless.blob.core.windows.net/indexstore/20240522-voyage-code-2" | ||
TESTBED_API_KEY= | ||
#TESTBED_BASE_URL=https://testbeds.moatless.ai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
from dotenv import load_dotenv | ||
import moatless.api.api | ||
import uvicorn | ||
|
||
|
||
def run_api(): | ||
"""Run the Moatless API server""" | ||
# Load environment variables from .env file | ||
load_dotenv() | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
logger = logging.getLogger(__name__) | ||
|
||
# Create and run API without workspace | ||
api = moatless.api.api.create_api() | ||
logger.info("Starting API server") | ||
uvicorn.run(api, host="0.0.0.0", port=8000) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_api() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from fastapi import FastAPI, HTTPException, UploadFile | ||
from typing import List, Dict, Any | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from dotenv import load_dotenv | ||
import json | ||
import logging | ||
from moatless.workspace import Workspace | ||
from moatless.artifacts.artifact import ArtifactListItem | ||
from moatless.api.schema import TrajectoryDTO | ||
from moatless.api.trajectory_utils import load_trajectory_from_file, create_trajectory_dto | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_api(workspace: Workspace | None = None) -> FastAPI: | ||
"""Create and initialize the API with an optional workspace""" | ||
api = FastAPI(title="Moatless API") | ||
|
||
# Add CORS middleware with proper configuration | ||
origins = [ | ||
"http://localhost:5173", # SvelteKit dev server | ||
"http://127.0.0.1:5173", # Alternative local dev URL (IPv4) | ||
"http://[::1]:5173", # Alternative local dev URL (IPv6) | ||
] | ||
|
||
api.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], | ||
allow_headers=["*"], | ||
max_age=3600, # Cache preflight requests for 1 hour | ||
) | ||
|
||
if workspace is not None: | ||
|
||
@api.get("/artifacts", response_model=List[ArtifactListItem]) | ||
async def list_all_artifacts(): | ||
"""Get all artifacts across all types""" | ||
return workspace.get_all_artifacts() | ||
|
||
@api.get("/artifacts/{type}", response_model=List[ArtifactListItem]) | ||
async def list_artifacts(type: str): | ||
try: | ||
return workspace.get_artifacts_by_type(type) | ||
except ValueError as e: | ||
raise HTTPException(status_code=404, detail=str(e)) | ||
|
||
@api.get("/artifacts/{type}/{id}", response_model=Dict[str, Any]) | ||
async def get_artifact(type: str, id: str): | ||
try: | ||
artifact = workspace.get_artifact(type, id) | ||
if not artifact: | ||
raise HTTPException(status_code=404, detail=f"Artifact {id} not found") | ||
return artifact.to_ui_representation() | ||
except ValueError as e: | ||
raise HTTPException(status_code=404, detail=str(e)) | ||
|
||
@api.get("/trajectory", response_model=TrajectoryDTO) | ||
async def get_trajectory(file_path: str): | ||
"""Get trajectory data from a file path""" | ||
try: | ||
return load_trajectory_from_file(file_path) | ||
except ValueError as e: | ||
raise HTTPException(status_code=404, detail=str(e)) | ||
|
||
@api.post("/trajectory/upload", response_model=TrajectoryDTO) | ||
async def upload_trajectory(file: UploadFile): | ||
"""Upload and process a trajectory file""" | ||
try: | ||
content = await file.read() | ||
trajectory_data = json.loads(content.decode()) | ||
return create_trajectory_dto(trajectory_data) | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=f"Invalid trajectory file: {str(e)}") | ||
|
||
return api |
Oops, something went wrong.