Eric Michael Martinez commited on
Commit
ea6f2ee
1 Parent(s): 975a3c1
Files changed (1) hide show
  1. app/app.py +62 -61
app/app.py CHANGED
@@ -28,6 +28,7 @@ else:
28
  import openai
29
 
30
 
 
31
  def api_login(email, password):
32
  port = os.getenv("APP_PORT")
33
  scheme = os.getenv("APP_SCHEME")
@@ -178,7 +179,7 @@ def get_chatbot_app(additional_examples=[]):
178
  chat,
179
  additional_inputs=[
180
  gr.Dropdown(
181
- ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4"],
182
  label="Model",
183
  value="gpt-3.5-turbo",
184
  ),
@@ -349,8 +350,8 @@ async def openai_api_chat_completions_passthrough(
349
  request_headers = request.headers
350
  openai_api_key = os.getenv("OPENAI_API_KEY")
351
 
352
- # if "gpt-4" in request_data["model"]:
353
- # request_data["model"] = "gpt-3.5-turbo"
354
 
355
  # Forward the request to the OpenAI API
356
  async with AsyncClient() as client:
@@ -368,64 +369,64 @@ async def openai_api_chat_completions_passthrough(
368
  return response.json()
369
 
370
 
371
- @retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=30))
372
- @app.post("/v1/images/generations")
373
- async def openai_api_chat_completions_passthrough(
374
- request: Request,
375
- user: User = Depends(fastapi_users.current_user()),
376
- ):
377
- if not user:
378
- raise HTTPException(status_code=401, detail="Unauthorized")
379
-
380
- # Get the request data and headers
381
- request_data = await request.json()
382
- request_headers = request.headers
383
- openai_api_key = os.getenv("OPENAI_API_KEY")
384
-
385
- # Forward the request to the OpenAI API
386
- async with AsyncClient() as client:
387
- response = await client.post(
388
- "https://api.openai.com/v1/images/generations",
389
- json=request_data,
390
- headers={
391
- "Content-Type": request_headers.get("Content-Type"),
392
- "Authorization": f"Bearer {openai_api_key}",
393
- },
394
- timeout=120.0,
395
- )
396
-
397
- # Return the OpenAI API response
398
- return response.json()
399
-
400
-
401
- @retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=30))
402
- @app.post("/v1/audio/speech")
403
- async def openai_api_audio_speech_passthrough(
404
- request: Request,
405
- user: User = Depends(fastapi_users.current_user()),
406
- ):
407
- if not user:
408
- raise HTTPException(status_code=401, detail="Unauthorized")
409
-
410
- # Get the request data and headers
411
- request_data = await request.json()
412
- request_headers = request.headers
413
- openai_api_key = os.getenv("OPENAI_API_KEY")
414
-
415
- # Forward the request to the OpenAI API
416
- async with AsyncClient() as client:
417
- response = await client.post(
418
- "https://api.openai.com/v1/audio/speech",
419
- json=request_data,
420
- headers={
421
- "Content-Type": request_headers.get("Content-Type"),
422
- "Authorization": f"Bearer {openai_api_key}",
423
- },
424
- timeout=120.0,
425
- )
426
-
427
- # Return the OpenAI API response
428
- return response.json()
429
 
430
 
431
  @app.on_event("startup")
 
28
  import openai
29
 
30
 
31
+ @retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=30))
32
  def api_login(email, password):
33
  port = os.getenv("APP_PORT")
34
  scheme = os.getenv("APP_SCHEME")
 
179
  chat,
180
  additional_inputs=[
181
  gr.Dropdown(
182
+ ["gpt-3.5-turbo", "gpt-3.5-turbo-16k"],
183
  label="Model",
184
  value="gpt-3.5-turbo",
185
  ),
 
350
  request_headers = request.headers
351
  openai_api_key = os.getenv("OPENAI_API_KEY")
352
 
353
+ if "gpt-4" in request_data["model"]:
354
+ request_data["model"] = "gpt-3.5-turbo"
355
 
356
  # Forward the request to the OpenAI API
357
  async with AsyncClient() as client:
 
369
  return response.json()
370
 
371
 
372
+ # @retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=30))
373
+ # @app.post("/v1/images/generations")
374
+ # async def openai_api_chat_completions_passthrough(
375
+ # request: Request,
376
+ # user: User = Depends(fastapi_users.current_user()),
377
+ # ):
378
+ # if not user:
379
+ # raise HTTPException(status_code=401, detail="Unauthorized")
380
+
381
+ # # Get the request data and headers
382
+ # request_data = await request.json()
383
+ # request_headers = request.headers
384
+ # openai_api_key = os.getenv("OPENAI_API_KEY")
385
+
386
+ # # Forward the request to the OpenAI API
387
+ # async with AsyncClient() as client:
388
+ # response = await client.post(
389
+ # "https://api.openai.com/v1/images/generations",
390
+ # json=request_data,
391
+ # headers={
392
+ # "Content-Type": request_headers.get("Content-Type"),
393
+ # "Authorization": f"Bearer {openai_api_key}",
394
+ # },
395
+ # timeout=120.0,
396
+ # )
397
+
398
+ # # Return the OpenAI API response
399
+ # return response.json()
400
+
401
+
402
+ # @retry(stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=30))
403
+ # @app.post("/v1/audio/speech")
404
+ # async def openai_api_audio_speech_passthrough(
405
+ # request: Request,
406
+ # user: User = Depends(fastapi_users.current_user()),
407
+ # ):
408
+ # if not user:
409
+ # raise HTTPException(status_code=401, detail="Unauthorized")
410
+
411
+ # # Get the request data and headers
412
+ # request_data = await request.json()
413
+ # request_headers = request.headers
414
+ # openai_api_key = os.getenv("OPENAI_API_KEY")
415
+
416
+ # # Forward the request to the OpenAI API
417
+ # async with AsyncClient() as client:
418
+ # response = await client.post(
419
+ # "https://api.openai.com/v1/audio/speech",
420
+ # json=request_data,
421
+ # headers={
422
+ # "Content-Type": request_headers.get("Content-Type"),
423
+ # "Authorization": f"Bearer {openai_api_key}",
424
+ # },
425
+ # timeout=120.0,
426
+ # )
427
+
428
+ # # Return the OpenAI API response
429
+ # return response.json()
430
 
431
 
432
  @app.on_event("startup")