Eric Michael Martinez commited on
Commit
cc03605
·
1 Parent(s): e926e13
Files changed (2) hide show
  1. app/app.py +1 -1
  2. student_api.ipynb +30 -2
app/app.py CHANGED
@@ -247,7 +247,7 @@ async def openai_api_completions_passthrough(
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"),
 
247
 
248
  # Forward the request to the OpenAI API
249
  response = requests.post(
250
+ "https://api.openai.com/v1/completions",
251
  json=request_data,
252
  headers={
253
  "Content-Type": request_headers.get("Content-Type"),
student_api.ipynb CHANGED
@@ -201,7 +201,7 @@
201
  },
202
  {
203
  "cell_type": "code",
204
- "execution_count": 38,
205
  "id": "d2250413",
206
  "metadata": {},
207
  "outputs": [
@@ -449,6 +449,34 @@
449
  "async def authenticated_route(user: User = Depends(current_active_user)):\n",
450
  " return {\"message\": f\"Hello {user.email}!\"}\n",
451
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  "@app.post(\"/v1/chat/completions\")\n",
453
  "async def openai_api_chat_completions_passthrough(\n",
454
  " request: Request,\n",
@@ -805,7 +833,7 @@
805
  "name": "python",
806
  "nbconvert_exporter": "python",
807
  "pygments_lexer": "ipython3",
808
- "version": "3.10.8"
809
  }
810
  },
811
  "nbformat": 4,
 
201
  },
202
  {
203
  "cell_type": "code",
204
+ "execution_count": 1,
205
  "id": "d2250413",
206
  "metadata": {},
207
  "outputs": [
 
449
  "async def authenticated_route(user: User = Depends(current_active_user)):\n",
450
  " return {\"message\": f\"Hello {user.email}!\"}\n",
451
  "\n",
452
+ "@app.post(\"/v1/completions\")\n",
453
+ "async def openai_api_completions_passthrough(\n",
454
+ " request: Request,\n",
455
+ " user: User = Depends(fastapi_users.current_user()),\n",
456
+ "):\n",
457
+ " if not user:\n",
458
+ " raise HTTPException(status_code=401, detail=\"Unauthorized\")\n",
459
+ "\n",
460
+ " # Get the request data and headers\n",
461
+ " request_data = await request.json()\n",
462
+ " request_headers = request.headers\n",
463
+ " openai_api_key = os.getenv(\"OPENAI_API_KEY\")\n",
464
+ "\n",
465
+ " # Forward the request to the OpenAI API\n",
466
+ " response = requests.post(\n",
467
+ " \"https://api.openai.com/v1/completions\",\n",
468
+ " json=request_data,\n",
469
+ " headers={\n",
470
+ " \"Content-Type\": request_headers.get(\"Content-Type\"),\n",
471
+ " \"Authorization\": f\"Bearer {openai_api_key}\",\n",
472
+ " },\n",
473
+ " )\n",
474
+ " print(response)\n",
475
+ "\n",
476
+ " # Return the OpenAI API response\n",
477
+ " return response.json()\n",
478
+ "\n",
479
+ "\n",
480
  "@app.post(\"/v1/chat/completions\")\n",
481
  "async def openai_api_chat_completions_passthrough(\n",
482
  " request: Request,\n",
 
833
  "name": "python",
834
  "nbconvert_exporter": "python",
835
  "pygments_lexer": "ipython3",
836
+ "version": "3.11.3"
837
  }
838
  },
839
  "nbformat": 4,