Skip to content

Commit

Permalink
Add dotted order and trace id to trace tree JS (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Feb 10, 2024
1 parent c5742d8 commit 3c5685f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
9 changes: 7 additions & 2 deletions js/src/run_trees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function convertToDottedOrderFormat(epoch: number, runId: string) {

export interface RunTreeConfig {
name: string;
run_type: string;
run_type?: string;
id?: string;
project_name?: string;
parent_run?: RunTree;
Expand All @@ -44,7 +44,7 @@ export interface RunTreeConfig {
export class RunTree implements BaseRun {
id: string;
name: RunTreeConfig["name"];
run_type: RunTreeConfig["run_type"];
run_type: string;
project_name: string;
parent_run?: RunTree;
child_runs: RunTree[];
Expand Down Expand Up @@ -87,6 +87,7 @@ export class RunTree implements BaseRun {
private static getDefaultConfig(): object {
return {
id: uuid.v4(),
run_type: "chain",
project_name:
getEnvironmentVariable("LANGCHAIN_PROJECT") ??
getEnvironmentVariable("LANGCHAIN_SESSION") ?? // TODO: Deprecate
Expand Down Expand Up @@ -168,6 +169,8 @@ export class RunTree implements BaseRun {
session_name: run.project_name,
child_runs: child_runs,
parent_run_id: parent_run_id,
trace_id: run.trace_id,
dotted_order: run.dotted_order,
};
return persistedRun;
}
Expand Down Expand Up @@ -195,6 +198,8 @@ export class RunTree implements BaseRun {
reference_example_id: this.reference_example_id,
extra: this.extra,
events: this.events,
dotted_order: this.dotted_order,
trace_id: this.trace_id,
};

await this.client.updateRun(this.id, runUpdate);
Expand Down
34 changes: 33 additions & 1 deletion js/src/tests/batch_client.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from "../client.js";
import { convertToDottedOrderFormat } from "../run_trees.js";
import { RunTree, convertToDottedOrderFormat } from "../run_trees.js";
import { v4 as uuidv4 } from "uuid";

async function deleteProject(langchainClient: Client, projectName: string) {
Expand Down Expand Up @@ -174,3 +174,35 @@ test.concurrent(
},
180_000
);

test.concurrent(
"Test persist update run tree",
async () => {
const langchainClient = new Client({
autoBatchTracing: true,
callerOptions: { maxRetries: 0 },
});
const projectName = "__test_persist_update_run_tree";
await deleteProject(langchainClient, projectName);
const runId = uuidv4();
const runTree = new RunTree({
name: "Test Run Tree",
id: runId,
inputs: { input: "foo1" },
client: langchainClient,
project_name: projectName,
});
await runTree.postRun();
await runTree.end({ output: "foo2" });
await runTree.patchRun();
await waitUntilRunFound(langchainClient, runId, true);
const storedRun = await langchainClient.readRun(runId);
expect(storedRun.id).toEqual(runId);
expect(storedRun.dotted_order).toEqual(runTree.dotted_order);
expect(storedRun.trace_id).toEqual(runTree.trace_id);
expect(storedRun.inputs).toEqual({ input: "foo1" });
expect(storedRun.outputs).toEqual({ output: "foo2" });
await langchainClient.deleteProject({ projectName });
},
180_000
);

0 comments on commit 3c5685f

Please sign in to comment.