Spaces:
Runtime error
Runtime error
Remove server and API codebase, including FastAPI app, models, and router.
Browse files- server.py +0 -13
- src/api/__init__.py +0 -3
- src/api/app.py +0 -13
- src/api/models.py +0 -20
- src/api/router.py +0 -29
server.py
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
import uvicorn
|
4 |
-
|
5 |
-
from src.api import create_app
|
6 |
-
|
7 |
-
|
8 |
-
def main() -> None:
|
9 |
-
uvicorn.run(create_app(), host="0.0.0.0", port=8000)
|
10 |
-
|
11 |
-
|
12 |
-
if __name__ == "__main__": # pragma: no cover - manual start
|
13 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/api/__init__.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
from .app import create_app
|
2 |
-
|
3 |
-
__all__ = ["create_app"]
|
|
|
|
|
|
|
|
src/api/app.py
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
from fastapi import FastAPI
|
4 |
-
|
5 |
-
from .router import router
|
6 |
-
|
7 |
-
__all__ = ["create_app"]
|
8 |
-
|
9 |
-
|
10 |
-
def create_app() -> FastAPI:
|
11 |
-
app = FastAPI(title="LLM Chat API", version="1.0.0")
|
12 |
-
app.include_router(router)
|
13 |
-
return app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/api/models.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
from pydantic import BaseModel, Field
|
4 |
-
|
5 |
-
__all__ = ["ChatRequest", "ChatResponse", "ResetRequest", "ResetResponse"]
|
6 |
-
|
7 |
-
class ChatRequest(BaseModel):
|
8 |
-
user: str = Field(..., example="default")
|
9 |
-
session: str = Field(..., example="default")
|
10 |
-
prompt: str = Field(..., min_length=1, example="Hello")
|
11 |
-
|
12 |
-
class ChatResponse(BaseModel):
|
13 |
-
reply: str
|
14 |
-
|
15 |
-
class ResetRequest(BaseModel):
|
16 |
-
user: str
|
17 |
-
session: str
|
18 |
-
|
19 |
-
class ResetResponse(BaseModel):
|
20 |
-
removed: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/api/router.py
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
from fastapi import APIRouter, HTTPException, status
|
4 |
-
|
5 |
-
from .models import ChatRequest, ChatResponse, ResetRequest, ResetResponse
|
6 |
-
from ..chat import ChatSession
|
7 |
-
from ..db import reset_history
|
8 |
-
from ..log import get_logger
|
9 |
-
|
10 |
-
router = APIRouter()
|
11 |
-
log = get_logger(__name__)
|
12 |
-
|
13 |
-
|
14 |
-
@router.post("/chat", response_model=ChatResponse, status_code=status.HTTP_200_OK)
|
15 |
-
async def chat_endpoint(payload: ChatRequest) -> ChatResponse:
|
16 |
-
log.debug("chat request user=%s session=%s", payload.user, payload.session)
|
17 |
-
async with ChatSession(user=payload.user, session=payload.session) as chat:
|
18 |
-
try:
|
19 |
-
reply = await chat.chat(payload.prompt)
|
20 |
-
except Exception as exc: # pragma: no cover - runtime errors
|
21 |
-
log.exception("chat processing failed")
|
22 |
-
raise HTTPException(status_code=500, detail=str(exc)) from exc
|
23 |
-
return ChatResponse(reply=reply)
|
24 |
-
|
25 |
-
|
26 |
-
@router.post("/reset", response_model=ResetResponse, status_code=status.HTTP_200_OK)
|
27 |
-
async def reset_endpoint(payload: ResetRequest) -> ResetResponse:
|
28 |
-
removed = reset_history(payload.user, payload.session)
|
29 |
-
return ResetResponse(removed=removed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|