MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / build_backend_url

Function build_backend_url

crates/openshell-router/src/backend.rs:811–832  ·  view source on GitHub ↗
(endpoint: &str, path: &str)

Source from the content-addressed store, hash-verified

809}
810
811fn build_backend_url(endpoint: &str, path: &str) -> String {
812 let base = endpoint.trim_end_matches('/');
813 // Strip the /v1 prefix from the request path when the base URL's path
814 // component has /v1 as its first segment (e.g. openai/nvidia: "/v1",
815 // deepinfra: "/v1/openai") or its final segment (e.g. groq:
816 // "/openai/v1"). This covers all known provider shapes while preserving
817 // the full path for proxy endpoints where /v1 is buried in the middle
818 // (e.g. "https://proxy.example/api/v1/openai" → path "/api/v1/openai",
819 // neither first nor last segment).
820 let base_path_has_v1_edge_segment = base
821 .find("://")
822 .and_then(|i| base[i + 3..].find('/').map(|j| i + 3 + j))
823 .is_some_and(|path_start| {
824 let base_path = &base[path_start..];
825 base_path.starts_with("/v1/") || base_path.ends_with("/v1")
826 });
827 if base_path_has_v1_edge_segment && (path == "/v1" || path.starts_with("/v1/")) {
828 return format!("{base}{}", &path[3..]);
829 }
830
831 format!("{base}{path}")
832}
833
834/// Check whether a route targets an AWS Bedrock `InvokeModel` endpoint.
835///

Callers 1

build_provider_urlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected