You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/core/Cline.ts
+10-48Lines changed: 10 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -1373,58 +1373,20 @@ export class Cline {
1373
1373
})
1374
1374
}
1375
1375
1376
-
// If the previous API request's total token usage is close to the context window, truncate the conversation history to free up space for the new request
// FIXME: hack to get anyone using openai compatible with deepseek to have the proper context window instead of the default 128k. We need a way for the user to specify the context window for models they input through openai compatible
maxAllowedSize=Math.max(contextWindow-40_000,contextWindow*0.8)// for deepseek, 80% of 64k meant only ~10k buffer which was too small and resulted in users getting context window errors.
1400
-
}
1401
-
1402
-
// This is the most reliable way to know when we're close to hitting the context window.
1403
-
if(totalTokens>=maxAllowedSize){
1404
-
// Since the user may switch between models with different context windows, truncating half may not be enough (ie if switching from claude 200k to deepseek 64k, half truncation will only remove 100k tokens, but we need to remove much more)
1405
-
// So if totalTokens/2 is greater than maxAllowedSize, we truncate 3/4 instead of 1/2
1406
-
// FIXME: truncating the conversation in a way that is optimal for prompt caching AND takes into account multi-context window complexity is something we need to improve
// NOTE: it's okay that we overwriteConversationHistory in resume task since we're only ever removing the last user message and not anything in the middle which would affect this range
// If the previous API request's total token usage is close to the context window, truncate the conversation history to free up space for the new request
// FIXME: hack to get anyone using openai compatible with deepseek to have the proper context window instead of the default 128k. We need a way for the user to specify the context window for models they input through openai compatible
maxAllowedSize=Math.max(contextWindow-40_000,contextWindow*0.8)// for deepseek, 80% of 64k meant only ~10k buffer which was too small and resulted in users getting context window errors.
40
+
}
41
+
42
+
// This is the most reliable way to know when we're close to hitting the context window.
43
+
if(totalTokens>=maxAllowedSize){
44
+
// Since the user may switch between models with different context windows, truncating half may not be enough (ie if switching from claude 200k to deepseek 64k, half truncation will only remove 100k tokens, but we need to remove much more)
45
+
// So if totalTokens/2 is greater than maxAllowedSize, we truncate 3/4 instead of 1/2
46
+
// FIXME: truncating the conversation in a way that is optimal for prompt caching AND takes into account multi-context window complexity is something we need to improve
// NOTE: it's okay that we overwriteConversationHistory in resume task since we're only ever removing the last user message and not anything in the middle which would affect this range
// Make sure the last message being removed is a user message, so that the next message after the initial task message is an assistant message. This preservers the user-assistant-user-assistant structure.
31
98
// NOTE: anthropic format messages are always user-assistant-user-assistant, while openai format messages can have multiple user messages in a row (we use anthropic format throughout cline)
32
-
if(messages[rangeEndIndex].role!=="user"){
99
+
if(apiMessages[rangeEndIndex].role!=="user"){
33
100
rangeEndIndex-=1
34
101
}
35
102
36
103
// this is an inclusive range that will be removed from the conversation history
0 commit comments