From 9bd5a221c86226d1e72c170fd8dff7877a5a6cb9 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:57:16 +0800 Subject: [PATCH] fix: After selecting the answer content in the AI conversation and clicking copy, it cannot be copied (#2062) --- .../step/chat_step/impl/base_chat_step.py | 7 +++--- .../impl/base_reset_problem_step.py | 4 ++-- .../ai-chat/component/control/index.vue | 23 ++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py index 77718df1c..488a6ff6b 100644 --- a/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py +++ b/apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py @@ -14,6 +14,7 @@ from typing import List from django.db.models import QuerySet from django.http import StreamingHttpResponse +from django.utils.translation import gettext as __ from langchain.chat_models.base import BaseChatModel from langchain.schema import BaseMessage from langchain.schema.messages import HumanMessage, AIMessage @@ -26,7 +27,6 @@ from application.chat_pipeline.step.chat_step.i_chat_step import IChatStep, Post from application.models.api_key_model import ApplicationPublicAccessClient from common.constants.authentication_type import AuthenticationType from setting.models_provider.tools import get_model_instance_by_model_user_id -from django.utils.translation import gettext_lazy as _ def add_access_num(client_id=None, client_type=None, application_id=None): @@ -174,7 +174,7 @@ class BaseChatStep(IChatStep): [AIMessageChunk(content=no_references_setting.get('value').replace('{question}', problem_text))]), False if chat_model is None: return iter([AIMessageChunk( - _('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.'))]), False + __('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.'))]), False else: return chat_model.stream(message_list), True @@ -218,7 +218,8 @@ class BaseChatStep(IChatStep): 'status') == 'designated_answer': return AIMessage(no_references_setting.get('value').replace('{question}', problem_text)), False if chat_model is None: - return AIMessage(_('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.')), False + return AIMessage( + __('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.')), False else: return chat_model.invoke(message_list), True 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 b5124ccc4..4ee798f5b 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 @@ -8,15 +8,15 @@ """ from typing import List +from django.utils.translation import gettext as __ from langchain.schema import HumanMessage from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep from application.models import ChatRecord from common.util.split_model import flat_map from setting.models_provider.tools import get_model_instance_by_model_user_id -from django.utils.translation import gettext_lazy as _ -prompt = _( +prompt = __( "() contains the user's question. Answer the guessed user's question based on the context ({question}) Requirement: Output a complete question and put it in the tag") diff --git a/ui/src/components/ai-chat/component/control/index.vue b/ui/src/components/ai-chat/component/control/index.vue index e8a2febe7..5f6f50f78 100644 --- a/ui/src/components/ai-chat/component/control/index.vue +++ b/ui/src/components/ai-chat/component/control/index.vue @@ -49,9 +49,26 @@ const menus = ref([ const selectionText = getSelection() if (selectionText) { clearSelectedText() - navigator.clipboard.writeText(selectionText).then(() => { - MsgSuccess(t('common.copySuccess')) - }) + if ( + typeof navigator.clipboard === 'undefined' || + typeof navigator.clipboard.writeText === 'undefined' + ) { + const input = document.createElement('input') + input.setAttribute('value', selectionText) + document.body.appendChild(input) + input.select() + try { + if (document.execCommand('copy')) { + MsgSuccess(t('common.copySuccess')) + } + } finally { + document.body.removeChild(input) + } + } else { + navigator.clipboard.writeText(selectionText).then(() => { + MsgSuccess(t('common.copySuccess')) + }) + } } } },