fix: After selecting the answer content in the AI conversation and clicking copy, it cannot be copied (#2062)
This commit is contained in:
parent
a9cc34103a
commit
9bd5a221c8
@ -14,6 +14,7 @@ from typing import List
|
|||||||
|
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
from django.http import StreamingHttpResponse
|
from django.http import StreamingHttpResponse
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain.chat_models.base import BaseChatModel
|
from langchain.chat_models.base import BaseChatModel
|
||||||
from langchain.schema import BaseMessage
|
from langchain.schema import BaseMessage
|
||||||
from langchain.schema.messages import HumanMessage, AIMessage
|
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 application.models.api_key_model import ApplicationPublicAccessClient
|
||||||
from common.constants.authentication_type import AuthenticationType
|
from common.constants.authentication_type import AuthenticationType
|
||||||
from setting.models_provider.tools import get_model_instance_by_model_user_id
|
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):
|
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
|
[AIMessageChunk(content=no_references_setting.get('value').replace('{question}', problem_text))]), False
|
||||||
if chat_model is None:
|
if chat_model is None:
|
||||||
return iter([AIMessageChunk(
|
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:
|
else:
|
||||||
return chat_model.stream(message_list), True
|
return chat_model.stream(message_list), True
|
||||||
|
|
||||||
@ -218,7 +218,8 @@ class BaseChatStep(IChatStep):
|
|||||||
'status') == 'designated_answer':
|
'status') == 'designated_answer':
|
||||||
return AIMessage(no_references_setting.get('value').replace('{question}', problem_text)), False
|
return AIMessage(no_references_setting.get('value').replace('{question}', problem_text)), False
|
||||||
if chat_model is None:
|
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:
|
else:
|
||||||
return chat_model.invoke(message_list), True
|
return chat_model.invoke(message_list), True
|
||||||
|
|
||||||
|
|||||||
@ -8,15 +8,15 @@
|
|||||||
"""
|
"""
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
from django.utils.translation import gettext as __
|
||||||
from langchain.schema import HumanMessage
|
from langchain.schema import HumanMessage
|
||||||
|
|
||||||
from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep
|
from application.chat_pipeline.step.reset_problem_step.i_reset_problem_step import IResetProblemStep
|
||||||
from application.models import ChatRecord
|
from application.models import ChatRecord
|
||||||
from common.util.split_model import flat_map
|
from common.util.split_model import flat_map
|
||||||
from setting.models_provider.tools import get_model_instance_by_model_user_id
|
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 <data></data> tag")
|
"() 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")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -49,9 +49,26 @@ const menus = ref([
|
|||||||
const selectionText = getSelection()
|
const selectionText = getSelection()
|
||||||
if (selectionText) {
|
if (selectionText) {
|
||||||
clearSelectedText()
|
clearSelectedText()
|
||||||
navigator.clipboard.writeText(selectionText).then(() => {
|
if (
|
||||||
MsgSuccess(t('common.copySuccess'))
|
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'))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user