Skip to content

Commit bd9fc95

Browse files
committed
Fix evaluation issues with instructions
1 parent cdb04aa commit bd9fc95

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/resources/decorators.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,30 @@ export class Decorators extends APIResource {
178178
if (record.output) payload.output = record.output;
179179

180180
// Validate and include instructions if required by config
181-
if (config.instruction_adherence && !record.instructions) {
182-
throw new Error(
183-
"When instruction_adherence is specified in the config, 'instructions' must be present in the dataset"
184-
);
181+
if (config.instruction_adherence) {
182+
if (!record.instructions) {
183+
throw new Error(
184+
"When instruction_adherence is specified in the config, 'instructions' must be present in the dataset"
185+
);
186+
}
187+
188+
if (Array.isArray(record.instructions)) {
189+
payload.instructions = record.instructions;
190+
} else if (typeof record.instructions === "string") {
191+
try {
192+
const parsed = JSON.parse(record.instructions);
193+
payload.instructions = Array.isArray(parsed)
194+
? parsed
195+
: [record.instructions];
196+
} catch {
197+
// If it's not valid JSON, treat the string as a single instruction
198+
payload.instructions = [record.instructions];
199+
}
200+
} else {
201+
throw new Error(
202+
"'instructions' must be a string or array of strings"
203+
);
204+
}
185205
}
186206

187207
// Validate and include task definition if required by config
@@ -191,10 +211,6 @@ export class Decorators extends APIResource {
191211
);
192212
}
193213

194-
if (record.instructions && config.instruction_adherence) {
195-
payload.instructions = record.instructions || "";
196-
}
197-
198214
if (record.task_definition && config.retrieval_relevance) {
199215
payload.task_definition = record.task_definition || "";
200216
}

0 commit comments

Comments
 (0)