mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
fix: missing topic prompt on resend/regenerate and duplicate prevention (#7173)
* fix: completion doesn't include topic prompt * fix: Multiple additions of topic prompts * fix: improve logic * fix: improve logic
This commit is contained in:
parent
22849905d4
commit
e1f9a5d66d
@ -191,16 +191,16 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
)
|
||||
}
|
||||
|
||||
if (topic.prompt) {
|
||||
assistant.prompt = assistant.prompt ? `${assistant.prompt}\n${topic.prompt}` : topic.prompt
|
||||
}
|
||||
const assistantWithTopicPrompt = topic.prompt
|
||||
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||
: assistant
|
||||
|
||||
baseUserMessage.usage = await estimateUserPromptUsage(baseUserMessage)
|
||||
|
||||
const { message, blocks } = getUserMessage(baseUserMessage)
|
||||
|
||||
currentMessageId.current = message.id
|
||||
dispatch(_sendMessage(message, blocks, assistant, topic.id))
|
||||
dispatch(_sendMessage(message, blocks, assistantWithTopicPrompt, topic.id))
|
||||
|
||||
// Clear input
|
||||
setText('')
|
||||
|
||||
@ -80,14 +80,17 @@ const MessageItem: FC<Props> = ({
|
||||
|
||||
const handleEditResend = useCallback(
|
||||
async (blocks: MessageBlock[]) => {
|
||||
const assistantWithTopicPrompt = topic.prompt
|
||||
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||
: assistant
|
||||
try {
|
||||
await resendUserMessageWithEdit(message, blocks, assistant)
|
||||
await resendUserMessageWithEdit(message, blocks, assistantWithTopicPrompt)
|
||||
stopEditing()
|
||||
} catch (error) {
|
||||
console.error('Failed to resend message:', error)
|
||||
}
|
||||
},
|
||||
[message, resendUserMessageWithEdit, assistant, stopEditing]
|
||||
[message, resendUserMessageWithEdit, assistant, stopEditing, topic.prompt]
|
||||
)
|
||||
|
||||
const handleEditCancel = useCallback(() => {
|
||||
|
||||
@ -15,6 +15,7 @@ import type { Model } from '@renderer/types'
|
||||
import type { Assistant, Topic } from '@renderer/types'
|
||||
import type { Message } from '@renderer/types/newMessage'
|
||||
import { captureScrollableDivAsBlob, captureScrollableDivAsDataURL } from '@renderer/utils'
|
||||
import { copyMessageAsPlainText } from '@renderer/utils/copy'
|
||||
import {
|
||||
exportMarkdownToJoplin,
|
||||
exportMarkdownToSiyuan,
|
||||
@ -23,7 +24,6 @@ import {
|
||||
exportMessageToNotion,
|
||||
messageToMarkdown
|
||||
} from '@renderer/utils/export'
|
||||
import { copyMessageAsPlainText } from '@renderer/utils/copy'
|
||||
// import { withMessageThought } from '@renderer/utils/formats'
|
||||
import { removeTrailingDoubleSpaces } from '@renderer/utils/markdown'
|
||||
import { findMainTextBlocks, findTranslationBlocks, getMainTextContent } from '@renderer/utils/messageUtils/find'
|
||||
@ -124,10 +124,13 @@ const MessageMenubar: FC<Props> = (props) => {
|
||||
const handleResendUserMessage = useCallback(
|
||||
async (messageUpdate?: Message) => {
|
||||
if (!loading) {
|
||||
await resendMessage(messageUpdate ?? message, assistant)
|
||||
const assistantWithTopicPrompt = topic.prompt
|
||||
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||
: assistant
|
||||
await resendMessage(messageUpdate ?? message, assistantWithTopicPrompt)
|
||||
}
|
||||
},
|
||||
[assistant, loading, message, resendMessage]
|
||||
[assistant, loading, message, resendMessage, topic.prompt]
|
||||
)
|
||||
|
||||
const { startEditing } = useMessageEditing()
|
||||
@ -316,8 +319,12 @@ const MessageMenubar: FC<Props> = (props) => {
|
||||
// const _message = resetAssistantMessage(message, selectedModel)
|
||||
// editMessage(message.id, { ..._message }) // REMOVED
|
||||
|
||||
const assistantWithTopicPrompt = topic.prompt
|
||||
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||
: assistant
|
||||
|
||||
// Call the function from the hook
|
||||
regenerateAssistantMessage(message, assistant)
|
||||
regenerateAssistantMessage(message, assistantWithTopicPrompt)
|
||||
}
|
||||
|
||||
const onMentionModel = async (e: React.MouseEvent) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user