File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Original file line number Diff line number Diff line change 12
12
from anyio .streams .memory import MemoryObjectSendStream
13
13
from starlette .concurrency import run_in_threadpool , iterate_in_threadpool
14
14
from fastapi import Depends , FastAPI , APIRouter , Request , Response
15
+ from fastapi .middleware import Middleware
15
16
from fastapi .middleware .cors import CORSMiddleware
16
17
from fastapi .responses import JSONResponse
17
18
from fastapi .routing import APIRoute
18
19
from pydantic import BaseModel , Field
19
20
from pydantic_settings import BaseSettings
20
21
from sse_starlette .sse import EventSourceResponse
22
+ from starlette_context import plugins
23
+ from starlette_context .middleware import RawContextMiddleware
21
24
22
25
import numpy as np
23
26
import numpy .typing as npt
@@ -306,7 +309,17 @@ async def custom_route_handler(request: Request) -> Response:
306
309
def create_app (settings : Optional [Settings ] = None ):
307
310
if settings is None :
308
311
settings = Settings ()
312
+
313
+ middleware = [
314
+ Middleware (
315
+ RawContextMiddleware ,
316
+ plugins = (
317
+ plugins .RequestIdPlugin (),
318
+ )
319
+ )
320
+ ]
309
321
app = FastAPI (
322
+ middleware = middleware ,
310
323
title = "🦙 llama.cpp Python API" ,
311
324
version = "0.0.1" ,
312
325
)
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ server = [
32
32
" fastapi>=0.100.0" ,
33
33
" pydantic-settings>=2.0.1" ,
34
34
" sse-starlette>=1.6.1" ,
35
+ " starlette-context>=0.3.6,<0.4"
35
36
]
36
37
test = [
37
38
" pytest>=7.4.0" ,
You can’t perform that action at this time.
0 commit comments