Skip to content

Commit

Permalink
(feat) pass through llm endpoints - add PATCH support (vertex conte…
Browse files Browse the repository at this point in the history
…xt caching requires for update ops) (#6924)

* add PATCH for pass through endpoints

* test_pass_through_routes_support_all_methods
  • Loading branch information
ishaan-jaff authored Nov 26, 2024
1 parent 8673f25 commit 8fd3bf3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_request_copy(request: Request):

@router.api_route(
"/gemini/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Google AI Studio Pass-through", "pass-through"],
)
async def gemini_proxy_route(
Expand Down Expand Up @@ -122,7 +122,7 @@ async def gemini_proxy_route(

@router.api_route(
"/cohere/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Cohere Pass-through", "pass-through"],
)
async def cohere_proxy_route(
Expand Down Expand Up @@ -171,7 +171,7 @@ async def cohere_proxy_route(

@router.api_route(
"/anthropic/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Anthropic Pass-through", "pass-through"],
)
async def anthropic_proxy_route(
Expand Down Expand Up @@ -224,7 +224,7 @@ async def anthropic_proxy_route(

@router.api_route(
"/bedrock/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Bedrock Pass-through", "pass-through"],
)
async def bedrock_proxy_route(
Expand Down Expand Up @@ -305,7 +305,7 @@ async def bedrock_proxy_route(

@router.api_route(
"/azure/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Azure Pass-through", "pass-through"],
)
async def azure_proxy_route(
Expand Down
2 changes: 1 addition & 1 deletion litellm/proxy/vertex_ai_endpoints/langfuse_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_request_copy(request: Request):

@router.api_route(
"/langfuse/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Langfuse Pass-through", "pass-through"],
)
async def langfuse_proxy_route(
Expand Down
6 changes: 4 additions & 2 deletions litellm/proxy/vertex_ai_endpoints/vertex_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ def construct_target_url(

@router.api_route(
"/vertex-ai/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE"],
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Vertex AI Pass-through", "pass-through"],
include_in_schema=False,
)
@router.api_route(
"/vertex_ai/{endpoint:path}", methods=["GET", "POST", "PUT", "DELETE"], tags=["Vertex AI Pass-through", "pass-through"]
"/vertex_ai/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Vertex AI Pass-through", "pass-through"],
)
async def vertex_proxy_route(
endpoint: str,
Expand Down
35 changes: 35 additions & 0 deletions tests/pass_through_unit_tests/test_pass_through_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
) # Adds the parent directory to the system path

import fastapi
from fastapi import FastAPI
from fastapi.routing import APIRoute
import httpx
import pytest
import litellm
Expand Down Expand Up @@ -320,3 +322,36 @@ async def mock_aread():
assert content is not None
if isinstance(content, bytes):
assert len(content) > 0


def test_pass_through_routes_support_all_methods():
"""
Test that all pass-through routes support GET, POST, PUT, DELETE, PATCH methods
"""
# Import the routers
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
router as llm_router,
)
from litellm.proxy.vertex_ai_endpoints.vertex_endpoints import (
router as vertex_router,
)

# Expected HTTP methods
expected_methods = {"GET", "POST", "PUT", "DELETE", "PATCH"}

# Function to check routes in a router
def check_router_methods(router):
for route in router.routes:
if isinstance(route, APIRoute):
# Get path and methods for this route
path = route.path
methods = set(route.methods)
print("supported methods for route", path, "are", methods)
# Assert all expected methods are supported
assert (
methods == expected_methods
), f"Route {path} does not support all methods. Supported: {methods}, Expected: {expected_methods}"

# Check both routers
check_router_methods(llm_router)
check_router_methods(vertex_router)

0 comments on commit 8fd3bf3

Please sign in to comment.