Skip to content

Commit

Permalink
Add run stats endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Jul 19, 2024
1 parent 772f676 commit c1b8e9f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 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.38",
"version": "0.1.39",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "[email protected]",
"files": [
Expand Down Expand Up @@ -261,4 +261,4 @@
},
"./package.json": "./package.json"
}
}
}
88 changes: 88 additions & 0 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,94 @@ export class Client {
}
}

public async getRunStats({
id,
trace,
parentRun,
runType,
projectNames,
projectIds,
referenceExampleIds,
startTime,
endTime,
error,
query,
filter,
traceFilter,
treeFilter,
isRoot,
dataSourceType,
}: {
id?: string[];
trace?: string;
parentRun?: string;
runType?: string;
projectNames?: string[];
projectIds?: string[];
referenceExampleIds?: string[];
startTime?: string;
endTime?: string;
error?: boolean;
query?: string;
filter?: string;
traceFilter?: string;
treeFilter?: string;
isRoot?: boolean;
dataSourceType?: string;
}): Promise<any> {

Check warning on line 1266 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
let projectIds_ = projectIds || [];
if (projectNames) {
projectIds_ = [
...(projectIds || []),
...(await Promise.all(
projectNames.map((name) =>
this.readProject({ projectName: name }).then(
(project) => project.id
)
)
)),
];
}

const payload = {
id,
trace,
parent_run: parentRun,
run_type: runType,
session: projectIds_,
reference_example: referenceExampleIds,
start_time: startTime,
end_time: endTime,
error,
query,
filter,
trace_filter: traceFilter,
tree_filter: treeFilter,
is_root: isRoot,
data_source_type: dataSourceType,
};

// Remove undefined values from the payload
const filteredPayload = Object.fromEntries(
Object.entries(payload).filter(([_, value]) => value !== undefined)
);

const response = await this.caller.call(
fetch,
`${this.apiUrl}/runs/stats`,
{
method: "POST",
headers: this.headers,
body: JSON.stringify(filteredPayload),
signal: AbortSignal.timeout(this.timeout_ms),
...this.fetchOptions,
}
);

const result = await response.json();
return result;
}

public async shareRun(
runId: string,
{ shareId }: { shareId?: string } = {}
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.38";
export const __version__ = "0.1.39";

0 comments on commit c1b8e9f

Please sign in to comment.