Skip to content

Commit

Permalink
Manually define names
Browse files Browse the repository at this point in the history
  • Loading branch information
ankrgyl committed Dec 18, 2023
1 parent 77bef21 commit 22b4942
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions js/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export const JSONDiff: Scorer<
};
};

Object.defineProperty(JSONDiff, "name", {
value: "JSONDiff",
configurable: true,
});

async function jsonDiff(
o1: any,
o2: any,
Expand Down
5 changes: 5 additions & 0 deletions js/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ export const NumericDiff: Scorer<number, {}> = (args) => {
score,
};
};

Object.defineProperty(NumericDiff, "name", {
value: "NumericDiff",
configurable: true,
});
18 changes: 16 additions & 2 deletions js/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ export const Levenshtein: Scorer<string, {}> = (args) => {
score,
};
};
Object.defineProperty(Levenshtein, "name", {
value: "Levenshtein",
configurable: true,
});

// For back-compat
export const LevenshteinScorer: Scorer<string, {}> = (args) => {
return Levenshtein(args);
};

Object.defineProperty(LevenshteinScorer, "name", {
value: "LevenshteinScorer",
configurable: true,
});

/**
* A scorer that uses cosine similarity to compare two strings.
*
Expand Down Expand Up @@ -80,12 +89,17 @@ export const EmbeddingSimilarity: Scorer<
);

return {
name: "EmbeddingDistance",
name: "EmbeddingSimilarity",
score: scaleScore(score ?? 0, expectedMin),
error: score === null ? "EmbeddingDistance failed" : undefined,
error: score === null ? "EmbeddingSimilarity failed" : undefined,
};
};

Object.defineProperty(EmbeddingSimilarity, "name", {
value: "EmbeddingSimilarity",
configurable: true,
});

function scaleScore(score: number, expectedMin: number): number {
return Math.max((score - expectedMin) / (1 - expectedMin), 0);
}
Expand Down

0 comments on commit 22b4942

Please sign in to comment.