Elffuss BraidHub

kikocis/continue public

fix: :art:
Changesetbb0f4212e0e0bfb18e5ef4830110411990154028d36218301b4c0f3a2deecc3a
Authorchezsmithy <chezsmithy@me.com> · 2025-09-09 09:02 -07:00
Committerchezsmithy <chezsmithy@me.com> · 2025-09-09 09:02 -07:00
Parents57ba4ba8a78e

Browse the files at this changeset

2 files changed

modified core/llm/llms/Bedrock.test.ts +91 −1
@@ -532,7 +532,7 @@
532532 );
533533 });
534534
535- it("should add cache points for prompt caching when needed", () => {
535+ it("should add cache points when cacheBehavior.cacheConversation is enabled", () => {
536536 // Create a test instance with caching behavior enabled
537537 const bedrockWithCaching = new TestBedrock({
538538 apiKey: "test-key",
@@ -576,5 +576,95 @@
576576 const userMessageText = converted[0].content?.[0].text;
577577 expect(userMessageText).toMatch(/First message.+/);
578578 });
579+
580+ it("should add cache points when completionOptions.promptCaching is enabled", () => {
581+ // Create a test instance with prompt caching enabled via completionOptions
582+ const bedrockWithPromptCaching = new TestBedrock({
583+ apiKey: "test-key",
584+ model: "anthropic.claude-3-sonnet-20240229-v1:0",
585+ region: "us-east-1",
586+ });
587+
588+ // Set completionOptions.promptCaching (without cacheBehavior)
589+ bedrockWithPromptCaching.completionOptions = {
590+ ...bedrockWithPromptCaching.completionOptions,
591+ promptCaching: true,
592+ };
593+
594+ const messages: ChatMessage[] = [
595+ { role: "user", content: "First message" } as UserChatMessage,
596+ { role: "assistant", content: "First response" },
597+ { role: "user", content: "Second message" } as UserChatMessage,
598+ ];
599+
600+ const availableTools = new Set<string>();
601+ const converted = bedrockWithPromptCaching["_convertMessages"](
602+ messages,
603+ availableTools,
604+ );
605+
606+ // The last two user messages should have cache points
607+ expect(converted.length).toBe(3);
608+ expect(converted[0].role).toBe("user");
609+ expect(converted[0].content?.some((block) => block.cachePoint)).toBe(
610+ true,
611+ );
612+ expect(converted[1].role).toBe("assistant");
613+ expect(converted[2].role).toBe("user");
614+ expect(converted[2].content?.some((block) => block.cachePoint)).toBe(
615+ true,
616+ );
617+
618+ // Verify that text content includes a cache ID suffix
619+ const userMessageText = converted[0].content?.[0].text;
620+ expect(userMessageText).toMatch(/First message.+/);
621+ });
622+
623+ it("should not add cache points when both caching options are disabled", () => {
624+ // Create a test instance with no caching enabled
625+ const bedrockNoCaching = new TestBedrock({
626+ apiKey: "test-key",
627+ model: "anthropic.claude-3-sonnet-20240229-v1:0",
628+ region: "us-east-1",
629+ });
630+
631+ // Explicitly set no caching
632+ bedrockNoCaching.cacheBehavior = {
633+ cacheConversation: false,
634+ cacheSystemMessage: false,
635+ };
636+ bedrockNoCaching.completionOptions = {
637+ ...bedrockNoCaching.completionOptions,
638+ promptCaching: false,
639+ };
640+
641+ const messages: ChatMessage[] = [
642+ { role: "user", content: "First message" } as UserChatMessage,
643+ { role: "assistant", content: "First response" },
644+ { role: "user", content: "Second message" } as UserChatMessage,
645+ ];
646+
647+ const availableTools = new Set<string>();
648+ const converted = bedrockNoCaching["_convertMessages"](
649+ messages,
650+ availableTools,
651+ );
652+
653+ // No cache points should be added
654+ expect(converted.length).toBe(3);
655+ expect(converted[0].role).toBe("user");
656+ expect(converted[0].content?.some((block) => block.cachePoint)).toBe(
657+ false,
658+ );
659+ expect(converted[1].role).toBe("assistant");
660+ expect(converted[2].role).toBe("user");
661+ expect(converted[2].content?.some((block) => block.cachePoint)).toBe(
662+ false,
663+ );
664+
665+ // Verify that text content doesn't include a cache ID suffix
666+ const userMessageText = converted[0].content?.[0].text;
667+ expect(userMessageText).toBe("First message");
668+ });
579669 });
580670 });
modified core/llm/llms/Bedrock.ts +4 −1
@@ -513,7 +513,10 @@
513513 // The second-to-last because it retrieves potentially already cached contents,
514514 // The last one because we want it cached for later retrieval.
515515 // See: https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html
516- if (this.cacheBehavior?.cacheConversation || this.completionOptions.promptCaching) {
516+ if (
517+ this.cacheBehavior?.cacheConversation ||
518+ this.completionOptions.promptCaching
519+ ) {
517520 this._addCachingToLastTwoUserMessages(converted);
518521 }
519522