From 641b44339126981ff1053e3f7efb1b9657b489a1 Mon Sep 17 00:00:00 2001 From: Chill Date: Mon, 24 Apr 2023 15:22:48 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#I6Y10K=20[app=5Fchatgpt]=E5=8F=91?= =?UTF-8?q?=E9=97=AE=E6=97=B6=E5=A2=9E=E5=8A=A0token=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_chatgpt/models/mail_channel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app_chatgpt/models/mail_channel.py b/app_chatgpt/models/mail_channel.py index 6c6da226..e16cd950 100644 --- a/app_chatgpt/models/mail_channel.py +++ b/app_chatgpt/models/mail_channel.py @@ -197,6 +197,9 @@ class Channel(models.Model): if c_history: messages += c_history messages.append({"role": "user", "content": msg}) + msg_len = sum(len(str(m)) for m in messages) + if msg_len * 2 >= ai.max_tokens * 0.6: + messages = [{"role": "user", "content": msg}] if sync_config == 'sync': self.get_ai_response(ai, messages, channel, user_id, message) else: