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:
@@ -67,6 +67,8 @@ func NewRemoteAPIChat(chatConfig *ChatConfig) (*RemoteAPIChat, error) {
|
||||
config = openai.DefaultConfig(apiKey)
|
||||
if baseURL := chatConfig.BaseURL; baseURL != "" {
|
||||
config.BaseURL = baseURL
|
||||
} else if providerName == provider.ProviderDeepSeek {
|
||||
config.BaseURL = provider.DeepSeekBaseURL
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +102,7 @@ func NewRemoteAPIChat(chatConfig *ChatConfig) (*RemoteAPIChat, error) {
|
||||
modelName: modelName,
|
||||
client: openai.NewClientWithConfig(config),
|
||||
modelID: chatConfig.ModelID,
|
||||
baseURL: chatConfig.BaseURL,
|
||||
baseURL: strings.TrimRight(config.BaseURL, "/"),
|
||||
apiKey: apiKey,
|
||||
provider: providerName,
|
||||
appID: chatConfig.AppID,
|
||||
@@ -255,6 +257,7 @@ func (c *RemoteAPIChat) chatWithRawHTTP(ctx context.Context, endpoint string, cu
|
||||
return nil, err
|
||||
}
|
||||
c.applyCompletionToolCallMetadata(body, result)
|
||||
applyRawPromptCacheUsage(body, &result.Usage)
|
||||
logUsage(ctx, c.modelName, &result.Usage)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user