Compare commits

...

1 Commits

Author SHA1 Message Date
Dennis Bartlett 644f91c178 Revert "chore: prompt cache up to the third-to-last message in the conversati…"
This reverts commit 359f77c2e3.
2025-04-14 10:54:31 -07:00
3 changed files with 3 additions and 14 deletions
-5
View File
@@ -1,5 +0,0 @@
---
"claude-dev": patch
---
Cache prompts up to third-to-last message in Claude conversation history
+2 -7
View File
@@ -34,7 +34,7 @@ export class AnthropicHandler implements ApiHandler {
case "claude-3-opus-20240229":
case "claude-3-haiku-20240307": {
/*
The latest message will be the new user message, one before will be the assistant message from a previous request, and the user message before that will be a previously cached user message. So we need to mark the latest user message as ephemeral to cache it for the next request, and mark the second and the third to last user message as ephemeral to let the server know the last message to retrieve from the cache for the current request..
The latest message will be the new user message, one before will be the assistant message from a previous request, and the user message before that will be a previously cached user message. So we need to mark the latest user message as ephemeral to cache it for the next request, and mark the second to last user message as ephemeral to let the server know the last message to retrieve from the cache for the current request..
*/
const userMsgIndices = messages.reduce(
(acc, msg, index) => (msg.role === "user" ? [...acc, index] : acc),
@@ -42,7 +42,6 @@ export class AnthropicHandler implements ApiHandler {
)
const lastUserMsgIndex = userMsgIndices[userMsgIndices.length - 1] ?? -1
const secondLastMsgUserIndex = userMsgIndices[userMsgIndices.length - 2] ?? -1
const thirdLastMsgUserIndex = userMsgIndices[userMsgIndices.length - 3] ?? -1
stream = await this.client.messages.create(
{
model: modelId,
@@ -59,11 +58,7 @@ export class AnthropicHandler implements ApiHandler {
},
], // setting cache breakpoint for system prompt so new tasks can reuse it
messages: messages.map((message, index) => {
if (
index === lastUserMsgIndex ||
index === secondLastMsgUserIndex ||
index === thirdLastMsgUserIndex
) {
if (index === lastUserMsgIndex || index === secondLastMsgUserIndex) {
return {
...message,
content:
+1 -2
View File
@@ -47,7 +47,6 @@ export class AwsBedrockHandler implements ApiHandler {
const userMsgIndices = messages.reduce((acc, msg, index) => (msg.role === "user" ? [...acc, index] : acc), [] as number[])
const lastUserMsgIndex = userMsgIndices[userMsgIndices.length - 1] ?? -1
const secondLastMsgUserIndex = userMsgIndices[userMsgIndices.length - 2] ?? -1
const thirdLastMsgUserIndex = userMsgIndices[userMsgIndices.length - 3] ?? -1
// Create anthropic client, using sessions created or renewed after this handler's
// initialization, and allowing for session renewal if necessary as well
@@ -68,7 +67,7 @@ export class AwsBedrockHandler implements ApiHandler {
},
],
messages: messages.map((message, index) => {
if (index === lastUserMsgIndex || index === secondLastMsgUserIndex || index === thirdLastMsgUserIndex) {
if (index === lastUserMsgIndex || index === secondLastMsgUserIndex) {
return {
...message,
content: