diff --git a/project/main.py b/project/main.py index f282e27..8d11f8a 100644 --- a/project/main.py +++ b/project/main.py @@ -95,12 +95,14 @@ def chat_post(): else: messages.append( {"role": "user", "content": chat.request}) - - openai_resp = openai.ChatCompletion.create( - model=current_app.config['OPENAI_MODEL_NAME'], - messages=messages - ) - msg_resp = openai_resp['choices'][0]['message']['content'] + try: + openai_resp = openai.ChatCompletion.create( + model=current_app.config['OPENAI_MODEL_NAME'], + messages=messages + ) + msg_resp = openai_resp['choices'][0]['message']['content'] + except: + msg_resp = "请求错误,请尝试重发。如果持续错误,请联系管理员检查。" if msg_resp: response = {"message": msg_resp, "status": "success"} else: