From 08981879a5b7a95a9ae41a7c1f0b276e2eabad7c Mon Sep 17 00:00:00 2001 From: ivan deng Date: Fri, 21 Apr 2023 20:55:32 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#I6XRE8=20=E3=80=90=E5=9F=BA=E6=9C=ACdone?= =?UTF-8?q?=EF=BC=8Ctodo=E8=A6=81=E5=8F=98=E6=88=90=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E3=80=91openai=E7=9A=84vpn=E5=A4=84=E7=90=86=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_chatgpt/models/ai_robot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app_chatgpt/models/ai_robot.py b/app_chatgpt/models/ai_robot.py index 43c939e4..7c737726 100644 --- a/app_chatgpt/models/ai_robot.py +++ b/app_chatgpt/models/ai_robot.py @@ -143,10 +143,16 @@ GPT-3 A set of models that can understand and generate natural language return res_post, is_ai def get_ai_post(self, res, author_id=False, answer_id=False, param={}): - if res and author_id and isinstance(res, openai.openai_object.OpenAIObject) or isinstance(res, list): + if res and author_id and isinstance(res, openai.openai_object.OpenAIObject) or isinstance(res, list) or isinstance(res, dict): # 返回是个对象,那么就是ai - usage = json.loads(json.dumps(res['usage'])) - content = json.loads(json.dumps(res['choices'][0]['message']['content'])) + if isinstance(res, dict): + # openai 格式处理 + usage = res['usage'] + content = res['choices'][0]['message']['content'] + else: + # azure 格式 + usage = json.loads(json.dumps(res['usage'])) + content = json.loads(json.dumps(res['choices'][0]['message']['content'])) data = content.replace(' .', '.').strip() answer_user = answer_id.mapped('user_ids')[:1] if usage: