Skip to content

Commit

Permalink
feat(js): Add method to list dataset versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tendev-eoghan committed Jan 8, 2025
1 parent af5a931 commit e6aad42
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
51 changes: 51 additions & 0 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Dataset,
DatasetDiffInfo,
DatasetShareSchema,
DatasetVersion,
Example,
ExampleCreate,
ExampleUpdate,
Expand Down Expand Up @@ -1836,6 +1837,56 @@ export class Client implements LangSmithTracingClientInterface {
return dataset as Dataset;
}

/**
* Lists the versions of a dataset.
*
* @param {Object} params - The parameters for listing dataset versions.
* @param {string} params.datasetId - The ID of the dataset.
* @param {string} [params.search] - Optional search query to filter dataset versions.
* @param {string} [params.example] - Optional example query to filter dataset versions.
* @param {number} [params.limit=100] - The maximum number of dataset versions to return.
* @param {number} [params.offset=0] - The offset for pagination.
* @returns {Promise<DatasetVersion[]>} A promise that resolves to an array of dataset versions.
* @throws {Error} Throws an error if the datasetId is not a valid UUID.
*/
public async listDatasetVersions({
datasetId,
search,
example,
limit = 100,
offset = 0,
}: {
datasetId: string;
search?: string;
example?: string;
limit?: number;
offset?: number;
}): Promise<DatasetVersion[]> {
assertUuid(datasetId);
const params = new URLSearchParams({
limit: limit.toString(),
offset: offset.toString(),
});
if (search !== undefined) {
params.append("search", search);
}
if (example !== undefined) {
params.append("example", example);
}
const response = await this.caller.call(
_getFetchImplementation(),
`${this.apiUrl}/datasets/${datasetId}/versions?${params.toString()}`,
{
method: "GET",
headers: this.headers,
signal: AbortSignal.timeout(this.timeout_ms),
...this.fetchOptions,
}
);
const datasetVersions = await response.json();
return datasetVersions as DatasetVersion[];
}

/**
* Get shared examples.
*
Expand Down
5 changes: 5 additions & 0 deletions js/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ export interface DatasetShareSchema {
url: string;
}

export interface DatasetVersion {
tags?: string[];
asOf: string;
}

export interface FeedbackSourceBase {
type: string;
metadata?: KVMap;
Expand Down

0 comments on commit e6aad42

Please sign in to comment.