Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da9df78

Browse filesBrowse files
Add X-Request-ID request header for mirroring custom IDs. (abetlen#703)
1 parent 1372e4f commit da9df78
Copy full SHA for da9df78

File tree

Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed

‎llama_cpp/server/app.py

Copy file name to clipboardExpand all lines: llama_cpp/server/app.py
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
from anyio.streams.memory import MemoryObjectSendStream
1313
from starlette.concurrency import run_in_threadpool, iterate_in_threadpool
1414
from fastapi import Depends, FastAPI, APIRouter, Request, Response
15+
from fastapi.middleware import Middleware
1516
from fastapi.middleware.cors import CORSMiddleware
1617
from fastapi.responses import JSONResponse
1718
from fastapi.routing import APIRoute
1819
from pydantic import BaseModel, Field
1920
from pydantic_settings import BaseSettings
2021
from sse_starlette.sse import EventSourceResponse
22+
from starlette_context import plugins
23+
from starlette_context.middleware import RawContextMiddleware
2124

2225
import numpy as np
2326
import numpy.typing as npt
@@ -306,7 +309,17 @@ async def custom_route_handler(request: Request) -> Response:
306309
def create_app(settings: Optional[Settings] = None):
307310
if settings is None:
308311
settings = Settings()
312+
313+
middleware = [
314+
Middleware(
315+
RawContextMiddleware,
316+
plugins=(
317+
plugins.RequestIdPlugin(),
318+
)
319+
)
320+
]
309321
app = FastAPI(
322+
middleware=middleware,
310323
title="🦙 llama.cpp Python API",
311324
version="0.0.1",
312325
)

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ server = [
3232
"fastapi>=0.100.0",
3333
"pydantic-settings>=2.0.1",
3434
"sse-starlette>=1.6.1",
35+
"starlette-context>=0.3.6,<0.4"
3536
]
3637
test = [
3738
"pytest>=7.4.0",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.