add chat endpoint

This commit is contained in:
grillazz 2025-05-03 08:44:15 +02:00
parent c8ff69efa5
commit 849f02cf54
2 changed files with 21 additions and 0 deletions

19
app/api/ml.py Normal file
View File

@ -0,0 +1,19 @@
from typing import Annotated
from fastapi import APIRouter, Depends, Form
from fastapi.responses import StreamingResponse
from app.services.llm import get_llm_service
from app.utils.logging import AppLogger
logger = AppLogger().get_logger()
router = APIRouter()
@router.post('/chat/')
async def chat(
prompt: Annotated[str, Form()],
llm_service = Depends(get_llm_service)
):
return StreamingResponse(llm_service.stream_chat(prompt), media_type="text/plain")

View File

@ -11,6 +11,7 @@ from app.api.nonsense import router as nonsense_router
from app.api.shakespeare import router as shakespeare_router
from app.api.stuff import router as stuff_router
from app.api.user import router as user_router
from app.api.ml import router as ml_router
from app.config import settings as global_settings
from app.database import engine
from app.redis import get_redis
@ -51,6 +52,7 @@ app.include_router(stuff_router)
app.include_router(nonsense_router)
app.include_router(shakespeare_router)
app.include_router(user_router)
app.include_router(ml_router, prefix="/v1/ml", tags=["ML"])
app.include_router(health_router, prefix="/v1/public/health", tags=["Health, Public"])