(body: ICommonObject, baseURL: string, orgId: string, workspaceId: string)
| 64 | } |
| 65 | |
| 66 | const createEvaluation = async (body: ICommonObject, baseURL: string, orgId: string, workspaceId: string) => { |
| 67 | try { |
| 68 | const appServer = getRunningExpressApp() |
| 69 | const newEval = new Evaluation() |
| 70 | Object.assign(newEval, stripProtectedFields(body)) |
| 71 | newEval.workspaceId = workspaceId |
| 72 | newEval.status = EvaluationStatus.PENDING |
| 73 | |
| 74 | const row = appServer.AppDataSource.getRepository(Evaluation).create(newEval) |
| 75 | row.average_metrics = JSON.stringify({}) |
| 76 | |
| 77 | const chatflowTypes = body.chatflowType ? JSON.parse(body.chatflowType) : [] |
| 78 | if (!Array.isArray(chatflowTypes)) { |
| 79 | throw new Error('chatflowType must be a valid array') |
| 80 | } |
| 81 | |
| 82 | const simpleEvaluators = |
| 83 | body.selectedSimpleEvaluators && body.selectedSimpleEvaluators.length > 0 ? JSON.parse(body.selectedSimpleEvaluators) : [] |
| 84 | if (!Array.isArray(simpleEvaluators)) { |
| 85 | throw new Error('selectedSimpleEvaluators must be a valid array') |
| 86 | } |
| 87 | |
| 88 | const additionalConfig: ICommonObject = { |
| 89 | chatflowTypes: chatflowTypes, |
| 90 | datasetAsOneConversation: body.datasetAsOneConversation, |
| 91 | simpleEvaluators: simpleEvaluators |
| 92 | } |
| 93 | |
| 94 | if (body.evaluationType === 'llm') { |
| 95 | const lLMEvaluators = |
| 96 | body.selectedLLMEvaluators && body.selectedLLMEvaluators.length > 0 ? JSON.parse(body.selectedLLMEvaluators) : [] |
| 97 | |
| 98 | if (!Array.isArray(lLMEvaluators)) { |
| 99 | throw new Error('selectedLLMEvaluators must be a valid array') |
| 100 | } |
| 101 | |
| 102 | additionalConfig.lLMEvaluators = lLMEvaluators |
| 103 | additionalConfig.llmConfig = { |
| 104 | credentialId: body.credentialId, |
| 105 | llm: body.llm, |
| 106 | model: body.model |
| 107 | } |
| 108 | } |
| 109 | row.additionalConfig = JSON.stringify(additionalConfig) |
| 110 | const newEvaluation = await appServer.AppDataSource.getRepository(Evaluation).save(row) |
| 111 | |
| 112 | await appServer.telemetry.sendTelemetry( |
| 113 | 'evaluation_created', |
| 114 | { |
| 115 | version: await getAppVersion() |
| 116 | }, |
| 117 | orgId |
| 118 | ) |
| 119 | |
| 120 | const dataset = await appServer.AppDataSource.getRepository(Dataset).findOneBy({ |
| 121 | id: body.datasetId, |
| 122 | workspaceId: workspaceId |
| 123 | }) |
no test coverage detected