Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added batch execution logic in auto evaluations #1071

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ const ABTestingEvaluationTable: React.FC<EvaluationTableProps> = ({

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!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -220,7 +220,7 @@ const CustomCodeRunEvaluationTable: React.FC<CustomCodeEvaluationTableProps> = (
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -162,13 +163,8 @@ const ExactMatchEvaluationTable: React.FC<ExactMatchEvaluationTableProps> = ({

const runAllEvaluations = async () => {
setEvaluationStatus(EvaluationFlow.EVALUATION_STARTED)
const promises: Promise<void>[] = []

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -182,13 +183,7 @@ const RegexEvaluationTable: React.FC<RegexEvaluationTableProps> = ({
showError.current = true

const {regexPattern, regexShouldMatch} = form.getFieldsValue()
const promises: Promise<void>[] = []

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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -182,13 +183,7 @@ const SimilarityMatchEvaluationTable: React.FC<SimilarityMatchEvaluationTablePro
}

const {similarityThreshold} = form.getFieldsValue()
const promises: Promise<void>[] = []

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,7 @@ const SingleModelEvaluationTable: React.FC<EvaluationTableProps> = ({

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!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -162,13 +163,7 @@ const WebhookEvaluationTable: React.FC<WebhookEvaluationTableProps> = ({
showError.current = true

const {webhookUrl} = form.getFieldsValue()
const promises: Promise<void>[] = []

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: {
Expand Down
2 changes: 1 addition & 1 deletion agenta-web/src/components/Playground/Views/TestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const App: React.FC<TestViewProps> = ({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 = () => {
Expand Down
4 changes: 2 additions & 2 deletions agenta-web/src/lib/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}

Expand Down
Loading