diff --git a/electron/main/ai/llm/index.ts b/electron/main/ai/llm/index.ts index 113387e1..8628d89d 100644 --- a/electron/main/ai/llm/index.ts +++ b/electron/main/ai/llm/index.ts @@ -499,9 +499,9 @@ export function buildPiModel(config: AIServiceConfig): PiModel { } } - // openai-compatible + openai-completions:自动补全 /v1(用户经常忘记) + // openai-compatible + openai-completions/openai-responses:自动补全 /v1(用户经常忘记) const resolvedBaseUrl = - config.provider === 'openai-compatible' && apiFormat === 'openai-completions' + config.provider === 'openai-compatible' && (apiFormat === 'openai-completions' || apiFormat === 'openai-responses') ? normalizeOpenAICompatibleBaseUrl(baseUrl) : baseUrl diff --git a/src/stores/aiChat.ts b/src/stores/aiChat.ts index d1bbf1c6..67096335 100644 --- a/src/stores/aiChat.ts +++ b/src/stores/aiChat.ts @@ -564,6 +564,8 @@ export const useAIChatStore = defineStore('aiChatRuntime', () => { const initialBufferKey = getDisplayedBufferKey(state) let resolvedConversationId = initialBufferKey === DRAFT_CONVERSATION_KEY ? null : initialBufferKey const targetBuffer = getOrCreateBuffer(state, initialBufferKey, state.selectedAssistantId) + // 在 try 外部声明,以便 catch 块能正确引用当前轮次的用户消息 + let currentUserMessage: ChatMessage | undefined targetBuffer.assistantId = state.selectedAssistantId targetBuffer.loaded = true @@ -622,6 +624,7 @@ export const useAIChatStore = defineStore('aiChatRuntime', () => { timestamp: Date.now(), toolCalls: [], } + currentUserMessage = userMessage targetBuffer.messages.push(userMessage) const aiMessage: ChatMessage = { @@ -945,7 +948,8 @@ export const useAIChatStore = defineStore('aiChatRuntime', () => { lastMessage.contentBlocks = [...blocks] lastMessage.isStreaming = false - const userMsg = targetBuffer.messages.find((m) => m.role === 'user') + // 优先使用当前轮次的用户消息,避免多轮对话取到第一条历史消息 + const userMsg = currentUserMessage || targetBuffer.messages.findLast((m) => m.role === 'user') if (userMsg) { await saveConversation(resolvedConversationId, userMsg, lastMessage) }