mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-30 15:59:09 +08:00
fix: move topic prompt handling to message thunk and fix prompt logic (#9569)
This commit is contained in:
parent
5bbc35695a
commit
267b41242d
@ -241,16 +241,12 @@ const Inputbar: FC<Props> = ({ assistant: _assistant, setActiveTopic, topic }) =
|
||||
baseUserMessage.mentions = mentionedModels
|
||||
}
|
||||
|
||||
const assistantWithTopicPrompt = topic.prompt
|
||||
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||
: assistant
|
||||
|
||||
baseUserMessage.usage = await estimateUserPromptUsage(baseUserMessage)
|
||||
|
||||
const { message, blocks } = getUserMessage(baseUserMessage)
|
||||
message.traceId = parent?.spanContext().traceId
|
||||
|
||||
dispatch(_sendMessage(message, blocks, assistantWithTopicPrompt, topic.id))
|
||||
dispatch(_sendMessage(message, blocks, assistant, topic.id))
|
||||
|
||||
// Clear input
|
||||
setText('')
|
||||
|
||||
@ -100,11 +100,8 @@ 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, assistantWithTopicPrompt)
|
||||
await resendUserMessageWithEdit(message, blocks, assistant)
|
||||
stopEditing()
|
||||
} catch (error) {
|
||||
logger.error('Failed to resend message:', error as Error)
|
||||
|
||||
@ -150,10 +150,7 @@ const MessageMenubar: FC<Props> = (props) => {
|
||||
const handleResendUserMessage = useCallback(
|
||||
async (messageUpdate?: Message) => {
|
||||
if (!loading) {
|
||||
const assistantWithTopicPrompt = topic.prompt
|
||||
? { ...assistant, prompt: `${assistant.prompt}\n${topic.prompt}` }
|
||||
: assistant
|
||||
await resendMessage(messageUpdate ?? message, assistantWithTopicPrompt)
|
||||
await resendMessage(messageUpdate ?? message, assistant)
|
||||
}
|
||||
},
|
||||
[assistant, loading, message, resendMessage, topic.prompt]
|
||||
@ -379,12 +376,8 @@ 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, assistantWithTopicPrompt)
|
||||
regenerateAssistantMessage(message, assistant)
|
||||
}
|
||||
|
||||
// 按条件筛选能够提及的模型,该函数仅在isAssistantMessage时会用到
|
||||
|
||||
@ -288,14 +288,18 @@ const dispatchMultiModelResponses = async (
|
||||
}
|
||||
|
||||
// --- End Helper Function ---
|
||||
|
||||
// 发送和处理助手响应的实现函数,话题提示词在此拼接
|
||||
const fetchAndProcessAssistantResponseImpl = async (
|
||||
dispatch: AppDispatch,
|
||||
getState: () => RootState,
|
||||
topicId: string,
|
||||
assistant: Assistant,
|
||||
origAssistant: Assistant,
|
||||
assistantMessage: Message // Pass the prepared assistant message (new or reset)
|
||||
) => {
|
||||
const topic = origAssistant.topics.find((t) => t.id === topicId)
|
||||
const assistant = topic?.prompt
|
||||
? { ...origAssistant, prompt: `${origAssistant.prompt}\n${topic.prompt}` }
|
||||
: origAssistant
|
||||
const assistantMsgId = assistantMessage.id
|
||||
let callbacks: StreamProcessorCallbacks = {}
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user