Eric Michael Martinez commited on
Commit
e926e13
1 Parent(s): 8dfcc52
Files changed (1) hide show
  1. app/app.py +28 -0
app/app.py CHANGED
@@ -232,6 +232,34 @@ app.include_router(
232
  async def authenticated_route(user: User = Depends(current_active_user)):
233
  return {"message": f"Hello {user.email}!"}
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  @app.post("/v1/chat/completions")
236
  async def openai_api_chat_completions_passthrough(
237
  request: Request,
 
232
  async def authenticated_route(user: User = Depends(current_active_user)):
233
  return {"message": f"Hello {user.email}!"}
234
 
235
+ @app.post("/v1/completions")
236
+ async def openai_api_completions_passthrough(
237
+ request: Request,
238
+ user: User = Depends(fastapi_users.current_user()),
239
+ ):
240
+ if not user:
241
+ raise HTTPException(status_code=401, detail="Unauthorized")
242
+
243
+ # Get the request data and headers
244
+ request_data = await request.json()
245
+ request_headers = request.headers
246
+ openai_api_key = os.getenv("OPENAI_API_KEY")
247
+
248
+ # Forward the request to the OpenAI API
249
+ response = requests.post(
250
+ "https://api.openai.com/v1/chat/completions",
251
+ json=request_data,
252
+ headers={
253
+ "Content-Type": request_headers.get("Content-Type"),
254
+ "Authorization": f"Bearer {openai_api_key}",
255
+ },
256
+ )
257
+ print(response)
258
+
259
+ # Return the OpenAI API response
260
+ return response.json()
261
+
262
+
263
  @app.post("/v1/chat/completions")
264
  async def openai_api_chat_completions_passthrough(
265
  request: Request,