Skip to content

Commit

Permalink
Update - introduce sequential requests handling in ab testing and sin…
Browse files Browse the repository at this point in the history
…gle model evaluation
  • Loading branch information
aybruhm committed Dec 6, 2023
1 parent 1676915 commit 9d9c981
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,72 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({
.catch(console.error)
}

const runEvaluationWithRetry = async (
id: string,
count: number = 1,
showNotification: boolean = true,
maxRetryCount: number,
retryDelay: number
) => {
let retryCount = 0
while (retryCount <= maxRetryCount) {
try {
await runEvaluation(id, count, showNotification)
// If the evaluation is successful, break out of the retry loop
break;
} catch (error) {
console.error(`Error in evaluation for ID ${id}, retrying...`)
retryCount++
if (retryCount <= maxRetryCount) {
// Add a delay before retrying
await delay(retryDelay)
} else {
console.error(`Max retry count reached for evaluation ID ${id}.`)
// Handle the failure after max retries (if needed)
}
}
}
}

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))

const runAllEvaluations = async () => {
const batchSize = 10 // Number of evaluations to make in each batch
const maxRetryCount = 3 // Maximum number of times to retry a failed evaluation
const retryDelay = 3000 // Delay before retrying a failed evaluation (in milliseconds)
const delayBetweenBatches = 5000 // Delay between batches (in milliseconds)

setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED)
Promise.all(rows.map((row) => runEvaluation(row.id!, rows.length - 1, false)))
.then(() => {
const runBatch = async (startIdx) => {
const endIdx = Math.min(startIdx + batchSize, rows.length)
const batchPromises = []

for (let index = startIdx; index < endIdx; index++) {
batchPromises.push(
runEvaluationWithRetry(rows[index].id!, rows.length - 1, false, maxRetryCount, retryDelay)
)
}

try {
await Promise.all(batchPromises)
} catch (err) {
console.error("Error in batch:", err)
// Handle the failure of the entire batch (if needed)
}

// Schedule the next batch with a delay
const nextBatchStartIdx = endIdx
if (nextBatchStartIdx < rows.length) {
setTimeout(() => runBatch(nextBatchStartIdx), delayBetweenBatches)
} else {
// All batches completed
setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED)
message.success("Evaluations Updated!")
})
.catch((err) => console.error("An error occurred:", err))
}
}

// Start the first batch
runBatch(0)
}

const runEvaluation = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,76 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({
.catch(console.error)
}

const runEvaluationWithRetry = async (
id: string,
count: number = 1,
showNotification: boolean = true,
maxRetryCount: number,
retryDelay: number
) => {
let retryCount = 0
while (retryCount <= maxRetryCount) {
try {
await runEvaluation(id, count, showNotification)
// If the evaluation is successful, break out of the retry loop
break;
} catch (error) {
console.error(`Error in evaluation for ID ${id}, retrying...`)
retryCount++
if (retryCount <= maxRetryCount) {
// Add a delay before retrying
await delay(retryDelay)
} else {
console.error(`Max retry count reached for evaluation ID ${id}.`)
// Handle the failure after max retries (if needed)
}
}
}
}

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))

const runAllEvaluations = async () => {
const batchSize = 10 // Number of evaluations to make in each batch
const maxRetryCount = 3 // Maximum number of times to retry a failed evaluation
const retryDelay = 3000 // Delay before retrying a failed evaluation (in milliseconds)
const delayBetweenBatches = 5000 // Delay between batches (in milliseconds)

setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED)
Promise.all(rows.map((row) => runEvaluation(row.id!, rows.length - 1, false)))
.then(() => {
const runBatch = async (startIdx) => {
const endIdx = Math.min(startIdx + batchSize, rows.length)
const batchPromises = []

for (let index = startIdx; index < endIdx; index++) {
batchPromises.push(
runEvaluationWithRetry(rows[index].id!, rows.length - 1, false, maxRetryCount, retryDelay)
)
}

try {
await Promise.all(batchPromises)
} catch (err) {
console.error("Error in batch:", err)
// Handle the failure of the entire batch (if needed)
}

// Schedule the next batch with a delay
const nextBatchStartIdx = endIdx
if (nextBatchStartIdx < rows.length) {
setTimeout(() => runBatch(nextBatchStartIdx), delayBetweenBatches)
} else {
// All batches completed
setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED)
message.success("Evaluations Updated!")
})
.catch((err) => console.error("An error occurred:", err))
}
}

// Start the first batch
runBatch(0)
}



const runEvaluation = async (
id: string,
count: number = 1,
Expand Down

0 comments on commit 9d9c981

Please sign in to comment.