Skip to content

Commit

Permalink
fix(anonymizer): make deep cloning the default (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqbd committed Jun 26, 2024
2 parents 48eef4e + d37b3f6 commit 9cae98a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.1.33",
"version": "0.1.34",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "yarn@1.22.19",
"files": [
Expand Down Expand Up @@ -263,4 +263,4 @@
},
"./package.json": "./package.json"
}
}
}
16 changes: 3 additions & 13 deletions js/src/anonymizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ function extractStringNodes(data: unknown, options: { maxDepth?: number }) {
}

function deepClone<T>(data: T): T {
if ("structuredClone" in globalThis) {
return globalThis.structuredClone(data);
}

return JSON.parse(JSON.stringify(data));
}

Expand All @@ -60,20 +56,14 @@ export type ReplacerType =

export function createAnonymizer(
replacer: ReplacerType,
options?: {
maxDepth?: number;
deepClone?: boolean;
}
options?: { maxDepth?: number }
) {
return <T>(data: T): T => {
const nodes = extractStringNodes(data, {
let mutateValue = deepClone(data);
const nodes = extractStringNodes(mutateValue, {
maxDepth: options?.maxDepth,
});

// by default we opt-in to mutate the value directly
// to improve performance
let mutateValue = options?.deepClone ? deepClone(data) : data;

const processor: StringNodeProcessor = Array.isArray(replacer)
? (() => {
const replacers: [regex: RegExp, replace: string][] = replacer.map(
Expand Down
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export type {
export { RunTree, type RunTreeConfig } from "./run_trees.js";

// Update using yarn bump-version
export const __version__ = "0.1.33";
export const __version__ = "0.1.34";

0 comments on commit 9cae98a

Please sign in to comment.