fix: move topic prompt handling to message thunk and fix prompt logic (#9569)

This commit is contained in:
Yricky 2025-08-26 22:20:16 +08:00 committed by GitHub
parent 5bbc35695a
commit 267b41242d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 20 deletions

View File

@ -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('')

View File

@ -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)

View File

@ -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时会用到

View File

@ -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 {