Spaces:
Runtime error
Runtime error
Eric Michael Martinez
commited on
Commit
•
ea6f2ee
1
Parent(s):
975a3c1
update
Browse files- 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"
|
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 |
-
|
353 |
-
|
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 |
-
|
375 |
-
|
376 |
-
):
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
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 |
-
|
405 |
-
|
406 |
-
):
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
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")
|