From da4b5be7a591cf2cba29be05265d89d7e60f957d Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:27:08 +0800 Subject: [PATCH] Pr@main@fix bugs (#22) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Ollama 添加未下载的模型,下载进度会由 100-0-100 * fix: 处理优化问题为空字符串的情况下,使用原始问题进行问答 * fix: 创建用户 登录密码使用默认密码MaxKB@123.. 提示规则不对。 * fix: 【应用】从应用中的【对话日志】处保存内容报错 * fix: 刷新访问链接增加确认提示 * fix: 【应用】浮窗模式的 放大按钮与关闭按钮未对齐 * fix: merge时被误删的代码 * fix: mac电脑输入法状态下按回车会发送对话 --------- Co-authored-by: wangdan-fit2cloud --- .../impl/base_reset_problem_step.py | 5 ++- .../serializers/chat_serializers.py | 11 +++++-- apps/application/template/embed.js | 31 ++++++++++--------- .../ollama_model_provider.py | 1 + apps/users/serializers/user_serializers.py | 28 ++++++++--------- ui/src/components/ai-chat/index.vue | 2 +- ui/src/views/applicaiton-overview/index.vue | 20 +++++++++--- ui/src/views/template/component/ModelCard.vue | 5 ++- 8 files changed, 64 insertions(+), 39 deletions(-) diff --git a/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py b/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py index fffdf4662..2386be4fe 100644 --- a/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py +++ b/apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py @@ -31,7 +31,10 @@ class BaseResetProblemStep(IResetProblemStep): response = chat_model.invoke(message_list) padding_problem = problem_text if response.content.__contains__("") and response.content.__contains__(''): - padding_problem = response.content[response.content.index('') + 6:response.content.index('')] + padding_problem_data = response.content[ + response.content.index('') + 6:response.content.index('')] + if padding_problem_data is not None and len(padding_problem_data.strip()) > 0: + padding_problem = padding_problem_data self.context['message_tokens'] = chat_model.get_num_tokens_from_messages(message_list) self.context['answer_tokens'] = chat_model.get_num_tokens(padding_problem) return padding_problem diff --git a/apps/application/serializers/chat_serializers.py b/apps/application/serializers/chat_serializers.py index d48e4c899..0d7f4a103 100644 --- a/apps/application/serializers/chat_serializers.py +++ b/apps/application/serializers/chat_serializers.py @@ -32,7 +32,7 @@ from common.util.field_message import ErrMessage from common.util.file_util import get_file_content from common.util.lock import try_lock, un_lock from common.util.rsa_util import decrypt -from dataset.models import Document, Problem, Paragraph +from dataset.models import Document, Problem, Paragraph, ProblemParagraphMapping from dataset.serializers.paragraph_serializers import ParagraphSerializers from setting.models import Model from setting.models_provider.constants.model_provider_constants import ModelProvideConstants @@ -405,12 +405,17 @@ class ChatRecordSerializer(serializers.Serializer): dataset_id=dataset_id, title=instance.get("title") if 'title' in instance else '') - problem = Problem(id=uuid.uuid1(), content=chat_record.problem_text, paragraph_id=paragraph.id, - document_id=document_id, dataset_id=dataset_id) + problem = Problem(id=uuid.uuid1(), content=chat_record.problem_text, dataset_id=dataset_id) + problem_paragraph_mapping = ProblemParagraphMapping(id=uuid.uuid1(), dataset_id=dataset_id, + document_id=document_id, + problem_id=problem.id, + paragraph_id=paragraph.id) # 插入问题 problem.save() # 插入段落 paragraph.save() + # 插入关联问题 + problem_paragraph_mapping.save() chat_record.improve_paragraph_id_list.append(paragraph.id) # 添加标注 chat_record.save() diff --git a/apps/application/template/embed.js b/apps/application/template/embed.js index bef116318..047f94b90 100644 --- a/apps/application/template/embed.js +++ b/apps/application/template/embed.js @@ -50,14 +50,15 @@ const chatButtonHtml= const getChatContainerHtml=(protocol,host,token)=>{ return `
-
+
-
` +
+` } /** * 初始化引导 @@ -247,22 +248,24 @@ function initMaxkbStyle(root){ box-shadow: 0px 4px 8px 0px rgba(31, 35, 41, 0.10); position: fixed;bottom: 20px;right: 45px;overflow: hidden; } - #maxkb #maxkb-chat-container .maxkb-chat-close{ - position: absolute; - top: 15px; - right: 10px; + + #maxkb #maxkb-chat-container .maxkb-operate{ + top: 15px; + right: 10px; + position: absolute; + display: flex; + align-items: center; + } + #maxkb #maxkb-chat-container .maxkb-operate .maxkb-chat-close{ + margin-left:15px; cursor: pointer; } - #maxkb #maxkb-chat-container .maxkb-openviewport{ - position: absolute; - top: 15px; - right: 50px; + #maxkb #maxkb-chat-container .maxkb-operate .maxkb-openviewport{ + cursor: pointer; } - #maxkb #maxkb-chat-container .maxkb-closeviewport{ - position: absolute; - top: 15px; - right: 50px; + #maxkb #maxkb-chat-container .maxkb-operate .maxkb-closeviewport{ + cursor: pointer; } #maxkb #maxkb-chat-container .maxkb-viewportnone{ diff --git a/apps/setting/models_provider/impl/ollama_model_provider/ollama_model_provider.py b/apps/setting/models_provider/impl/ollama_model_provider/ollama_model_provider.py index 3436fdb0e..2d8097a70 100644 --- a/apps/setting/models_provider/impl/ollama_model_provider/ollama_model_provider.py +++ b/apps/setting/models_provider/impl/ollama_model_provider/ollama_model_provider.py @@ -94,6 +94,7 @@ def convert_to_down_model_chunk(row_str: str, chunk_index: int): if row.get('status') == 'success': status = DownModelChunkStatus.success if row.get('status').__contains__("pulling"): + progress = 0 status = DownModelChunkStatus.pulling if 'total' in row and 'completed' in row: progress = (row.get('completed') / row.get('total') * 100) diff --git a/apps/users/serializers/user_serializers.py b/apps/users/serializers/user_serializers.py index 7a1aa3da1..6672a4cb5 100644 --- a/apps/users/serializers/user_serializers.py +++ b/apps/users/serializers/user_serializers.py @@ -133,15 +133,15 @@ class RegisterSerializer(ApiMixin, serializers.Serializer): ]) password = serializers.CharField(required=True, error_messages=ErrMessage.char("密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="密码长度6-20个字符,必须字母、数字、特殊字符组合")]) re_password = serializers.CharField(required=True, error_messages=ErrMessage.char("确认密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="确认密码长度6-20个字符,必须字母、数字、特殊字符组合")]) code = serializers.CharField(required=True, error_messages=ErrMessage.char("验证码")) @@ -263,14 +263,14 @@ class RePasswordSerializer(ApiMixin, serializers.Serializer): password = serializers.CharField(required=True, error_messages=ErrMessage.char("密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="确认密码长度6-20个字符,必须字母、数字、特殊字符组合")]) re_password = serializers.CharField(required=True, error_messages=ErrMessage.char("确认密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="确认密码长度6-20个字符,必须字母、数字、特殊字符组合")] ) @@ -586,8 +586,8 @@ class UserManageSerializer(serializers.Serializer): ]) password = serializers.CharField(required=True, error_messages=ErrMessage.char("密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="密码长度6-20个字符,必须字母、数字、特殊字符组合")]) nick_name = serializers.CharField(required=False, error_messages=ErrMessage.char("姓名"), max_length=64, @@ -653,13 +653,13 @@ class UserManageSerializer(serializers.Serializer): class RePasswordInstance(ApiMixin, serializers.Serializer): password = serializers.CharField(required=True, error_messages=ErrMessage.char("密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="密码长度6-20个字符,必须字母、数字、特殊字符组合")]) re_password = serializers.CharField(required=True, error_messages=ErrMessage.char("确认密码"), validators=[validators.RegexValidator(regex=re.compile( - "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" - "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~()-+=]{6,20}$") + "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z_!@#$%^&*`~.()-+=]+$)(?![a-z0-9]+$)(?![a-z_!@#$%^&*`~()-+=]+$)" + "(?![0-9_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9_!@#$%^&*`~.()-+=]{6,20}$") , message="确认密码长度6-20个字符,必须字母、数字、特殊字符组合")] ) diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index e126adcc6..1330f4814 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -285,7 +285,7 @@ function sendChatHandle(event: any) { if (!event.ctrlKey) { // 如果没有按下组合键ctrl,则会阻止默认事件 event.preventDefault() - if (!isDisabledChart.value && !loading.value) { + if (!isDisabledChart.value && !loading.value&&!event.isComposing) { chatMessage() } } else { diff --git a/ui/src/views/applicaiton-overview/index.vue b/ui/src/views/applicaiton-overview/index.vue index 9e000a857..6b0d82561 100644 --- a/ui/src/views/applicaiton-overview/index.vue +++ b/ui/src/views/applicaiton-overview/index.vue @@ -196,11 +196,21 @@ function getAppStatistics() { } function refreshAccessToken() { - const obj = { - access_token_reset: true - } - const str = '刷新成功' - updateAccessToken(obj, str) + MsgConfirm( + `是否重新生成公共访问链接?`, + `重新生成公共访问链接会影响嵌入第三方脚本变更,需要将新脚本重新嵌入第三方,请谨慎操作!`, + { + confirmButtonText: '确认' + } + ) + .then(() => { + const obj = { + access_token_reset: true + } + const str = '刷新成功' + updateAccessToken(obj, str) + }) + .catch(() => {}) } function changeState(bool: Boolean) { const obj = { diff --git a/ui/src/views/template/component/ModelCard.vue b/ui/src/views/template/component/ModelCard.vue index 07c5312ed..184fbcbe4 100644 --- a/ui/src/views/template/component/ModelCard.vue +++ b/ui/src/views/template/component/ModelCard.vue @@ -150,7 +150,10 @@ const initInterval = () => { downModel.value = ok.data }) } else { - downModel.value = undefined + if (downModel.value) { + props.updateModelById(props.model.id, downModel.value) + downModel.value = undefined + } } }, 6000) }