| 1 | import { ILLM } from "../.."; |
| 2 | import { countTokensAsync } from "../../llm/countTokens"; |
| 3 | |
| 4 | export async function throwIfFileExceedsHalfOfContext( |
| 5 | filepath: string, |
| 6 | content: string, |
| 7 | model: ILLM | null, |
| 8 | ) { |
| 9 | if (model) { |
| 10 | const tokens = await countTokensAsync(content, model.title); |
| 11 | const tokenLimit = model.contextLength / 2; |
| 12 | if (tokens > tokenLimit) { |
| 13 | throw new Error( |
| 14 | `File ${filepath} is too large (${tokens} tokens vs ${tokenLimit} token limit). Try another approach`, |
| 15 | ); |
| 16 | } |
| 17 | } |
| 18 | } |