Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vllm_router/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
initialize_service_discovery,
)
from vllm_router.services.batch_service import initialize_batch_processor
from vllm_router.services.callbacks_service.callbacks import initialize_custom_callbacks
from vllm_router.services.callbacks_service.callbacks import configure_custom_callbacks
from vllm_router.services.files_service import initialize_storage
from vllm_router.services.request_service.rewriter import (
get_request_rewriter,
Expand Down Expand Up @@ -195,7 +195,7 @@ def initialize_all(app: FastAPI, args):
)

if args.callbacks:
initialize_custom_callbacks(args.callbacks, app)
configure_custom_callbacks(args.callbacks, app)

initialize_routing_logic(
args.routing_logic,
Expand Down
11 changes: 11 additions & 0 deletions src/vllm_router/dynamic_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ServiceDiscoveryType,
reconfigure_service_discovery,
)
from vllm_router.services.callbacks_service.callbacks import configure_custom_callbacks
from vllm_router.utils import (
SingletonMeta,
parse_comma_separated_args,
Expand Down Expand Up @@ -223,6 +224,15 @@ def reconfigure_stats(self, config: DynamicRouterConfig):
# TODO (ApostaC): Implement reconfigure_stats
pass

def reconfigure_callbacks(self, config: DynamicRouterConfig):
"""
Reconfigures the router with the given config.
"""
if config.callbacks:
configure_custom_callbacks(config.callbacks, self.app)
else:
self.app.state.callbacks = None

def reconfigure_all(self, config: DynamicRouterConfig):
"""
Reconfigures the router with the given config.
Expand All @@ -231,6 +241,7 @@ def reconfigure_all(self, config: DynamicRouterConfig):
self.reconfigure_routing_logic(config)
self.reconfigure_batch_api(config)
self.reconfigure_stats(config)
self.reconfigure_callbacks(config)

def _sleep_or_break(self, check_interval: float = 1):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/vllm_router/services/callbacks_service/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger = init_logger(__name__)


def initialize_custom_callbacks(callbacks_file_location: str, app: FastAPI):
def configure_custom_callbacks(callbacks_file_location: str, app: FastAPI):
# Split the path by dots to separate module from instance
parts = callbacks_file_location.split(".")

Expand Down
4 changes: 2 additions & 2 deletions src/vllm_router/services/request_service/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def process_request(
await store_in_semantic_cache(
endpoint=endpoint, method=request.method, body=body, chunk=cache_chunk
)
if background_tasks and hasattr(request.app.state, "callbacks"):
if background_tasks and getattr(request.app.state, "callbacks", None):
background_tasks.add_task(
request.app.state.callbacks.post_request, request, full_response
)
Expand Down Expand Up @@ -170,7 +170,7 @@ async def route_general_request(
else:
request_endpoint = None

if hasattr(request.app.state, "callbacks") and (
if getattr(request.app.state, "callbacks", None) and (
response_overwrite := request.app.state.callbacks.pre_request(
request, request_body, request_json
)
Expand Down