Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort by dotted order in py sdk #229

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class Client {
const childRuns = await toArray(this.listRuns({ id: run.child_run_ids }));
const treemap: { [key: string]: Run[] } = {};
const runs: { [key: string]: Run } = {};
childRuns.sort((a, b) => a.execution_order - b.execution_order);
childRuns.sort((a, b) => a.dotted_order.localeCompare(b.dotted_order));
for (const childRun of childRuns) {
if (
childRun.parent_run_id === null ||
Expand Down
16 changes: 16 additions & 0 deletions js/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ export interface Run extends BaseRun {

/** IDs of parent runs, if multiple exist. */
parent_run_ids?: string[];
/**Unique ID assigned to every run within this nested trace.**/
trace_id: string;

/**
* The dotted order for the run.
*
* This is a string composed of {time}{run-uuid}.* so that a trace can be
* sorted in the order it was executed.
*
* Example:
* - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
* - Children:
* - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
* - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
*/
dotted_order: string;
}

export interface RunCreate extends BaseRun {
Expand Down
2 changes: 1 addition & 1 deletion python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def _load_child_runs(self, run: ls_schemas.Run) -> ls_schemas.Run:
list
)
runs: Dict[uuid.UUID, ls_schemas.Run] = {}
for child_run in sorted(child_runs, key=lambda r: r.execution_order):
for child_run in sorted(child_runs, key=lambda r: r.dotted_order):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fn is also something we'd change once trace ID changes are made

if child_run.parent_run_id is None:
raise ls_utils.LangSmithError(f"Child run {child_run.id} has no parent")
treemap[child_run.parent_run_id].append(child_run)
Expand Down
15 changes: 14 additions & 1 deletion python/langsmith/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,20 @@ class Run(RunBase):
"""Time the first token was processed."""
parent_run_ids: Optional[List[UUID]] = None
"""List of parent run IDs."""

trace_id: UUID
"""Unique ID assigned to every run within this nested trace."""
dotted_order: str
"""Dotted order for the run.

This is a string composed of {time}{run-uuid}.* so that a trace can be
sorted in the order it was executed.

Example:
- Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
- Children:
- 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
- 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
""" # noqa: E501
_host_url: Optional[str] = PrivateAttr(default=None)

def __init__(self, _host_url: Optional[str] = None, **kwargs: Any) -> None:
Expand Down
Loading