From 6b8345e792968b3d1b6d164e2a52aaac87ca17ea Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Thu, 8 May 2025 21:08:13 -0700 Subject: [PATCH] Introduce promptCaching option --- core/config/types.ts | 1 - core/index.d.ts | 2 +- core/llm/llms/Bedrock.ts | 6 +++--- packages/config-yaml/src/schemas/models.ts | 1 + 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/config/types.ts b/core/config/types.ts index e9b7ca3fd..a23dcfeec 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -852,7 +852,6 @@ declare global { export interface CacheBehavior { cacheSystemMessage?: boolean; cacheConversation?: boolean; - cacheToolsConfig?: boolean; } export interface ClientCertificateOptions { diff --git a/core/index.d.ts b/core/index.d.ts index 5a9707e3f..ba00f345c 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -927,7 +927,6 @@ export interface RequestOptions { export interface CacheBehavior { cacheSystemMessage?: boolean; cacheConversation?: boolean; - cacheToolsConfig?: boolean; } export interface ClientCertificateOptions { @@ -1024,6 +1023,7 @@ export interface BaseCompletionOptions { toolChoice?: ToolChoice; reasoning?: boolean; reasoningBudgetTokens?: number; + promptCaching?: boolean; } export interface ModelCapability { diff --git a/core/llm/llms/Bedrock.ts b/core/llm/llms/Bedrock.ts index 055d456d2..7ca0f801c 100644 --- a/core/llm/llms/Bedrock.ts +++ b/core/llm/llms/Bedrock.ts @@ -292,10 +292,10 @@ class Bedrock extends BaseLLM { const convertedMessages = this._convertMessages(messages); const shouldCacheSystemMessage = - !!systemMessage && this.cacheBehavior?.cacheSystemMessage; + !!systemMessage && this.cacheBehavior?.cacheSystemMessage || this.completionOptions.promptCaching; const enablePromptCaching = - shouldCacheSystemMessage || this.cacheBehavior?.cacheConversation; - const shouldCacheToolsConfig = this.cacheBehavior?.cacheToolsConfig; + shouldCacheSystemMessage || this.cacheBehavior?.cacheConversation || this.completionOptions.promptCaching; + const shouldCacheToolsConfig = this.completionOptions.promptCaching; // Add header for prompt caching if (enablePromptCaching) { diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index 2a1eb0a68..575799936 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -49,6 +49,7 @@ export const completionOptionsSchema = z.object({ n: z.number().optional(), reasoning: z.boolean().optional(), reasoningBudgetTokens: z.number().optional(), + promptCaching: z.boolean().optional(), }); export type CompletionOptions = z.infer;