Niansuh commited on
Commit
b301b4c
·
verified ·
1 Parent(s): 86b46ef

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -18
main.py CHANGED
@@ -352,26 +352,27 @@ async def chat_completions(request: ChatRequest, req: Request, api_key: str = De
352
  "id": f"chatcmpl-{uuid.uuid4()}",
353
  "object": "chat.logger.info(f"Completed response generation for API key: {api_key} | IP: {client_ip}")"
354
  return {
355
- "id": f"chatcmpl-{uuid.uuid4()}",
356
- "object": "chat.completion",
357
- "created": int(datetime.now().timestamp()),
358
- "model": request.model,
359
- "choices": [
360
- {
361
- "message": {
362
- "role": "assistant",
363
- "content": response_content
364
- },
365
- "finish_reason": "stop",
366
- "index": 0
367
- }
368
- ],
369
- "usage": {
370
- "prompt_tokens": sum(len(msg.content.split()) for msg in request.messages),
371
- "completion_tokens": len(response_content.split()),
372
- "total_tokens": sum(len(msg.content.split()) for msg in request.messages) + len(response_content.split())
373
  },
 
 
374
  }
 
 
 
 
 
 
 
 
375
  except ModelNotWorkingException as e:
376
  logger.warning(f"Model not working: {e} | IP: {client_ip}")
377
  raise HTTPException(status_code=503, detail=str(e))
 
352
  "id": f"chatcmpl-{uuid.uuid4()}",
353
  "object": "chat.logger.info(f"Completed response generation for API key: {api_key} | IP: {client_ip}")"
354
  return {
355
+ "id": f"chatcmpl-{uuid.uuid4()}",
356
+ "object": "chat.completion",
357
+ "created": int(datetime.now().timestamp()),
358
+ "model": request.model,
359
+ "choices": [
360
+ {
361
+ "message": {
362
+ "role": "assistant",
363
+ "content": response_content
 
 
 
 
 
 
 
 
 
364
  },
365
+ "finish_reason": "stop",
366
+ "index": 0
367
  }
368
+ ],
369
+ "usage": {
370
+ "prompt_tokens": sum(len(msg.content.split()) for msg in request.messages),
371
+ "completion_tokens": len(response_content.split()),
372
+ "total_tokens": sum(len(msg.content.split()) for msg in request.messages) + len(response_content.split())
373
+ }
374
+ } # This closing curly brace was missing
375
+
376
  except ModelNotWorkingException as e:
377
  logger.warning(f"Model not working: {e} | IP: {client_ip}")
378
  raise HTTPException(status_code=503, detail=str(e))