fix(chat): include history in model fallback
This commit is contained in:
@@ -75,11 +75,7 @@ func prepareMessagesWithHistory(chatManage *types.ChatManage) []chat.Message {
|
||||
{Role: "system", Content: systemPrompt},
|
||||
}
|
||||
|
||||
// Add conversation history (already limited by maxRounds in load_history/rewrite plugins)
|
||||
for _, history := range chatManage.History {
|
||||
chatMessages = append(chatMessages, chat.Message{Role: "user", Content: history.Query})
|
||||
chatMessages = append(chatMessages, chat.Message{Role: "assistant", Content: history.Answer})
|
||||
}
|
||||
chatMessages = AppendHistoryMessages(chatMessages, chatManage.History)
|
||||
|
||||
// Add current user message. Only include images when the chat model supports
|
||||
// vision; non-vision models rely on the text description in UserContent.
|
||||
@@ -92,6 +88,16 @@ func prepareMessagesWithHistory(chatManage *types.ChatManage) []chat.Message {
|
||||
return chatMessages
|
||||
}
|
||||
|
||||
// AppendHistoryMessages appends prior Q&A rounds in chronological order.
|
||||
// History is already filtered and truncated upstream by the load_history plugin.
|
||||
func AppendHistoryMessages(messages []chat.Message, history []*types.History) []chat.Message {
|
||||
for _, history := range history {
|
||||
messages = append(messages, chat.Message{Role: "user", Content: history.Query})
|
||||
messages = append(messages, chat.Message{Role: "assistant", Content: history.Answer})
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
// loadAndProcessHistory fetches recent messages, groups them into Q&A pairs,
|
||||
// strips <think> tags from assistant answers, sorts by recency, and limits to maxRounds.
|
||||
// fetchCount controls how many raw messages to fetch (typically maxRounds*2+10).
|
||||
|
||||
Reference in New Issue
Block a user