( promptTokens: number, contextLength: number | undefined )
| 7 | const clamp01 = (value: number): number => Math.min(1, Math.max(0, value)); |
| 8 | |
| 9 | export const getContextRatio = ( |
| 10 | promptTokens: number, |
| 11 | contextLength: number | undefined |
| 12 | ): number | undefined => { |
| 13 | if (contextLength === undefined || contextLength <= 0) { |
| 14 | return undefined; |
| 15 | } |
| 16 | |
| 17 | return clamp01(promptTokens / contextLength); |
| 18 | }; |
| 19 | |
| 20 | export const getContextTone = (ratio: number): 'danger' | 'safe' | 'warn' => { |
| 21 | if (ratio >= 0.9) { |
no test coverage detected