From fba399b2b5f286bbf59ac69d4ac690220d136b95 Mon Sep 17 00:00:00 2001 From: LanQian <5499636+LanQian528@users.noreply.github.com> Date: Wed, 22 May 2024 14:48:04 +0800 Subject: [PATCH] fix bugs --- chat2api.py | 4 ++++ chatgpt/ChatService.py | 2 ++ 2 files changed, 6 insertions(+) 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