kpfadnis commited on
Commit
bde7974
·
1 Parent(s): b9bcfa6

fix (validator): Fix input file validator for 'chat' task.

Browse files
Files changed (1) hide show
  1. src/validators.ts +18 -13
src/validators.ts CHANGED
@@ -106,7 +106,7 @@ function isValidTask(task): boolean {
106
  return false;
107
  }
108
 
109
- if (!task.hasOwnProperty('contexts')) {
110
  return false;
111
  }
112
 
@@ -151,33 +151,38 @@ export function validateInputData(data): { valid: boolean; reasons: string[] } {
151
  );
152
  }
153
 
154
- // Step : Validate documents releated requirements
155
- if (!data.hasOwnProperty('documents')) {
156
  valid = false;
157
- reasons.push("Missing mandatory 'documents' information.");
158
  }
159
  if (
160
- data.hasOwnProperty('documents') &&
161
- !data.documents.every((document) => isValidDocument(document))
162
  ) {
163
  valid = false;
164
  reasons.push(
165
- "One or more documents are incorrectly specified. Please refer to 'sample.json' on the format for a document.",
166
  );
167
  }
168
 
169
- // Step : Validate tasks releated requirements
170
- if (!data.hasOwnProperty('tasks')) {
 
 
 
171
  valid = false;
172
- reasons.push("Missing mandatory 'tasks' information.");
 
 
173
  }
174
  if (
175
- data.hasOwnProperty('tasks') &&
176
- !data.tasks.every((task) => isValidTask(task))
177
  ) {
178
  valid = false;
179
  reasons.push(
180
- "One or more tasks are incorrectly specified. Please refer to 'sample.json' on the format for a task.",
181
  );
182
  }
183
 
 
106
  return false;
107
  }
108
 
109
+ if (task.taskType === 'rag' && !task.hasOwnProperty('contexts')) {
110
  return false;
111
  }
112
 
 
151
  );
152
  }
153
 
154
+ // Step : Validate tasks releated requirements
155
+ if (!data.hasOwnProperty('tasks')) {
156
  valid = false;
157
+ reasons.push("Missing mandatory 'tasks' information.");
158
  }
159
  if (
160
+ data.hasOwnProperty('tasks') &&
161
+ !data.tasks.every((task) => isValidTask(task))
162
  ) {
163
  valid = false;
164
  reasons.push(
165
+ "One or more tasks are incorrectly specified. Please refer to 'sample.json' on the format for a task.",
166
  );
167
  }
168
 
169
+ // Step : Validate documents releated requirements
170
+ if (
171
+ data.tasks.some((task) => task.taskType === 'rag') &&
172
+ !data.hasOwnProperty('documents')
173
+ ) {
174
  valid = false;
175
+ reasons.push(
176
+ "Missing mandatory 'documents' information when `rag` type tasks are included.",
177
+ );
178
  }
179
  if (
180
+ data.hasOwnProperty('documents') &&
181
+ !data.documents.every((document) => isValidDocument(document))
182
  ) {
183
  valid = false;
184
  reasons.push(
185
+ "One or more documents are incorrectly specified. Please refer to 'sample.json' on the format for a document.",
186
  );
187
  }
188