(
systemPrompt?: string,
context?: string,
messages?: Array<{ role: string; content: string }>,
providerId?: string
)
| 309 | * Estimates tokens for input content including context |
| 310 | */ |
| 311 | export function estimateInputTokens( |
| 312 | systemPrompt?: string, |
| 313 | context?: string, |
| 314 | messages?: Array<{ role: string; content: string }>, |
| 315 | providerId?: string |
| 316 | ): TokenEstimate { |
| 317 | let totalText = '' |
| 318 | |
| 319 | if (systemPrompt) { |
| 320 | totalText += `${systemPrompt}\n` |
| 321 | } |
| 322 | |
| 323 | if (context) { |
| 324 | totalText += `${context}\n` |
| 325 | } |
| 326 | |
| 327 | if (messages) { |
| 328 | for (const message of messages) { |
| 329 | totalText += `${message.role}: ${message.content}\n` |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | return estimateTokenCount(totalText, providerId) |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Estimates tokens for output content |
no test coverage detected