@@ -49,6 +49,8 @@ class OpenAIHTTPBackend(Backend):
49
49
If not provided, the default timeout provided from settings is used.
50
50
:param http2: If True, uses HTTP/2 for requests to the OpenAI server.
51
51
Defaults to True.
52
+ :param follow_redirects: If True, the HTTP client will follow redirect responses.
53
+ If not provided, the default value from settings is used.
52
54
:param max_output_tokens: The maximum number of tokens to request for completions.
53
55
If not provided, the default maximum tokens provided from settings is used.
54
56
"""
@@ -62,6 +64,7 @@ def __init__(
62
64
project : Optional [str ] = None ,
63
65
timeout : Optional [float ] = None ,
64
66
http2 : Optional [bool ] = True ,
67
+ follow_redirects : Optional [bool ] = None ,
65
68
max_output_tokens : Optional [int ] = None ,
66
69
):
67
70
super ().__init__ (type_ = "openai_http" )
@@ -88,6 +91,11 @@ def __init__(
88
91
self .project = project or settings .openai .project
89
92
self .timeout = timeout if timeout is not None else settings .request_timeout
90
93
self .http2 = http2 if http2 is not None else settings .request_http2
94
+ self .follow_redirects = (
95
+ follow_redirects
96
+ if follow_redirects is not None
97
+ else settings .request_follow_redirects
98
+ )
91
99
self .max_output_tokens = (
92
100
max_output_tokens
93
101
if max_output_tokens is not None
@@ -120,6 +128,7 @@ def info(self) -> dict[str, Any]:
120
128
"max_output_tokens" : self .max_output_tokens ,
121
129
"timeout" : self .timeout ,
122
130
"http2" : self .http2 ,
131
+ "follow_redirects" : self .follow_redirects ,
123
132
"authorization" : bool (self .authorization ),
124
133
"organization" : self .organization ,
125
134
"project" : self .project ,
@@ -319,7 +328,11 @@ def _get_async_client(self) -> httpx.AsyncClient:
319
328
:return: The async HTTP client.
320
329
"""
321
330
if self ._async_client is None :
322
- client = httpx .AsyncClient (http2 = self .http2 , timeout = self .timeout )
331
+ client = httpx .AsyncClient (
332
+ http2 = self .http2 ,
333
+ timeout = self .timeout ,
334
+ follow_redirects = self .follow_redirects ,
335
+ )
323
336
self ._async_client = client
324
337
else :
325
338
client = self ._async_client
@@ -449,12 +462,13 @@ async def _iterative_completions_request(
449
462
raise ValueError (f"Unsupported type: { type_ } " )
450
463
451
464
logger .info (
452
- "{} making request: {} to target: {} using http2: {} for "
453
- "timeout: {} with headers: {} and payload: {}" ,
465
+ "{} making request: {} to target: {} using http2: {} following "
466
+ "redirects: {} for timeout: {} with headers: {} and payload: {}" ,
454
467
self .__class__ .__name__ ,
455
468
request_id ,
456
469
target ,
457
470
self .http2 ,
471
+ self .follow_redirects ,
458
472
self .timeout ,
459
473
headers ,
460
474
payload ,
@@ -544,6 +558,7 @@ async def _iterative_completions_request(
544
558
payload = payload ,
545
559
timeout = self .timeout ,
546
560
http2 = self .http2 ,
561
+ follow_redirects = self .follow_redirects ,
547
562
),
548
563
start_time = start_time ,
549
564
end_time = iter_time ,
0 commit comments