Skip to content

Commit 95a26ae

Browse files
christopherholland-workdaychristopherholland-workday
andauthored
Revert loop bound changes (#5848)
Co-authored-by: christopherholland-workday <christopher.holland+evisort@workday.com>
1 parent 0cbdb25 commit 95a26ae

3 files changed

Lines changed: 5 additions & 47 deletions

File tree

packages/components/evaluation/EvaluationRunner.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ export class EvaluationRunner {
8888

8989
public async runEvaluations(data: ICommonObject) {
9090
const chatflowIds = JSON.parse(data.chatflowId)
91-
92-
// Validate chatflowIds is an actual array to prevent DoS attacks
93-
if (!Array.isArray(chatflowIds)) {
94-
throw new Error('chatflowId must be a valid array')
95-
}
96-
97-
// Validate dataset.rows is an actual array to prevent DoS attacks
98-
if (!data.dataset || !Array.isArray(data.dataset.rows)) {
99-
throw new Error('dataset.rows must be a valid array')
100-
}
101-
10291
const returnData: ICommonObject = {}
10392
returnData.evaluationId = data.evaluationId
10493
returnData.runDate = new Date()

packages/server/src/services/evaluations/EvaluatorRunner.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ export const runAdditionalEvaluators = async (
1717
selectedEvaluators: string[],
1818
workspaceId: string
1919
) => {
20-
// Validate inputs are arrays and enforce size limits
21-
if (!Array.isArray(actualOutputArray) || !Array.isArray(selectedEvaluators)) {
22-
throw new Error('Invalid input: expected arrays')
23-
}
24-
2520
const evaluationResults: any[] = []
2621
const evaluatorDict: any = {}
2722

@@ -108,7 +103,6 @@ export const runAdditionalEvaluators = async (
108103
case 'ContainsAny':
109104
passed = false
110105
splitValues = value.split(',').map((v) => v.trim().toLowerCase()) // Split, trim, and convert to lowercase
111-
112106
for (let i = 0; i < splitValues.length; i++) {
113107
if (actualOutput.includes(splitValues[i])) {
114108
passed = true
@@ -123,7 +117,6 @@ export const runAdditionalEvaluators = async (
123117
case 'ContainsAll':
124118
passed = true
125119
splitValues = value.split(',').map((v) => v.trim().toLowerCase()) // Split, trim, and convert to lowercase
126-
127120
for (let i = 0; i < splitValues.length; i++) {
128121
if (!actualOutput.includes(splitValues[i])) {
129122
passed = false
@@ -138,7 +131,6 @@ export const runAdditionalEvaluators = async (
138131
case 'DoesNotContainAny':
139132
passed = true
140133
splitValues = value.split(',').map((v) => v.trim().toLowerCase()) // Split, trim, and convert to lowercase
141-
142134
for (let i = 0; i < splitValues.length; i++) {
143135
if (actualOutput.includes(splitValues[i])) {
144136
passed = false
@@ -153,7 +145,6 @@ export const runAdditionalEvaluators = async (
153145
case 'DoesNotContainAll':
154146
passed = true
155147
splitValues = value.split(',').map((v) => v.trim().toLowerCase()) // Split, trim, and convert to lowercase
156-
157148
for (let i = 0; i < splitValues.length; i++) {
158149
if (actualOutput.includes(splitValues[i])) {
159150
passed = false

packages/server/src/services/evaluations/index.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,14 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str
7272
const row = appServer.AppDataSource.getRepository(Evaluation).create(newEval)
7373
row.average_metrics = JSON.stringify({})
7474

75-
// Parse and validate evaluator arrays to prevent DoS attacks
76-
const chatflowTypes = body.chatflowType ? JSON.parse(body.chatflowType) : []
77-
if (!Array.isArray(chatflowTypes)) {
78-
throw new Error('chatflowType must be a valid array')
79-
}
80-
81-
const simpleEvaluators = body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : []
82-
if (!Array.isArray(simpleEvaluators)) {
83-
throw new Error('selectedSimpleEvaluators must be a valid array')
84-
}
85-
8675
const additionalConfig: ICommonObject = {
87-
chatflowTypes: chatflowTypes,
76+
chatflowTypes: body.chatflowType ? JSON.parse(body.chatflowType) : [],
8877
datasetAsOneConversation: body.datasetAsOneConversation,
89-
simpleEvaluators: simpleEvaluators
78+
simpleEvaluators: body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : []
9079
}
9180

9281
if (body.evaluationType === 'llm') {
93-
const lLMEvaluators = body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : []
94-
if (!Array.isArray(lLMEvaluators)) {
95-
throw new Error('selectedLLMEvaluators must be a valid array')
96-
}
97-
98-
additionalConfig.lLMEvaluators = lLMEvaluators
82+
additionalConfig.lLMEvaluators = body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : []
9983
additionalConfig.llmConfig = {
10084
credentialId: body.credentialId,
10185
llm: body.llm,
@@ -139,12 +123,6 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str
139123
// When chatflow has an APIKey
140124
const apiKeys: { chatflowId: string; apiKey: string }[] = []
141125
const chatflowIds = JSON.parse(body.chatflowId)
142-
143-
// Validate chatflowIds is an actual array to prevent DoS attacks
144-
if (!Array.isArray(chatflowIds)) {
145-
throw new Error('chatflowId must be a valid array')
146-
}
147-
148126
for (let i = 0; i < chatflowIds.length; i++) {
149127
const chatflowId = chatflowIds[i]
150128
const cFlow = await appServer.AppDataSource.getRepository(ChatFlow).findOneBy({
@@ -268,7 +246,7 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str
268246
metricsArray,
269247
actualOutputArray,
270248
errorArray,
271-
additionalConfig.simpleEvaluators,
249+
body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : [],
272250
workspaceId
273251
)
274252

@@ -279,7 +257,7 @@ const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: str
279257

280258
if (body.evaluationType === 'llm') {
281259
resultRow.llmConfig = additionalConfig.llmConfig
282-
resultRow.LLMEvaluators = additionalConfig.lLMEvaluators
260+
resultRow.LLMEvaluators = body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : []
283261
const llmEvaluatorMap: { evaluatorId: string; evaluator: any }[] = []
284262
for (let i = 0; i < resultRow.LLMEvaluators.length; i++) {
285263
const evaluatorId = resultRow.LLMEvaluators[i]

0 commit comments

Comments
 (0)