From 5a986877d0474d8484328afa2700135be531fdc2 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Thu, 26 Sep 2024 13:24:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E8=BF=87=E9=95=BFopenai=E5=BA=94=E7=94=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/application/flow/workflow_manage.py | 2 ++ .../0016_alter_chatrecord_problem_text.py | 18 ++++++++++++++++++ apps/application/models/application.py | 2 +- .../serializers/application_serializers.py | 13 +++++++------ .../serializers/chat_message_serializers.py | 5 +++-- 5 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 apps/application/migrations/0016_alter_chatrecord_problem_text.py diff --git a/apps/application/flow/workflow_manage.py b/apps/application/flow/workflow_manage.py index af3e6aaa1..340baa724 100644 --- a/apps/application/flow/workflow_manage.py +++ b/apps/application/flow/workflow_manage.py @@ -7,6 +7,7 @@ @desc: """ import json +import traceback from functools import reduce from typing import List, Dict @@ -208,6 +209,7 @@ class WorkflowManage: self.params['chat_record_id'], self.answer, True , message_tokens, answer_tokens) except Exception as e: + traceback.print_exc() self.current_node.get_write_error_context(e) self.work_flow_post_handler.handler(self.params['chat_id'], self.params['chat_record_id'], self.answer, diff --git a/apps/application/migrations/0016_alter_chatrecord_problem_text.py b/apps/application/migrations/0016_alter_chatrecord_problem_text.py new file mode 100644 index 000000000..edda1e607 --- /dev/null +++ b/apps/application/migrations/0016_alter_chatrecord_problem_text.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.15 on 2024-09-26 13:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('application', '0015_re_database_index'), + ] + + operations = [ + migrations.AlterField( + model_name='chatrecord', + name='problem_text', + field=models.CharField(max_length=10240, verbose_name='问题'), + ), + ] diff --git a/apps/application/models/application.py b/apps/application/models/application.py index 13bf3b6aa..de1868dde 100644 --- a/apps/application/models/application.py +++ b/apps/application/models/application.py @@ -137,7 +137,7 @@ class ChatRecord(AppModelMixin): chat = models.ForeignKey(Chat, on_delete=models.CASCADE) vote_status = models.CharField(verbose_name='投票', max_length=10, choices=VoteChoices.choices, default=VoteChoices.UN_VOTE) - problem_text = models.CharField(max_length=1024, verbose_name="问题") + problem_text = models.CharField(max_length=10240, verbose_name="问题") answer_text = models.CharField(max_length=40960, verbose_name="答案") message_tokens = models.IntegerField(verbose_name="请求token数量", default=0) answer_tokens = models.IntegerField(verbose_name="响应token数量", default=0) diff --git a/apps/application/serializers/application_serializers.py b/apps/application/serializers/application_serializers.py index 176da414e..fdfe8eeb7 100644 --- a/apps/application/serializers/application_serializers.py +++ b/apps/application/serializers/application_serializers.py @@ -728,12 +728,13 @@ class ApplicationSerializer(serializers.Serializer): if application_setting_model is not None and X_PACK_LICENSE_IS_VALID: application_setting = QuerySet(application_setting_model).filter( application_id=application_access_token.application_id).first() - application_setting_dict = {'show_source': application_access_token.show_source, - 'show_history': application_setting.show_history, - 'draggable': application_setting.draggable, - 'show_guide': application_setting.show_guide, - 'avatar': application_setting.avatar, - 'float_icon': application_setting.float_icon} + if application_setting is not None: + application_setting_dict = {'show_source': application_access_token.show_source, + 'show_history': application_setting.show_history, + 'draggable': application_setting.draggable, + 'show_guide': application_setting.show_guide, + 'avatar': application_setting.avatar, + 'float_icon': application_setting.float_icon} return ApplicationSerializer.Query.reset_application( {**ApplicationSerializer.ApplicationModel(application).data, 'stt_model_id': application.stt_model_id, diff --git a/apps/application/serializers/chat_message_serializers.py b/apps/application/serializers/chat_message_serializers.py index 54bcfadfc..880f5957d 100644 --- a/apps/application/serializers/chat_message_serializers.py +++ b/apps/application/serializers/chat_message_serializers.py @@ -117,7 +117,8 @@ class ChatInfo: 'client_type': client_type} def append_chat_record(self, chat_record: ChatRecord, client_id=None): - chat_record.problem_text = chat_record.problem_text[0:1024] if chat_record.problem_text is not None else "" + chat_record.problem_text = chat_record.problem_text[0:10240] if chat_record.problem_text is not None else "" + chat_record.answer_text = chat_record.answer_text[0:40960] if chat_record.problem_text is not None else "" # 存入缓存中 self.chat_record_list.append(chat_record) if self.application.id is not None: @@ -187,7 +188,7 @@ class OpenAIChatSerializer(serializers.Serializer): chat_id = str(uuid.uuid1()) chat = QuerySet(Chat).filter(id=chat_id).first() if chat is None: - Chat(id=chat_id, application_id=application_id, abstract=message, client_id=client_id).save() + Chat(id=chat_id, application_id=application_id, abstract=message[0:1024], client_id=client_id).save() return chat_id def chat(self, instance: Dict, with_valid=True):