diff --git a/chat2api.py b/chat2api.py index e7c5e7f..e1cfad3 100644 --- a/chat2api.py +++ b/chat2api.py @@ -38,6 +38,10 @@ async def to_send_conversation(request_data, access_token): except HTTPException as e: await chat_service.close_client() raise HTTPException(status_code=e.status_code, detail=e.detail) + except Exception as e: + await chat_service.close_client() + logger.error(f"Server error, {str(e)}") + raise HTTPException(status_code=500, detail="Server error") @app.post(f"/{api_prefix}/v1/chat/completions" if api_prefix else "/v1/chat/completions") diff --git a/chatgpt/ChatService.py b/chatgpt/ChatService.py index 3214026..1bd75fa 100644 --- a/chatgpt/ChatService.py +++ b/chatgpt/ChatService.py @@ -48,6 +48,8 @@ class ChatService: self.api_messages = self.data.get("messages", []) self.prompt_tokens = 0 self.max_tokens = self.data.get("max_tokens", 2147483647) + if not isinstance(self.max_tokens, int): + self.max_tokens = 2147483647 self.chat_headers = None self.chat_request = None