From b0b696cb4ff0ac5277bc2f580790d594d48b9712 Mon Sep 17 00:00:00 2001 From: Hardik Shah Date: Thu, 13 Feb 2025 18:18:23 -0800 Subject: [PATCH] fix: regex pattern matching to support :path suffix in the routes (#1089) This PR fixes client sdk test failure -- https://github.com/meta-llama/llama-stack-ops/actions/runs/13320153693/job/37203122048 by updating the regex matching pattern to also consider `:path` in the routes --- llama_stack/distribution/library_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/llama_stack/distribution/library_client.py b/llama_stack/distribution/library_client.py index 55a15e5e9..a7ef753b9 100644 --- a/llama_stack/distribution/library_client.py +++ b/llama_stack/distribution/library_client.py @@ -231,7 +231,13 @@ class AsyncLlamaStackAsLibraryClient(AsyncLlamaStackClient): def _convert_path_to_regex(path: str) -> str: # Convert {param} to named capture groups - pattern = re.sub(r"{(\w+)}", r"(?P<\1>[^/]+)", path) + # handle {param:path} as well which allows for forward slashes in the param value + pattern = re.sub( + r"{(\w+)(?::path)?}", + lambda m: f"(?P<{m.group(1)}>{'[^/]+' if not m.group(0).endswith(':path') else '.+'})", + path, + ) + return f"^{pattern}$" for api, api_endpoints in endpoints.items():