Spaces:
Runtime error
Runtime error
tech-envision
commited on
Commit
·
e75d7f2
1
Parent(s):
dcff6aa
Refactor API into separate package
Browse files- README.md +4 -2
- src/api.py → api_app/__init__.py +4 -9
- api_app/__main__.py +16 -0
README.md
CHANGED
|
@@ -124,10 +124,12 @@ more like a standard Ubuntu installation.
|
|
| 124 |
|
| 125 |
## REST API
|
| 126 |
|
| 127 |
-
Start the API server
|
| 128 |
|
| 129 |
```bash
|
| 130 |
-
|
|
|
|
|
|
|
| 131 |
```
|
| 132 |
|
| 133 |
### Endpoints
|
|
|
|
| 124 |
|
| 125 |
## REST API
|
| 126 |
|
| 127 |
+
Start the API server as a module or with ``uvicorn``:
|
| 128 |
|
| 129 |
```bash
|
| 130 |
+
python -m api_app
|
| 131 |
+
# or
|
| 132 |
+
uvicorn api_app:app --host 0.0.0.0 --port 8000
|
| 133 |
```
|
| 134 |
|
| 135 |
### Endpoints
|
src/api.py → api_app/__init__.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from fastapi import FastAPI, UploadFile, File, Form
|
| 4 |
-
from fastapi.responses import StreamingResponse
|
| 5 |
from fastapi import HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
import asyncio
|
|
@@ -9,9 +9,9 @@ import os
|
|
| 9 |
import tempfile
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
-
from .chat import ChatSession
|
| 13 |
-
from .log import get_logger
|
| 14 |
-
from .db import list_sessions, list_sessions_info
|
| 15 |
|
| 16 |
|
| 17 |
_LOG = get_logger(__name__)
|
|
@@ -79,8 +79,3 @@ def create_app() -> FastAPI:
|
|
| 79 |
|
| 80 |
|
| 81 |
app = create_app()
|
| 82 |
-
|
| 83 |
-
if __name__ == "__main__": # pragma: no cover - manual start
|
| 84 |
-
import uvicorn
|
| 85 |
-
|
| 86 |
-
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", "8000")))
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
from fastapi import FastAPI, UploadFile, File, Form
|
| 4 |
+
from fastapi.responses import StreamingResponse
|
| 5 |
from fastapi import HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
import asyncio
|
|
|
|
| 9 |
import tempfile
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
+
from src.chat import ChatSession
|
| 13 |
+
from src.log import get_logger
|
| 14 |
+
from src.db import list_sessions, list_sessions_info
|
| 15 |
|
| 16 |
|
| 17 |
_LOG = get_logger(__name__)
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
app = create_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api_app/__main__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
from . import app
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main() -> None:
|
| 11 |
+
"""Run the FastAPI application using uvicorn."""
|
| 12 |
+
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", "8000")))
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
if __name__ == "__main__": # pragma: no cover - entry point
|
| 16 |
+
main()
|