Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -110,15 +110,17 @@ async def get_models():
|
|
110 |
async def fetch_models():
|
111 |
return await get_models()
|
112 |
|
113 |
-
@app.post(
|
|
|
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)
|
121 |
-
#data is kept to me only
|
|
|
122 |
async def stream_generator(payload_dict):
|
123 |
async with httpx.AsyncClient() as client:
|
124 |
try:
|
@@ -133,8 +135,9 @@ async def get_completion(payload: Payload, request: Request):
|
|
133 |
raise HTTPException(status_code=500, detail=f"Streaming failed: {req_err}")
|
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:")
|
|
|
110 |
async def fetch_models():
|
111 |
return await get_models()
|
112 |
|
113 |
+
@app.post("/chat/completions")
|
114 |
+
@app.post("/v1/chat/completions")
|
115 |
async def get_completion(payload: Payload, request: Request):
|
116 |
# Use the correct endpoint depending on the model type (no authentication now π)
|
117 |
endpoint = secret_api_endpoint_2 if payload.model in alternate_models else secret_api_endpoint
|
118 |
+
|
119 |
# Use the payload directly as it includes stream and other user data
|
120 |
payload_dict = payload.dict()
|
121 |
+
print(payload_dict) # coz I m curious af heheheh :)
|
122 |
+
# data is kept to me only don't worry :)
|
123 |
+
|
124 |
async def stream_generator(payload_dict):
|
125 |
async with httpx.AsyncClient() as client:
|
126 |
try:
|
|
|
135 |
raise HTTPException(status_code=500, detail=f"Streaming failed: {req_err}")
|
136 |
except Exception as e:
|
137 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {e}")
|
138 |
+
|
139 |
+
return StreamingResponse(stream_generator(payload_dict), media_type="application/json")
|
140 |
|
|
|
141 |
@app.on_event("startup")
|
142 |
async def startup_event():
|
143 |
print("API endpoints:")
|