feat(llm): add prompt-cache observability and wiki cache-friendly prompts
Normalize provider-specific cache counters into TokenUsage, propagate call purpose and prefix fingerprints through context for logging and Langfuse, and restructure wiki page-modify prompts with warmup/singleflight to improve prefix cache hit rates during reduce batches.
This commit is contained in:
@@ -113,6 +113,18 @@ func prepareMessagesWithHistory(chatManage *types.ChatManage) []chat.Message {
|
||||
return chatMessages
|
||||
}
|
||||
|
||||
func withPromptCacheMetadata(
|
||||
ctx context.Context,
|
||||
chatModel chat.Chat,
|
||||
messages []chat.Message,
|
||||
opts *chat.ChatOptions,
|
||||
purpose string,
|
||||
) context.Context {
|
||||
prefixFingerprint := chat.PromptPrefixFingerprint(messages, opts)
|
||||
_ = chatModel // model identity is already captured by the usage sink
|
||||
return types.WithLLMCallMetadata(ctx, purpose, prefixFingerprint)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
||||
Reference in New Issue
Block a user