|
|
@@ -16,13 +16,17 @@ import {
|
|
|
|
|
|
const patterns = [
|
|
|
/prompt is too long/i,
|
|
|
+ /request_too_large/i,
|
|
|
/input is too long for requested model/i,
|
|
|
/exceeds the context window/i,
|
|
|
+ /exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,
|
|
|
/input token count.*exceeds the maximum/i,
|
|
|
/tokens in request more than max tokens allowed/i,
|
|
|
/maximum prompt length is \d+/i,
|
|
|
/reduce the length of the messages/i,
|
|
|
/maximum context length is \d+ tokens/i,
|
|
|
+ /exceeds (?:the )?maximum allowed input length of [\d,]+ tokens?/i,
|
|
|
+ /input \(\d+ tokens\) is longer than the model'?s context length \(\d+ tokens\)/i,
|
|
|
/exceeds the limit of \d+/i,
|
|
|
/exceeds the available context size/i,
|
|
|
/greater than the context length/i,
|
|
|
@@ -34,11 +38,17 @@ const patterns = [
|
|
|
/input length.*exceeds.*context length/i,
|
|
|
/prompt too long; exceeded (?:max )?context length/i,
|
|
|
/too large for model with \d+ maximum context length/i,
|
|
|
+ /prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,
|
|
|
/model_context_window_exceeded/i,
|
|
|
+ /too many tokens/i,
|
|
|
+ /token limit exceeded/i,
|
|
|
]
|
|
|
|
|
|
+const exclusions = [/^(throttling error|service unavailable):/i, /rate limit/i, /too many requests/i]
|
|
|
+
|
|
|
export const isContextOverflow = (message: string) =>
|
|
|
- patterns.some((pattern) => pattern.test(message)) || /^4(00|13)\s*(status code)?\s*\(no body\)/i.test(message)
|
|
|
+ !exclusions.some((pattern) => pattern.test(message)) &&
|
|
|
+ (patterns.some((pattern) => pattern.test(message)) || /^4(00|13)\s*(status code)?\s*\(no body\)/i.test(message))
|
|
|
|
|
|
export const isContextOverflowFailure = (failure: unknown) =>
|
|
|
failure instanceof LLMError
|