@@ -3,13 +3,17 @@ import { LLMError, ProviderErrorEvent } from "./schema"
33
44const patterns = [
55 / p r o m p t i s t o o l o n g / i,
6+ / r e q u e s t _ t o o _ l a r g e / i,
67 / i n p u t i s t o o l o n g f o r r e q u e s t e d m o d e l / i,
78 / e x c e e d s t h e c o n t e x t w i n d o w / i,
9+ / e x c e e d s (?: t h e ) ? (?: m o d e l ' ? s ) ? m a x i m u m c o n t e x t l e n g t h (?: o f [ \d , ] + t o k e n s ? | \s * \( [ \d , ] + \) ) / i,
810 / i n p u t t o k e n c o u n t .* e x c e e d s t h e m a x i m u m / i,
911 / t o k e n s i n r e q u e s t m o r e t h a n m a x t o k e n s a l l o w e d / i,
1012 / m a x i m u m p r o m p t l e n g t h i s \d + / i,
1113 / r e d u c e t h e l e n g t h o f t h e m e s s a g e s / i,
1214 / m a x i m u m c o n t e x t l e n g t h i s \d + t o k e n s / i,
15+ / e x c e e d s (?: t h e ) ? m a x i m u m a l l o w e d i n p u t l e n g t h o f [ \d , ] + t o k e n s ? / i,
16+ / i n p u t \( \d + t o k e n s \) i s l o n g e r t h a n t h e m o d e l ' ? s c o n t e x t l e n g t h \( \d + t o k e n s \) / i,
1317 / e x c e e d s t h e l i m i t o f \d + / i,
1418 / e x c e e d s t h e a v a i l a b l e c o n t e x t s i z e / i,
1519 / g r e a t e r t h a n t h e c o n t e x t l e n g t h / i,
@@ -21,11 +25,17 @@ const patterns = [
2125 / i n p u t l e n g t h .* e x c e e d s .* c o n t e x t l e n g t h / i,
2226 / p r o m p t t o o l o n g ; e x c e e d e d (?: m a x ) ? c o n t e x t l e n g t h / i,
2327 / t o o l a r g e f o r m o d e l w i t h \d + m a x i m u m c o n t e x t l e n g t h / i,
28+ / p r o m p t h a s [ \d , ] + t o k e n s ? , b u t t h e c o n f i g u r e d c o n t e x t s i z e i s [ \d , ] + t o k e n s ? / i,
2429 / m o d e l _ c o n t e x t _ w i n d o w _ e x c e e d e d / i,
30+ / t o o m a n y t o k e n s / i,
31+ / t o k e n l i m i t e x c e e d e d / i,
2532]
2633
34+ const exclusions = [ / ^ ( t h r o t t l i n g e r r o r | s e r v i c e u n a v a i l a b l e ) : / i, / r a t e l i m i t / i, / t o o m a n y r e q u e s t s / i]
35+
2736export const isContextOverflow = ( message : string ) =>
28- patterns . some ( ( pattern ) => pattern . test ( message ) ) || / ^ 4 ( 0 0 | 1 3 ) \s * ( s t a t u s c o d e ) ? \s * \( n o b o d y \) / i. test ( message )
37+ ! exclusions . some ( ( pattern ) => pattern . test ( message ) ) &&
38+ ( patterns . some ( ( pattern ) => pattern . test ( message ) ) || / ^ 4 ( 0 0 | 1 3 ) \s * ( s t a t u s c o d e ) ? \s * \( n o b o d y \) / i. test ( message ) )
2939
3040export const isContextOverflowFailure = ( failure : unknown ) =>
3141 failure instanceof LLMError
0 commit comments