Skip to content

Commit e75d526

Browse files
authored
Merge pull request #7 from tisnik/service-stub
REST API service stub
2 parents 29b5c8b + 7ce946f commit e75d526

File tree

8 files changed

+88
-1
lines changed

8 files changed

+88
-1
lines changed

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ name = "lightspeed-stack"
33
version = "0.1.0"
44
description = "LLM tooling stack"
55
authors = []
6-
dependencies = []
76
requires-python = ">=3.11.1,<=3.12.10"
87
readme = "README.md"
98
license = {file = "LICENSE"}
9+
dependencies = [
10+
"fastapi>=0.115.6",
11+
"uvicorn>=0.32.1",
12+
]
1013

1114
[project.urls]
1215
Homepage = "https://github.com/lightspeed-core/lightspeed-stack"
@@ -19,3 +22,6 @@ distribution = true
1922
dev = [
2023
"black>=25.1.0"
2124
]
25+
26+
[tool.pdm.scripts]
27+
start = "pdm run make run"

src/app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""REST API service based on FastAPI."""

src/app/endpoints/info.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Handler for REST API call to provide info."""
2+
3+
import asyncio
4+
import logging
5+
from typing import Any, Optional
6+
7+
from fastapi import APIRouter, Request
8+
9+
logger = logging.getLogger(__name__)
10+
router = APIRouter(tags=["info"])
11+
12+
13+
@router.get("/info")
14+
def info_endpoint_handler(request: Request) -> dict:
15+
return {
16+
"foo": 1,
17+
"bar": 2,
18+
}

src/app/main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from fastapi import FastAPI, Request, Response
2+
from app import routers
3+
import version
4+
5+
app = FastAPI(
6+
title="Swagger service - OpenAPI",
7+
description=f" service API specification.",
8+
version=version.__version__,
9+
license_info={
10+
"name": "Apache 2.0",
11+
"url": "https://www.apache.org/licenses/LICENSE-2.0.html",
12+
},
13+
)
14+
15+
routers.include_routers(app)

src/app/routers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""REST API routers."""
2+
3+
from fastapi import FastAPI
4+
5+
from app.endpoints import (
6+
info,
7+
)
8+
9+
10+
def include_routers(app: FastAPI) -> None:
11+
"""Include FastAPI routers for different endpoints.
12+
13+
Args:
14+
app: The `FastAPI` app instance.
15+
"""
16+
app.include_router(info.router, prefix="/v1")

src/lightspeed-stack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""Lightspeed stack."""
22

3+
from runners.uvicorn import start_uvicorn
4+
import version
5+
36
if __name__ == "__main__":
47
print("Lightspeed stack")
8+
start_uvicorn()

src/runners/uvicorn.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Uvicorn runner."""
2+
3+
import logging
4+
5+
import uvicorn
6+
7+
logger: logging.Logger = logging.getLogger(__name__)
8+
9+
10+
def start_uvicorn() -> None:
11+
"""Start Uvicorn-based REST API service."""
12+
logger.info("Starting Uvicorn")
13+
14+
host = "localhost"
15+
port = 8080
16+
workers = 1
17+
18+
uvicorn.run(
19+
"app.main:app",
20+
host=host,
21+
port=port,
22+
workers=workers,
23+
)

src/version.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Service version that is read by project manager tools."""
2+
3+
# this should be the only version value used in all source codes!!!
4+
__version__ = "0.0.1"

0 commit comments

Comments
 (0)