Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
from fastapi import FastAPI, HTTPException, Request
|
@@ -109,14 +110,15 @@ async def get_models():
|
|
109 |
async def fetch_models():
|
110 |
return await get_models()
|
111 |
|
112 |
-
@app.post("/chat/completions")
|
113 |
async def get_completion(payload: Payload, request: Request):
|
114 |
# Use the correct endpoint depending on the model type (no authentication now π)
|
115 |
endpoint = secret_api_endpoint_2 if payload.model in alternate_models else secret_api_endpoint
|
116 |
-
|
117 |
# Use the payload directly as it includes stream and other user data
|
118 |
payload_dict = payload.dict()
|
119 |
-
|
|
|
120 |
async def stream_generator(payload_dict):
|
121 |
async with httpx.AsyncClient() as client:
|
122 |
try:
|
@@ -132,8 +134,7 @@ async def get_completion(payload: Payload, request: Request):
|
|
132 |
except Exception as e:
|
133 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {e}")
|
134 |
|
135 |
-
return StreamingResponse(stream_generator(
|
136 |
-
|
137 |
@app.on_event("startup")
|
138 |
async def startup_event():
|
139 |
print("API endpoints:")
|
|
|
1 |
+
|
2 |
import os
|
3 |
from dotenv import load_dotenv
|
4 |
from fastapi import FastAPI, HTTPException, Request
|
|
|
110 |
async def fetch_models():
|
111 |
return await get_models()
|
112 |
|
113 |
+
@app.post(["/chat/completions", "/v1/chat/completions"])
|
114 |
async def get_completion(payload: Payload, request: Request):
|
115 |
# Use the correct endpoint depending on the model type (no authentication now π)
|
116 |
endpoint = secret_api_endpoint_2 if payload.model in alternate_models else secret_api_endpoint
|
117 |
+
|
118 |
# Use the payload directly as it includes stream and other user data
|
119 |
payload_dict = payload.dict()
|
120 |
+
print(payload_dict) # coz i m curious af heheheh :)
|
121 |
+
#data is kept to me only so dont worry
|
122 |
async def stream_generator(payload_dict):
|
123 |
async with httpx.AsyncClient() as client:
|
124 |
try:
|
|
|
134 |
except Exception as e:
|
135 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {e}")
|
136 |
|
137 |
+
return StreamingResponse(stream_generator(openai_payload), media_type="application/json")
|
|
|
138 |
@app.on_event("startup")
|
139 |
async def startup_event():
|
140 |
print("API endpoints:")
|