feat(v2): populate CacheHints on provider.Request when caching enabled
buildProviderRequest now computes cache-breakpoint positions automatically when the WithPromptCaching() option is set. It places up to 3 hints: tools, system, and the index of the last non-system message. Providers that don't support caching (OpenAI, Google) ignore the field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
20
v2/llm.go
20
v2/llm.go
@@ -122,6 +122,26 @@ func buildProviderRequest(model string, messages []Message, cfg *requestConfig)
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.cacheConfig != nil && cfg.cacheConfig.enabled {
|
||||
hints := &provider.CacheHints{LastCacheableMessageIndex: -1}
|
||||
if len(req.Tools) > 0 {
|
||||
hints.CacheTools = true
|
||||
}
|
||||
for _, m := range messages {
|
||||
if m.Role == RoleSystem {
|
||||
hints.CacheSystem = true
|
||||
break
|
||||
}
|
||||
}
|
||||
for i := len(messages) - 1; i >= 0; i-- {
|
||||
if messages[i].Role != RoleSystem {
|
||||
hints.LastCacheableMessageIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
req.CacheHints = hints
|
||||
}
|
||||
|
||||
return req
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user