Skip to content

Commit

Permalink
Merge pull request #8 from parea-ai/add-helpers-ts
Browse files Browse the repository at this point in the history
feat(client): add helpers
  • Loading branch information
jalexanderII authored Jan 29, 2024
2 parents c0770ac + 80407e4 commit ee94dcb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,26 @@ export type TraceStatsSchema = {
scores?: EvaluationScoreSchema[];
};

export type ExperimentStatsSchema = {
parent_trace_stats: TraceStatsSchema[];
};

export type DataItem = {
[key: string]: any;
};

export class ExperimentStatsSchema {
parent_trace_stats: TraceStatsSchema[];

constructor(parent_trace_stats: TraceStatsSchema[]) {
this.parent_trace_stats = parent_trace_stats;
}

cumulativeAvgScore(): number {
const scores = this.parent_trace_stats.flatMap((traceStat) => traceStat.scores?.map((score) => score.score) || []);
return scores.length > 0 ? scores.reduce((acc, curr) => acc + curr, 0) / scores.length : 0.0;
}

avgScore(scoreName: string): number {
const scores = this.parent_trace_stats.flatMap(
(traceStat) => traceStat.scores?.filter((score) => score.name === scoreName).map((score) => score.score) || [],
);
return scores.length > 0 ? scores.reduce((acc, curr) => acc + curr, 0) / scores.length : 0.0;
}
}

0 comments on commit ee94dcb

Please sign in to comment.