Skip to content

Commit

Permalink
Merge branch 'main' into wfh/rework_ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Jul 16, 2024
2 parents 9d9e7a3 + 0154e09 commit 933a05a
Show file tree
Hide file tree
Showing 38 changed files with 1,489 additions and 366 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/release_js.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: JS Release

on:
push:
branches:
- main
paths:
- "js/package.json"
workflow_dispatch:

jobs:
Expand All @@ -11,33 +16,34 @@ jobs:
permissions:
contents: write
id-token: write
defaults:
run:
working-directory: "js"
steps:
- uses: actions/checkout@v3
# JS Build
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: 20.x
cache: "yarn"
cache-dependency-path: "js/yarn.lock"
- name: Install dependencies
run: cd js && yarn install --immutable
run: yarn install --immutable
- name: Build
run: cd js && yarn run build
run: yarn run build
- name: Check version
run: cd js && yarn run check-version
run: yarn run check-version
- name: Check NPM version
id: check_npm_version
run: |
cd js
if yarn run check-npm-version; then
echo "::set-output name=should_publish::true"
echo "should_publish=true" >> $GITHUB_OUTPUT
else
echo "::set-output name=should_publish::false"
echo "should_publish=false" >> $GITHUB_OUTPUT
fi
- name: Publish package to NPM
if: steps.check_npm_version.outputs.should_publish == 'true'
run: |
cd js
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
yarn publish --non-interactive
1 change: 1 addition & 0 deletions js/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
ignorePatterns: [
".eslintrc.cjs",
"scripts",
"src/utils/lodash/*",
"node_modules",
"dist",
"dist-cjs",
Expand Down
4 changes: 1 addition & 3 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.37",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "[email protected]",
"files": [
Expand Down Expand Up @@ -95,7 +95,6 @@
"dependencies": {
"@types/uuid": "^9.0.1",
"commander": "^10.0.1",
"lodash.set": "^4.3.2",
"p-queue": "^6.6.2",
"p-retry": "4",
"uuid": "^9.0.0"
Expand All @@ -109,7 +108,6 @@
"@langchain/langgraph": "^0.0.19",
"@tsconfig/recommended": "^1.0.2",
"@types/jest": "^29.5.1",
"@types/lodash.set": "^4.3.9",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"babel-jest": "^29.5.0",
Expand Down
18 changes: 4 additions & 14 deletions js/src/anonymizer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import set from "lodash.set";
import set from "../utils/lodash/set.js";

export interface StringNode {
value: string;
Expand Down 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
115 changes: 114 additions & 1 deletion js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,9 @@ export class Client {
splits,
inlineS3Urls,
metadata,
limit,
offset,
filter,
}: {
datasetId?: string;
datasetName?: string;
Expand All @@ -2205,6 +2208,9 @@ export class Client {
splits?: string[];
inlineS3Urls?: boolean;
metadata?: KVMap;
limit?: number;
offset?: number;
filter?: string;
} = {}): AsyncIterable<Example> {
let datasetId_;
if (datasetId !== undefined && datasetName !== undefined) {
Expand Down Expand Up @@ -2242,11 +2248,27 @@ export class Client {
const serializedMetadata = JSON.stringify(metadata);
params.append("metadata", serializedMetadata);
}
if (limit !== undefined) {
params.append("limit", limit.toString());
}
if (offset !== undefined) {
params.append("offset", offset.toString());
}
if (filter !== undefined) {
params.append("filter", filter);
}
let i = 0;
for await (const examples of this._getPaginated<Example>(
"/examples",
params
)) {
yield* examples;
for (const example of examples) {
yield example;
i++;
}
if (limit !== undefined && i >= limit) {
break;
}
}
}

Expand Down Expand Up @@ -2292,6 +2314,97 @@ export class Client {
return result;
}

public async listDatasetSplits({
datasetId,
datasetName,
asOf,
}: {
datasetId?: string;
datasetName?: string;
asOf?: string | Date;
}): Promise<string[]> {
let datasetId_: string;
if (datasetId === undefined && datasetName === undefined) {
throw new Error("Must provide dataset name or ID");
} else if (datasetId !== undefined && datasetName !== undefined) {
throw new Error("Must provide either datasetName or datasetId, not both");
} else if (datasetId === undefined) {
const dataset = await this.readDataset({ datasetName });
datasetId_ = dataset.id;
} else {
datasetId_ = datasetId;
}

assertUuid(datasetId_);

const params = new URLSearchParams();
const dataset_version = asOf
? typeof asOf === "string"
? asOf
: asOf?.toISOString()
: undefined;
if (dataset_version) {
params.append("as_of", dataset_version);
}

const response = await this._get<string[]>(
`/datasets/${datasetId_}/splits`,
params
);
return response;
}

public async updateDatasetSplits({
datasetId,
datasetName,
splitName,
exampleIds,
remove = false,
}: {
datasetId?: string;
datasetName?: string;
splitName: string;
exampleIds: string[];
remove?: boolean;
}): Promise<void> {
let datasetId_: string;
if (datasetId === undefined && datasetName === undefined) {
throw new Error("Must provide dataset name or ID");
} else if (datasetId !== undefined && datasetName !== undefined) {
throw new Error("Must provide either datasetName or datasetId, not both");
} else if (datasetId === undefined) {
const dataset = await this.readDataset({ datasetName });
datasetId_ = dataset.id;
} else {
datasetId_ = datasetId;
}

assertUuid(datasetId_);

const data = {
split_name: splitName,
examples: exampleIds.map((id) => {
assertUuid(id);
return id;
}),
remove,
};

const response = await this.caller.call(
fetch,
`${this.apiUrl}/datasets/${datasetId_}/splits`,
{
method: "PUT",
headers: { ...this.headers, "Content-Type": "application/json" },
body: JSON.stringify(data),
signal: AbortSignal.timeout(this.timeout_ms),
...this.fetchOptions,
}
);

await raiseForStatus(response, "update dataset splits");
}

/**
* @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
*/
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.37";
44 changes: 44 additions & 0 deletions js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,22 @@ test.concurrent(
client.listExamples({ datasetId: dataset.id })
);
expect(examplesList.length).toEqual(4);

const examplesListLimited = await toArray(
client.listExamples({ datasetId: dataset.id, limit: 2 })
);
expect(examplesListLimited.length).toEqual(2);

const examplesListOffset = await toArray(
client.listExamples({ datasetId: dataset.id, offset: 2 })
);
expect(examplesListOffset.length).toEqual(2);

const examplesListLimitedOffset = await toArray(
client.listExamples({ datasetId: dataset.id, limit: 1, offset: 2 })
);
expect(examplesListLimitedOffset.length).toEqual(1);

await client.deleteExample(example.id);
const examplesList2 = await toArray(
client.listExamples({ datasetId: dataset.id })
Expand Down Expand Up @@ -583,6 +599,34 @@ test.concurrent(
expect(examplesList3[0].metadata?.foo).toEqual("bar");
expect(examplesList3[0].metadata?.baz).toEqual("qux");

examplesList3 = await toArray(
client.listExamples({
datasetId: dataset.id,
filter: 'exists(metadata, "baz")',
})
);
expect(examplesList3.length).toEqual(1);
expect(examplesList3[0].metadata?.foo).toEqual("bar");
expect(examplesList3[0].metadata?.baz).toEqual("qux");

examplesList3 = await toArray(
client.listExamples({
datasetId: dataset.id,
filter: 'has("metadata", \'{"foo": "bar"}\')',
})
);
expect(examplesList3.length).toEqual(1);
expect(examplesList3[0].metadata?.foo).toEqual("bar");
expect(examplesList3[0].metadata?.baz).toEqual("qux");

examplesList3 = await toArray(
client.listExamples({
datasetId: dataset.id,
filter: 'exists(metadata, "bazzz")',
})
);
expect(examplesList3.length).toEqual(0);

examplesList3 = await toArray(
client.listExamples({
datasetId: dataset.id,
Expand Down
49 changes: 49 additions & 0 deletions js/src/utils/lodash/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
The MIT License

Copyright JS Foundation and other contributors <https://js.foundation/>

Based on Underscore.js, copyright Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>

This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/lodash/lodash

The following license applies to all parts of this software except as
documented below:

====

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

====

Copyright and related rights for sample code are waived via CC0. Sample
code is defined as all source code displayed within the prose of the
documentation.

CC0: http://creativecommons.org/publicdomain/zero/1.0/

====

Files located in the node_modules and vendor directories are externally
maintained libraries used by this software which have their own
licenses; we recommend you read them, as their terms may differ from the
terms above.
Loading

0 comments on commit 933a05a

Please sign in to comment.