Skip to content

Commit

Permalink
feat: added total_time response element
Browse files Browse the repository at this point in the history
  • Loading branch information
samestrin committed Jul 17, 2024
1 parent c2f2b9d commit 44e5cba
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/retryWithBackoff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SendMessageError, EmbeddingsError } = require('./errors.js');
const { delay } = require('./utils.js');
const { hrtime } = require('process');
const log = require('loglevel');
log.setLevel(log.levels.SILENT);

Expand All @@ -14,6 +15,7 @@ log.setLevel(log.levels.SILENT);
* @throws {SendMessageError|EmbeddingsError} - Throws an error if all retry attempts fail.
*/
async function retryWithBackoff(fn, options, errorType) {
const start = hrtime();
let { retryAttempts = 3, retryMultiplier = 0.3 } = options;
let currentRetry = 0;

Expand All @@ -22,6 +24,9 @@ async function retryWithBackoff(fn, options, errorType) {
log.log(`retryWithBackoff:${retryAttempts}`);
let response = await fn();
if (response?.results) {
const end = hrtime(start);
const milliseconds = end[0] * 1e3 + end[1] / 1e6;
response.total_time = milliseconds.toFixed(5);
return response;
}
} catch (error) {
Expand Down

0 comments on commit 44e5cba

Please sign in to comment.