ParthSadaria commited on
Commit
9f6a21e
·
verified ·
1 Parent(s): 72b5133

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -14
main.py CHANGED
@@ -143,19 +143,6 @@ async def get_models():
143
  async def fetch_models():
144
  return await get_models()
145
 
146
- def load_model_ids(json_file_path):
147
- try:
148
- with open(json_file_path, 'r') as f:
149
- models_data = json.load(f)
150
- # Extract 'id' from each model object
151
- model_ids = [model['id'] for model in models_data if 'id' in model]
152
- return model_ids
153
- except FileNotFoundError:
154
- print("Error: models.json file not found.")
155
- return []
156
- except json.JSONDecodeError:
157
- print("Error: Invalid JSON format in models.json.")
158
- return []
159
 
160
  @app.post("/chat/completions")
161
  @app.post("/v1/chat/completions")
@@ -174,11 +161,12 @@ async def get_completion(payload: Payload,request: Request):
174
 
175
  # Select the appropriate endpoint
176
  endpoint = secret_api_endpoint_2 if model_to_use in alternate_models else secret_api_endpoint
177
- current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
178
  aaip = request.client.host
179
  print(f"Time: {current_time}, {aaip}")
180
  print(payload_dict)
181
 
 
182
  async def stream_generator(payload_dict):
183
  scraper = cloudscraper.create_scraper() # Create a CloudScraper session
184
  try:
@@ -313,6 +301,20 @@ async def playground():
313
  return HTMLResponse(content=html_content)
314
  except FileNotFoundError:
315
  return HTMLResponse(content="<h1>playground.html not found</h1>", status_code=404)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  @app.on_event("startup")
317
  async def startup_event():
318
  global available_model_ids
 
143
  async def fetch_models():
144
  return await get_models()
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
  @app.post("/chat/completions")
148
  @app.post("/v1/chat/completions")
 
161
 
162
  # Select the appropriate endpoint
163
  endpoint = secret_api_endpoint_2 if model_to_use in alternate_models else secret_api_endpoint
164
+ current_time = (datetime.datetime.utcnow() + datetime.timedelta(hours=5, minutes=30)).strftime("%Y-%m-%d %I:%M:%S %p")
165
  aaip = request.client.host
166
  print(f"Time: {current_time}, {aaip}")
167
  print(payload_dict)
168
 
169
+
170
  async def stream_generator(payload_dict):
171
  scraper = cloudscraper.create_scraper() # Create a CloudScraper session
172
  try:
 
301
  return HTMLResponse(content=html_content)
302
  except FileNotFoundError:
303
  return HTMLResponse(content="<h1>playground.html not found</h1>", status_code=404)
304
+
305
+ def load_model_ids(json_file_path):
306
+ try:
307
+ with open(json_file_path, 'r') as f:
308
+ models_data = json.load(f)
309
+ # Extract 'id' from each model object
310
+ model_ids = [model['id'] for model in models_data if 'id' in model]
311
+ return model_ids
312
+ except FileNotFoundError:
313
+ print("Error: models.json file not found.")
314
+ return []
315
+ except json.JSONDecodeError:
316
+ print("Error: Invalid JSON format in models.json.")
317
+ return []
318
  @app.on_event("startup")
319
  async def startup_event():
320
  global available_model_ids