mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 05:09:09 +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
e4e4dcbd1e
commit
9138aecdf0
@ -191,16 +191,16 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topic.prompt) {
|
const assistantWithTopicPrompt = topic.prompt
|
||||||
assistant.prompt = assistant.prompt ? `${assistant.prompt}\n${topic.prompt}` : topic.prompt
|
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||||
}
|
: assistant
|
||||||
|
|
||||||
baseUserMessage.usage = await estimateUserPromptUsage(baseUserMessage)
|
baseUserMessage.usage = await estimateUserPromptUsage(baseUserMessage)
|
||||||
|
|
||||||
const { message, blocks } = getUserMessage(baseUserMessage)
|
const { message, blocks } = getUserMessage(baseUserMessage)
|
||||||
|
|
||||||
currentMessageId.current = message.id
|
currentMessageId.current = message.id
|
||||||
dispatch(_sendMessage(message, blocks, assistant, topic.id))
|
dispatch(_sendMessage(message, blocks, assistantWithTopicPrompt, topic.id))
|
||||||
|
|
||||||
// Clear input
|
// Clear input
|
||||||
setText('')
|
setText('')
|
||||||
|
|||||||
@ -80,14 +80,17 @@ const MessageItem: FC<Props> = ({
|
|||||||
|
|
||||||
const handleEditResend = useCallback(
|
const handleEditResend = useCallback(
|
||||||
async (blocks: MessageBlock[]) => {
|
async (blocks: MessageBlock[]) => {
|
||||||
|
const assistantWithTopicPrompt = topic.prompt
|
||||||
|
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||||
|
: assistant
|
||||||
try {
|
try {
|
||||||
await resendUserMessageWithEdit(message, blocks, assistant)
|
await resendUserMessageWithEdit(message, blocks, assistantWithTopicPrompt)
|
||||||
stopEditing()
|
stopEditing()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to resend message:', error)
|
console.error('Failed to resend message:', error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[message, resendUserMessageWithEdit, assistant, stopEditing]
|
[message, resendUserMessageWithEdit, assistant, stopEditing, topic.prompt]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleEditCancel = useCallback(() => {
|
const handleEditCancel = useCallback(() => {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import type { Model } from '@renderer/types'
|
|||||||
import type { Assistant, Topic } from '@renderer/types'
|
import type { Assistant, Topic } from '@renderer/types'
|
||||||
import type { Message } from '@renderer/types/newMessage'
|
import type { Message } from '@renderer/types/newMessage'
|
||||||
import { captureScrollableDivAsBlob, captureScrollableDivAsDataURL } from '@renderer/utils'
|
import { captureScrollableDivAsBlob, captureScrollableDivAsDataURL } from '@renderer/utils'
|
||||||
|
import { copyMessageAsPlainText } from '@renderer/utils/copy'
|
||||||
import {
|
import {
|
||||||
exportMarkdownToJoplin,
|
exportMarkdownToJoplin,
|
||||||
exportMarkdownToSiyuan,
|
exportMarkdownToSiyuan,
|
||||||
@ -23,7 +24,6 @@ import {
|
|||||||
exportMessageToNotion,
|
exportMessageToNotion,
|
||||||
messageToMarkdown
|
messageToMarkdown
|
||||||
} from '@renderer/utils/export'
|
} from '@renderer/utils/export'
|
||||||
import { copyMessageAsPlainText } from '@renderer/utils/copy'
|
|
||||||
// import { withMessageThought } from '@renderer/utils/formats'
|
// import { withMessageThought } from '@renderer/utils/formats'
|
||||||
import { removeTrailingDoubleSpaces } from '@renderer/utils/markdown'
|
import { removeTrailingDoubleSpaces } from '@renderer/utils/markdown'
|
||||||
import { findMainTextBlocks, findTranslationBlocks, getMainTextContent } from '@renderer/utils/messageUtils/find'
|
import { findMainTextBlocks, findTranslationBlocks, getMainTextContent } from '@renderer/utils/messageUtils/find'
|
||||||
@ -124,10 +124,13 @@ const MessageMenubar: FC<Props> = (props) => {
|
|||||||
const handleResendUserMessage = useCallback(
|
const handleResendUserMessage = useCallback(
|
||||||
async (messageUpdate?: Message) => {
|
async (messageUpdate?: Message) => {
|
||||||
if (!loading) {
|
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()
|
const { startEditing } = useMessageEditing()
|
||||||
@ -316,8 +319,12 @@ const MessageMenubar: FC<Props> = (props) => {
|
|||||||
// const _message = resetAssistantMessage(message, selectedModel)
|
// const _message = resetAssistantMessage(message, selectedModel)
|
||||||
// editMessage(message.id, { ..._message }) // REMOVED
|
// editMessage(message.id, { ..._message }) // REMOVED
|
||||||
|
|
||||||
|
const assistantWithTopicPrompt = topic.prompt
|
||||||
|
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||||
|
: assistant
|
||||||
|
|
||||||
// Call the function from the hook
|
// Call the function from the hook
|
||||||
regenerateAssistantMessage(message, assistant)
|
regenerateAssistantMessage(message, assistantWithTopicPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onMentionModel = async (e: React.MouseEvent) => {
|
const onMentionModel = async (e: React.MouseEvent) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user