mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-08-26 16:40:40 +03:00
add chat endpoint
This commit is contained in:
parent
c8ff69efa5
commit
849f02cf54
19
app/api/ml.py
Normal file
19
app/api/ml.py
Normal 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")
|
@ -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.shakespeare import router as shakespeare_router
|
||||||
from app.api.stuff import router as stuff_router
|
from app.api.stuff import router as stuff_router
|
||||||
from app.api.user import router as user_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.config import settings as global_settings
|
||||||
from app.database import engine
|
from app.database import engine
|
||||||
from app.redis import get_redis
|
from app.redis import get_redis
|
||||||
@ -51,6 +52,7 @@ app.include_router(stuff_router)
|
|||||||
app.include_router(nonsense_router)
|
app.include_router(nonsense_router)
|
||||||
app.include_router(shakespeare_router)
|
app.include_router(shakespeare_router)
|
||||||
app.include_router(user_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"])
|
app.include_router(health_router, prefix="/v1/public/health", tags=["Health, Public"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user