@@ -60,6 +60,8 @@ class OpenAIHTTPBackend(Backend):
60
60
If not provided, the default timeout provided from settings is used.
61
61
:param http2: If True, uses HTTP/2 for requests to the OpenAI server.
62
62
Defaults to True.
63
+ :param follow_redirects: If True, the HTTP client will follow redirect responses.
64
+ If not provided, the default value from settings is used.
63
65
:param max_output_tokens: The maximum number of tokens to request for completions.
64
66
If not provided, the default maximum tokens provided from settings is used.
65
67
:param extra_query: Query parameters to include in requests to the OpenAI server.
@@ -78,6 +80,7 @@ def __init__(
78
80
project : Optional [str ] = None ,
79
81
timeout : Optional [float ] = None ,
80
82
http2 : Optional [bool ] = True ,
83
+ follow_redirects : Optional [bool ] = None ,
81
84
max_output_tokens : Optional [int ] = None ,
82
85
extra_query : Optional [Union [dict [str , str ], dict [str , dict [str , str ]]]] = None ,
83
86
):
@@ -105,6 +108,11 @@ def __init__(
105
108
self .project = project or settings .openai .project
106
109
self .timeout = timeout if timeout is not None else settings .request_timeout
107
110
self .http2 = http2 if http2 is not None else settings .request_http2
111
+ self .follow_redirects = (
112
+ follow_redirects
113
+ if follow_redirects is not None
114
+ else settings .request_follow_redirects
115
+ )
108
116
self .max_output_tokens = (
109
117
max_output_tokens
110
118
if max_output_tokens is not None
@@ -138,6 +146,7 @@ def info(self) -> dict[str, Any]:
138
146
"max_output_tokens" : self .max_output_tokens ,
139
147
"timeout" : self .timeout ,
140
148
"http2" : self .http2 ,
149
+ "follow_redirects" : self .follow_redirects ,
141
150
"authorization" : bool (self .authorization ),
142
151
"organization" : self .organization ,
143
152
"project" : self .project ,
@@ -346,7 +355,11 @@ def _get_async_client(self) -> httpx.AsyncClient:
346
355
:return: The async HTTP client.
347
356
"""
348
357
if self ._async_client is None :
349
- client = httpx .AsyncClient (http2 = self .http2 , timeout = self .timeout )
358
+ client = httpx .AsyncClient (
359
+ http2 = self .http2 ,
360
+ timeout = self .timeout ,
361
+ follow_redirects = self .follow_redirects ,
362
+ )
350
363
self ._async_client = client
351
364
else :
352
365
client = self ._async_client
@@ -492,12 +505,14 @@ async def _iterative_completions_request(
492
505
raise ValueError (f"Unsupported type: { type_ } " )
493
506
494
507
logger .info (
495
- "{} making request: {} to target: {} using http2: {} for "
496
- "timeout: {} with headers: {} and params: {} and payload: {}" ,
508
+ "{} making request: {} to target: {} using http2: {} following "
509
+ "redirects: {} for timeout: {} with headers: {} and params: {} and " ,
510
+ "payload: {}" ,
497
511
self .__class__ .__name__ ,
498
512
request_id ,
499
513
target ,
500
514
self .http2 ,
515
+ self .follow_redirects ,
501
516
self .timeout ,
502
517
headers ,
503
518
params ,
@@ -591,6 +606,7 @@ async def _iterative_completions_request(
591
606
payload = payload ,
592
607
timeout = self .timeout ,
593
608
http2 = self .http2 ,
609
+ follow_redirects = self .follow_redirects ,
594
610
),
595
611
start_time = start_time ,
596
612
end_time = iter_time ,
0 commit comments