Skip to content

Commit 75678eb

Browse files
Nina KollmanNina Kollman
authored andcommitted
support evaluator name + verison
1 parent 711962a commit 75678eb

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

packages/sample-app/src/sample_experiment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ const main = async () => {
8686
experiment.run(medicalTaskRefuseAdvice, {
8787
datasetSlug: "medical-q",
8888
datasetVersion: "v1",
89-
evaluators: [{ name: "medical_advice" }],
90-
// experimentSlug: "medical-advice-exp-ts",
89+
evaluators: ["medical_advice"],
90+
experimentSlug: "medical-advice-exp-ts",
9191
stopOnError: false,
9292
waitForResults: true,
9393
});

packages/traceloop-sdk/src/lib/client/evaluator/evaluator.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,25 @@ export class Evaluator extends BaseDatasetEntity {
6767
throw new Error('experimentId, evaluator, and taskResult are required');
6868
}
6969

70-
if (!evaluator.name) {
71-
throw new Error('evaluator.name is required');
70+
// Handle both string and object evaluator types
71+
const evaluatorName = typeof evaluator === 'string' ? evaluator : evaluator.name;
72+
const evaluatorVersion = typeof evaluator === 'string' ? undefined : evaluator.version;
73+
74+
if (!evaluatorName) {
75+
throw new Error('evaluator name is required');
7276
}
7377

7478
const inputSchemaMapping = this.createInputSchemaMapping(taskResult);
7579

7680
const payload = {
7781
experiment_id: experimentId,
7882
experiment_run_id: experimentRunId,
79-
evaluator_version: evaluator.version,
83+
evaluator_version: evaluatorVersion,
8084
task_id: taskId,
8185
input_schema_mapping: inputSchemaMapping,
8286
};
8387

84-
const response = await this.client.post(`/v2/evaluators/slug/${evaluator.name}/execute`, payload);
88+
const response = await this.client.post(`/v2/evaluators/slug/${evaluatorName}/execute`, payload);
8589
const data = await this.handleResponse(response);
8690

8791
return {
@@ -169,9 +173,15 @@ export class Evaluator extends BaseDatasetEntity {
169173
throw new Error('At least one task result must be provided');
170174
}
171175

172-
// Validate each evaluator
173-
if (!evaluator.name || typeof evaluator.name !== 'string') {
174-
throw new Error(`Evaluator must have a valid name`);
176+
// Validate evaluator based on its type
177+
if (typeof evaluator === 'string') {
178+
if (!evaluator.trim()) {
179+
throw new Error('Evaluator name cannot be empty');
180+
}
181+
} else {
182+
if (!evaluator.name || typeof evaluator.name !== 'string' || !evaluator.name.trim()) {
183+
throw new Error('Evaluator must have a valid name');
184+
}
175185
}
176186

177187
// Validate each task result

packages/traceloop-sdk/src/lib/client/experiment/experiment.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,20 @@ export class Experiment {
272272

273273
if (options.evaluators) {
274274
options.evaluators.forEach((evaluator, index) => {
275-
if (!evaluator.name || typeof evaluator.name !== 'string') {
276-
throw new Error(`Evaluator at index ${index} must have a valid name`);
275+
if (typeof evaluator === 'string') {
276+
if (!evaluator.trim()) {
277+
throw new Error(`Evaluator at index ${index} cannot be an empty string`);
278+
}
279+
} else {
280+
if (!evaluator || typeof evaluator !== 'object') {
281+
throw new Error(`Evaluator at index ${index} must be a string or object with name and version`);
282+
}
283+
if (!evaluator.name || typeof evaluator.name !== 'string' || !evaluator.name.trim()) {
284+
throw new Error(`Evaluator at index ${index} must have a valid non-empty name`);
285+
}
286+
if (!evaluator.version || typeof evaluator.version !== 'string' || !evaluator.version.trim()) {
287+
throw new Error(`Evaluator at index ${index} must have a valid non-empty version`);
288+
}
277289
}
278290
});
279291
}

packages/traceloop-sdk/src/lib/interfaces/experiment.interface.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ export interface ExperimentTaskFunction<TInput = Record<string, any>, TOutput =
22
(input: TInput): Promise<TOutput> | TOutput;
33
}
44

5-
export interface EvaluatorDetails {
5+
export type EvaluatorDetails = string | EvaluatorWithVersion;
6+
7+
export interface EvaluatorWithVersion {
68
name: string;
7-
version?: string;
9+
version: string;
810
}
911

1012
export interface ExperimentRunOptions {

0 commit comments

Comments
 (0)