Replace token estimation with using last API response token usage

This commit is contained in:
Saoud Rizwan
2024-08-30 22:29:18 -04:00
parent dcd6d84632
commit 3e58160d99
6 changed files with 28 additions and 140 deletions

View File

@@ -15,3 +15,8 @@ export function findLastIndex<T>(array: Array<T>, predicate: (value: T, index: n
}
return -1
}
export function findLast<T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): T | undefined {
const index = findLastIndex(array, predicate)
return index === -1 ? undefined : array[index]
}