Skip to content

Commit

Permalink
allow filtering projects by metadata (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
samnoyes authored Aug 6, 2024
2 parents ee4a1be + 88c7274 commit 0badaa0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.1.40",
"version": "0.1.41",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "yarn@1.22.19",
"files": [
Expand Down
5 changes: 5 additions & 0 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1758,13 +1758,15 @@ export class Client {
referenceDatasetId,
referenceDatasetName,
referenceFree,
metadata,
}: {
projectIds?: string[];
name?: string;
nameContains?: string;
referenceDatasetId?: string;
referenceDatasetName?: string;
referenceFree?: boolean;
metadata?: RecordStringAny;
} = {}): AsyncIterable<TracerSession> {
const params = new URLSearchParams();
if (projectIds !== undefined) {
Expand All @@ -1789,6 +1791,9 @@ export class Client {
if (referenceFree !== undefined) {
params.append("reference_free", referenceFree.toString());
}
if (metadata !== undefined) {
params.append("metadata", JSON.stringify(metadata));
}
for await (const projects of this._getPaginated<TracerSession>(
"/sessions",
params
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.40";
export const __version__ = "0.1.41";
23 changes: 22 additions & 1 deletion js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dataset, Run } from "../schemas.js";
import { Dataset, Run, TracerSession } from "../schemas.js";
import {
FunctionMessage,
HumanMessage,
Expand Down Expand Up @@ -912,6 +912,27 @@ test("Test delete prompt", async () => {
expect(await client.promptExists(promptName)).toBe(false);
});

test("test listing projects by metadata", async () => {
const client = new Client();
await client.createProject({
projectName: "my_metadata_project",
metadata: {
foobar: "bar",
baz: "barfooqux",
},
});

const projects = await client.listProjects({ metadata: { foobar: "bar" } });

let myProject: TracerSession | null = null;
for await (const project of projects) {
myProject = project;
}
expect(myProject?.name).toEqual("my_metadata_project");

await client.deleteProject({ projectName: "my_metadata_project" });
});

test("Test create commit", async () => {
const client = new Client();

Expand Down
5 changes: 5 additions & 0 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,7 @@ def list_projects(
reference_dataset_name: Optional[str] = None,
reference_free: Optional[bool] = None,
limit: Optional[int] = None,
metadata: Optional[Dict[str, Any]] = None,
) -> Iterator[ls_schemas.TracerSession]:
"""List projects from the LangSmith API.
Expand All @@ -2457,6 +2458,8 @@ def list_projects(
Whether to filter for only projects not associated with a dataset.
limit : Optional[int], optional
The maximum number of projects to return, by default None
metadata: Optional[Dict[str, Any]], optional
Metadata to filter by.
Yields:
------
Expand Down Expand Up @@ -2486,6 +2489,8 @@ def list_projects(
params["reference_dataset"] = reference_dataset_id
if reference_free is not None:
params["reference_free"] = reference_free
if metadata is not None:
params["metadata"] = json.dumps(metadata)
for i, project in enumerate(
self._get_paginated_list("/sessions", params=params)
):
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langsmith"
version = "0.1.96"
version = "0.1.97"
description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform."
authors = ["LangChain <support@langchain.dev>"]
license = "MIT"
Expand Down

0 comments on commit 0badaa0

Please sign in to comment.