mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: 修复问题过长openai应用接口错误
This commit is contained in:
parent
2ce8798d62
commit
5a986877d0
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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='问题'),
|
||||
),
|
||||
]
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue