ParthSadaria commited on
Commit
a0270ea
Β·
verified Β·
1 Parent(s): 96a881b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -5
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(["/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:
@@ -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:")