Eric Michael Martinez commited on
Commit
7483975
·
1 Parent(s): 7b70181

add timeout

Browse files
Files changed (1) hide show
  1. app/app.py +2 -11
app/app.py CHANGED
@@ -280,16 +280,6 @@ async def openai_api_completions_passthrough(
280
  request_headers = request.headers
281
  openai_api_key = os.getenv("OPENAI_API_KEY")
282
 
283
- # Forward the request to the OpenAI API
284
- response = requests.post(
285
- "https://api.openai.com/v1/completions",
286
- json=request_data,
287
- headers={
288
- "Content-Type": request_headers.get("Content-Type"),
289
- "Authorization": f"Bearer {openai_api_key}",
290
- },
291
- )
292
-
293
  # Forward the request to the OpenAI API
294
  async with AsyncClient() as client:
295
  response = await client.post(
@@ -299,6 +289,7 @@ async def openai_api_completions_passthrough(
299
  "Content-Type": request_headers.get("Content-Type"),
300
  "Authorization": f"Bearer {openai_api_key}",
301
  },
 
302
  )
303
 
304
  # Return the OpenAI API response
@@ -319,7 +310,6 @@ async def openai_api_chat_completions_passthrough(
319
  openai_api_key = os.getenv("OPENAI_API_KEY")
320
 
321
  if "gpt-4" in request_data["model"]:
322
- print("User requested gpt-4, falling back to gpt-3.5-turbo")
323
  request_data["model"] = "gpt-3.5-turbo"
324
 
325
  # Forward the request to the OpenAI API
@@ -331,6 +321,7 @@ async def openai_api_chat_completions_passthrough(
331
  "Content-Type": request_headers.get("Content-Type"),
332
  "Authorization": f"Bearer {openai_api_key}",
333
  },
 
334
  )
335
 
336
  # Return the OpenAI API response
 
280
  request_headers = request.headers
281
  openai_api_key = os.getenv("OPENAI_API_KEY")
282
 
 
 
 
 
 
 
 
 
 
 
283
  # Forward the request to the OpenAI API
284
  async with AsyncClient() as client:
285
  response = await client.post(
 
289
  "Content-Type": request_headers.get("Content-Type"),
290
  "Authorization": f"Bearer {openai_api_key}",
291
  },
292
+ timeout=120.0,
293
  )
294
 
295
  # Return the OpenAI API response
 
310
  openai_api_key = os.getenv("OPENAI_API_KEY")
311
 
312
  if "gpt-4" in request_data["model"]:
 
313
  request_data["model"] = "gpt-3.5-turbo"
314
 
315
  # Forward the request to the OpenAI API
 
321
  "Content-Type": request_headers.get("Content-Type"),
322
  "Authorization": f"Bearer {openai_api_key}",
323
  },
324
+ timeout=120.0,
325
  )
326
 
327
  # Return the OpenAI API response