Skip to content

Commit 9bd5a22

Browse files
authored
fix: After selecting the answer content in the AI conversation and clicking copy, it cannot be copied (#2062)
1 parent a9cc341 commit 9bd5a22

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

apps/application/chat_pipeline/step/chat_step/impl/base_chat_step.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from django.db.models import QuerySet
1616
from django.http import StreamingHttpResponse
17+
from django.utils.translation import gettext as __
1718
from langchain.chat_models.base import BaseChatModel
1819
from langchain.schema import BaseMessage
1920
from langchain.schema.messages import HumanMessage, AIMessage
@@ -26,7 +27,6 @@
2627
from application.models.api_key_model import ApplicationPublicAccessClient
2728
from common.constants.authentication_type import AuthenticationType
2829
from setting.models_provider.tools import get_model_instance_by_model_user_id
29-
from django.utils.translation import gettext_lazy as _
3030

3131

3232
def add_access_num(client_id=None, client_type=None, application_id=None):
@@ -174,7 +174,7 @@ def get_stream_result(message_list: List[BaseMessage],
174174
[AIMessageChunk(content=no_references_setting.get('value').replace('{question}', problem_text))]), False
175175
if chat_model is None:
176176
return iter([AIMessageChunk(
177-
_('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.'))]), False
177+
__('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.'))]), False
178178
else:
179179
return chat_model.stream(message_list), True
180180

@@ -218,7 +218,8 @@ def get_block_result(message_list: List[BaseMessage],
218218
'status') == 'designated_answer':
219219
return AIMessage(no_references_setting.get('value').replace('{question}', problem_text)), False
220220
if chat_model is None:
221-
return AIMessage(_('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.')), False
221+
return AIMessage(
222+
__('Sorry, the AI model is not configured. Please go to the application to set up the AI model first.')), False
222223
else:
223224
return chat_model.invoke(message_list), True
224225

apps/application/chat_pipeline/step/reset_problem_step/impl/base_reset_problem_step.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"""
99
from typing import List
1010

11+
from django.utils.translation import gettext as __
1112
from langchain.schema import HumanMessage
1213

1314
from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep
1415
from application.models import ChatRecord
1516
from common.util.split_model import flat_map
1617
from setting.models_provider.tools import get_model_instance_by_model_user_id
17-
from django.utils.translation import gettext_lazy as _
1818

19-
prompt = _(
19+
prompt = __(
2020
"() 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 <data></data> tag")
2121

2222

ui/src/components/ai-chat/component/control/index.vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,26 @@ const menus = ref([
4949
const selectionText = getSelection()
5050
if (selectionText) {
5151
clearSelectedText()
52-
navigator.clipboard.writeText(selectionText).then(() => {
53-
MsgSuccess(t('common.copySuccess'))
54-
})
52+
if (
53+
typeof navigator.clipboard === 'undefined' ||
54+
typeof navigator.clipboard.writeText === 'undefined'
55+
) {
56+
const input = document.createElement('input')
57+
input.setAttribute('value', selectionText)
58+
document.body.appendChild(input)
59+
input.select()
60+
try {
61+
if (document.execCommand('copy')) {
62+
MsgSuccess(t('common.copySuccess'))
63+
}
64+
} finally {
65+
document.body.removeChild(input)
66+
}
67+
} else {
68+
navigator.clipboard.writeText(selectionText).then(() => {
69+
MsgSuccess(t('common.copySuccess'))
70+
})
71+
}
5572
}
5673
}
5774
},

0 commit comments

Comments
 (0)