diff --git a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx index 83c7fdda0d..163e490af8 100644 --- a/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ABTestingEvaluationTable.tsx @@ -200,10 +200,7 @@ const ABTestingEvaluationTable: React.FC = ({ const runAllEvaluations = async () => { setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED) - batchExecute( - rows.map((row) => () => runEvaluation(row.id!, rows.length - 1, false)), - {allowRetry: true, batchSize: 10}, - ) + batchExecute(rows.map((row) => () => runEvaluation(row.id!, rows.length - 1, false))) .then(() => { setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED) message.success("Evaluations Updated!") diff --git a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx index 0c46619d43..3034fb7787 100644 --- a/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/AICritiqueEvaluationTable.tsx @@ -26,7 +26,7 @@ import { import {useVariants} from "@/lib/hooks/useVariant" import {useRouter} from "next/router" import {EvaluationFlow, EvaluationType} from "@/lib/enums" -import {getApikeys} from "@/lib/helpers/utils" +import {batchExecute, getApikeys} from "@/lib/helpers/utils" import {createUseStyles} from "react-jss" import {exportAICritiqueEvaluationData} from "@/lib/helpers/evaluate" import SecondaryButton from "../SecondaryButton/SecondaryButton" @@ -225,7 +225,7 @@ Answer ONLY with one of the given grading or evaluation options. const runAllEvaluations = async () => { try { setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED) - await Promise.all(rows.map((_, rowIndex) => runEvaluation(rowIndex))) + await batchExecute(rows.map((_, rowIndex) => () => runEvaluation(rowIndex))) setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED) console.log("All evaluations finished.") } catch (err) { diff --git a/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx index eeb8fd2c5e..711321cf82 100644 --- a/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/CustomCodeRunEvaluationTable.tsx @@ -30,7 +30,7 @@ import { import {useVariants} from "@/lib/hooks/useVariant" import {useRouter} from "next/router" import {EvaluationFlow, EvaluationType} from "@/lib/enums" -import {getApikeys} from "@/lib/helpers/utils" +import {batchExecute, getApikeys} from "@/lib/helpers/utils" import {createUseStyles} from "react-jss" import SecondaryButton from "../SecondaryButton/SecondaryButton" import {exportCustomCodeEvaluationData} from "@/lib/helpers/evaluate" @@ -220,7 +220,7 @@ const CustomCodeRunEvaluationTable: React.FC = ( const runAllEvaluations = async () => { try { setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED) - await Promise.all(rows.map((_, rowIndex) => runEvaluation(rowIndex))) + await batchExecute(rows.map((_, rowIndex) => () => runEvaluation(rowIndex))) setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED) console.log("All evaluations finished.") } catch (err) { diff --git a/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx index 7c038fff7d..7f80ba22b4 100644 --- a/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/ExactMatchEvaluationTable.tsx @@ -31,6 +31,7 @@ import SecondaryButton from "../SecondaryButton/SecondaryButton" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" import {Evaluation} from "@/lib/Types" import ParamsForm from "../Playground/ParamsForm/ParamsForm" +import {batchExecute} from "@/lib/helpers/utils" const {Title} = Typography @@ -162,13 +163,8 @@ const ExactMatchEvaluationTable: React.FC = ({ const runAllEvaluations = async () => { setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED) - const promises: Promise[] = [] - for (let i = 0; i < rows.length; i++) { - promises.push(runEvaluation(i)) - } - - Promise.all(promises) + batchExecute(rows.map((_, rowIndex) => () => runEvaluation(rowIndex))) .then(() => { console.log("All functions finished.") setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED) diff --git a/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx index 996e4b68fa..baa31e5dd5 100644 --- a/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/RegexEvaluationTable.tsx @@ -31,6 +31,7 @@ import {exportRegexEvaluationData} from "@/lib/helpers/evaluate" import {isValidRegex} from "@/lib/helpers/validators" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" import ParamsForm from "../Playground/ParamsForm/ParamsForm" +import {batchExecute} from "@/lib/helpers/utils" const {Title} = Typography @@ -182,13 +183,7 @@ const RegexEvaluationTable: React.FC = ({ showError.current = true const {regexPattern, regexShouldMatch} = form.getFieldsValue() - const promises: Promise[] = [] - - for (let i = 0; i < rows.length; i++) { - promises.push(runEvaluation(i)) - } - - Promise.all(promises) + batchExecute(rows.map((_, rowIndex) => () => runEvaluation(rowIndex))) .then(() => { updateEvaluation(evaluation.id, { evaluation_type_settings: { diff --git a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx index c1cce3b59f..1e294efb83 100644 --- a/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SimilarityMatchEvaluationTable.tsx @@ -26,6 +26,7 @@ import {exportSimilarityEvaluationData} from "@/lib/helpers/evaluate" import SecondaryButton from "../SecondaryButton/SecondaryButton" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" import ParamsForm from "../Playground/ParamsForm/ParamsForm" +import {batchExecute} from "@/lib/helpers/utils" const {Title} = Typography @@ -182,13 +183,7 @@ const SimilarityMatchEvaluationTable: React.FC[] = [] - - for (let i = 0; i < rows.length; i++) { - promises.push(runEvaluation(i)) - } - - Promise.all(promises).then(() => { + batchExecute(rows.map((_, rowIndex) => () => runEvaluation(rowIndex))).then(() => { updateEvaluation(evaluation.id, { evaluation_type_settings: { similarity_threshold: similarityThreshold, diff --git a/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx index 77bc9ebb4c..679e0b2fd8 100644 --- a/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/SingleModelEvaluationTable.tsx @@ -260,10 +260,7 @@ const SingleModelEvaluationTable: React.FC = ({ const runAllEvaluations = async () => { setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED) - batchExecute( - rows.map((row) => () => runEvaluation(row.id!, rows.length - 1, false)), - {allowRetry: true, batchSize: 10}, - ) + batchExecute(rows.map((row) => () => runEvaluation(row.id!, rows.length - 1, false))) .then(() => { setEvaluationStatus(EvaluationFlow.EVALUATION_FINISHED) message.success("Evaluations Updated!") diff --git a/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx b/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx index cf7776838f..cd3979f81c 100644 --- a/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx +++ b/agenta-web/src/components/EvaluationTable/WebhookEvaluationTable.tsx @@ -30,6 +30,7 @@ import SecondaryButton from "../SecondaryButton/SecondaryButton" import {exportWebhookEvaluationData} from "@/lib/helpers/evaluate" import {contentToChatMessageString, testsetRowToChatMessages} from "@/lib/helpers/testset" import ParamsForm from "../Playground/ParamsForm/ParamsForm" +import {batchExecute} from "@/lib/helpers/utils" const {Title} = Typography @@ -162,13 +163,7 @@ const WebhookEvaluationTable: React.FC = ({ showError.current = true const {webhookUrl} = form.getFieldsValue() - const promises: Promise[] = [] - - for (let i = 0; i < rows.length; i++) { - promises.push(runEvaluation(i)) - } - - Promise.all(promises) + batchExecute(rows.map((_, rowIndex) => () => runEvaluation(rowIndex))) .then(() => { updateEvaluation(evaluation.id, { evaluation_type_settings: { diff --git a/agenta-web/src/components/Playground/Views/TestView.tsx b/agenta-web/src/components/Playground/Views/TestView.tsx index fd542a6de2..cd0fe16951 100644 --- a/agenta-web/src/components/Playground/Views/TestView.tsx +++ b/agenta-web/src/components/Playground/Views/TestView.tsx @@ -283,7 +283,7 @@ const App: React.FC = ({inputParams, optParams, variant, isChatVa ?.querySelectorAll("[data-cy=testview-input-parameters-run-button]") .forEach((btn) => funcs.push(() => (btn as HTMLButtonElement).click())) - batchExecute(funcs, {allowRetry: true, batchSize: 10}) + batchExecute(funcs) } const handleAddRow = () => { diff --git a/agenta-web/src/lib/helpers/utils.ts b/agenta-web/src/lib/helpers/utils.ts index 7b02123a95..79aa0e82ed 100644 --- a/agenta-web/src/lib/helpers/utils.ts +++ b/agenta-web/src/lib/helpers/utils.ts @@ -263,11 +263,11 @@ export async function batchExecute( }, ) { const { - batchSize = 20, + batchSize = 10, supressErrors = false, batchDelayMs = 2000, logErrors = true, - allowRetry = false, + allowRetry = true, retryConfig, } = options || {}