@@ -32,7 +32,7 @@ class ModelDeploymentBaseEndpoint(ExtendedEnum):
32
32
"""Supported base endpoints for model deployments."""
33
33
34
34
PREDICT = "predict"
35
- PREDICT_WITH_RESPONSE_STREAM = "predictwithresponsestream "
35
+ PREDICT_WITH_RESPONSE_STREAM = "predictWithResponseStream "
36
36
37
37
38
38
class AquaOpenAIMixin :
@@ -51,9 +51,9 @@ def _patch_route(self, original_path: str) -> str:
51
51
Returns:
52
52
str: The normalized OpenAI-compatible route path (e.g., '/v1/chat/completions').
53
53
"""
54
- normalized_path = original_path .lower (). rstrip ("/" )
54
+ normalized_path = original_path .rstrip ("/" )
55
55
56
- match = re .search (r"/predict(withresponsestream )?" , normalized_path )
56
+ match = re .search (r"/predict(WithResponseStream )?" , normalized_path )
57
57
if not match :
58
58
logger .debug ("Route header cannot be resolved from path: %s" , original_path )
59
59
return ""
@@ -71,7 +71,7 @@ def _patch_route(self, original_path: str) -> str:
71
71
"Route suffix does not start with a version prefix (e.g., '/v1'). "
72
72
"This may lead to compatibility issues with OpenAI-style endpoints. "
73
73
"Consider updating the URL to include a version prefix, "
74
- "such as '/predict/v1' or '/predictwithresponsestream /v1'."
74
+ "such as '/predict/v1' or '/predictWithResponseStream /v1'."
75
75
)
76
76
# route_suffix = f"v1/{route_suffix}"
77
77
@@ -124,13 +124,13 @@ def _patch_headers(self, request: httpx.Request) -> None:
124
124
125
125
def _patch_url (self ) -> httpx .URL :
126
126
"""
127
- Strips any suffixes from the base URL to retain only the `/predict` or `/predictwithresponsestream ` path.
127
+ Strips any suffixes from the base URL to retain only the `/predict` or `/predictWithResponseStream ` path.
128
128
129
129
Returns:
130
130
httpx.URL: The normalized base URL with the correct model deployment path.
131
131
"""
132
- base_path = f"{ self .base_url .path .lower (). rstrip ('/' )} /"
133
- match = re .search (r"/predict(withresponsestream )?/" , base_path )
132
+ base_path = f"{ self .base_url .path .rstrip ('/' )} /"
133
+ match = re .search (r"/predict(WithResponseStream )?/" , base_path )
134
134
if match :
135
135
trimmed = base_path [: match .end () - 1 ]
136
136
return self .base_url .copy_with (path = trimmed )
@@ -144,7 +144,7 @@ def _prepare_request_common(self, request: httpx.Request) -> None:
144
144
145
145
This includes:
146
146
- Patching headers with streaming and routing info.
147
- - Normalizing the URL path to include only `/predict` or `/predictwithresponsestream `.
147
+ - Normalizing the URL path to include only `/predict` or `/predictWithResponseStream `.
148
148
149
149
Args:
150
150
request (httpx.Request): The outgoing HTTPX request.
@@ -176,6 +176,7 @@ def __init__(
176
176
http_client : Optional [httpx .Client ] = None ,
177
177
http_client_kwargs : Optional [Dict [str , Any ]] = None ,
178
178
_strict_response_validation : bool = False ,
179
+ patch_headers : bool = False ,
179
180
** kwargs : Any ,
180
181
) -> None :
181
182
"""
@@ -196,6 +197,7 @@ def __init__(
196
197
http_client (httpx.Client, optional): Custom HTTP client; if not provided, one will be auto-created.
197
198
http_client_kwargs (dict[str, Any], optional): Extra kwargs for auto-creating the HTTP client.
198
199
_strict_response_validation (bool, optional): Enable strict response validation.
200
+ patch_headers (bool, optional): If True, redirects the requests by modifying the headers.
199
201
**kwargs: Additional keyword arguments passed to the parent __init__.
200
202
"""
201
203
if http_client is None :
@@ -207,6 +209,8 @@ def __init__(
207
209
logger .debug ("API key not provided; using default placeholder for OCI." )
208
210
api_key = "OCI"
209
211
212
+ self .patch_headers = patch_headers
213
+
210
214
super ().__init__ (
211
215
api_key = api_key ,
212
216
organization = organization ,
@@ -229,7 +233,8 @@ def _prepare_request(self, request: httpx.Request) -> None:
229
233
Args:
230
234
request (httpx.Request): The outgoing HTTP request.
231
235
"""
232
- self ._prepare_request_common (request )
236
+ if self .patch_headers :
237
+ self ._prepare_request_common (request )
233
238
234
239
235
240
class AsyncOpenAI (openai .AsyncOpenAI , AquaOpenAIMixin ):
@@ -248,6 +253,7 @@ def __init__(
248
253
http_client : Optional [httpx .Client ] = None ,
249
254
http_client_kwargs : Optional [Dict [str , Any ]] = None ,
250
255
_strict_response_validation : bool = False ,
256
+ patch_headers : bool = False ,
251
257
** kwargs : Any ,
252
258
) -> None :
253
259
"""
@@ -269,6 +275,7 @@ def __init__(
269
275
http_client (httpx.AsyncClient, optional): Custom asynchronous HTTP client; if not provided, one will be auto-created.
270
276
http_client_kwargs (dict[str, Any], optional): Extra kwargs for auto-creating the HTTP client.
271
277
_strict_response_validation (bool, optional): Enable strict response validation.
278
+ patch_headers (bool, optional): If True, redirects the requests by modifying the headers.
272
279
**kwargs: Additional keyword arguments passed to the parent __init__.
273
280
"""
274
281
if http_client is None :
@@ -280,6 +287,8 @@ def __init__(
280
287
logger .debug ("API key not provided; using default placeholder for OCI." )
281
288
api_key = "OCI"
282
289
290
+ self .patch_headers = patch_headers
291
+
283
292
super ().__init__ (
284
293
api_key = api_key ,
285
294
organization = organization ,
@@ -302,4 +311,5 @@ async def _prepare_request(self, request: httpx.Request) -> None:
302
311
Args:
303
312
request (httpx.Request): The outgoing HTTP request.
304
313
"""
305
- self ._prepare_request_common (request )
314
+ if self .patch_headers :
315
+ self ._prepare_request_common (request )
0 commit comments