langsmith
Advanced tools
Comparing version 0.0.70-rc.0 to 0.0.70-rc.1
@@ -68,2 +68,8 @@ import { AsyncCallerParams } from "./utils/async_caller.js"; | ||
}; | ||
export declare class Queue<T> { | ||
items: [T, () => void][]; | ||
get size(): number; | ||
push(item: T): Promise<void>; | ||
pop(upToN: number): [T[], () => void]; | ||
} | ||
export declare class Client { | ||
@@ -82,3 +88,3 @@ private apiKey?; | ||
private batchEndpointSupported?; | ||
private pendingAutoBatchedRuns; | ||
private autoBatchQueue; | ||
private pendingAutoBatchedRunLimit; | ||
@@ -108,3 +114,3 @@ private autoBatchTimeout; | ||
private triggerAutoBatchSend; | ||
private appendRunCreateToAutoBatchQueue; | ||
private processRunOperation; | ||
protected batchEndpointIsSupported(): Promise<boolean>; | ||
@@ -111,0 +117,0 @@ createRun(run: CreateRunParams): Promise<void>; |
@@ -75,2 +75,36 @@ import * as uuid from "uuid"; | ||
} | ||
export class Queue { | ||
constructor() { | ||
Object.defineProperty(this, "items", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: [] | ||
}); | ||
} | ||
get size() { | ||
return this.items.length; | ||
} | ||
push(item) { | ||
return new Promise((resolve) => { | ||
this.items.push([item, resolve]); | ||
}); | ||
} | ||
pop(upToN) { | ||
if (upToN < 1) { | ||
throw new Error("Number of items to pop off may not be less than 1."); | ||
} | ||
const popped = []; | ||
while (popped.length < upToN && this.items.length) { | ||
const item = this.items.shift(); | ||
if (item) { | ||
popped.push(item); | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return [popped.map((it) => it[0]), () => popped.forEach((it) => it[1]())]; | ||
} | ||
} | ||
export class Client { | ||
@@ -142,3 +176,3 @@ constructor(config = {}) { | ||
writable: true, | ||
value: true | ||
value: false | ||
}); | ||
@@ -151,7 +185,7 @@ Object.defineProperty(this, "batchEndpointSupported", { | ||
}); | ||
Object.defineProperty(this, "pendingAutoBatchedRuns", { | ||
Object.defineProperty(this, "autoBatchQueue", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: [] | ||
value: new Queue() | ||
}); | ||
@@ -364,41 +398,42 @@ Object.defineProperty(this, "pendingAutoBatchedRunLimit", { | ||
} | ||
async triggerAutoBatchSend(runs) { | ||
let batch = runs; | ||
if (batch === undefined) { | ||
batch = this.pendingAutoBatchedRuns.slice(0, this.pendingAutoBatchedRunLimit); | ||
this.pendingAutoBatchedRuns = this.pendingAutoBatchedRuns.slice(this.pendingAutoBatchedRunLimit); | ||
async triggerAutoBatchSend() { | ||
const [batch, done] = this.autoBatchQueue.pop(this.pendingAutoBatchedRunLimit); | ||
if (!batch.length) { | ||
done(); | ||
return; | ||
} | ||
await this.batchIngestRuns({ | ||
runCreates: batch | ||
.filter((item) => item.action === "create") | ||
.map((item) => item.item), | ||
runUpdates: batch | ||
.filter((item) => item.action === "update") | ||
.map((item) => item.item), | ||
}); | ||
try { | ||
await this.batchIngestRuns({ | ||
runCreates: batch | ||
.filter((item) => item.action === "create") | ||
.map((item) => item.item), | ||
runUpdates: batch | ||
.filter((item) => item.action === "update") | ||
.map((item) => item.item), | ||
}); | ||
} | ||
finally { | ||
done(); | ||
} | ||
} | ||
appendRunCreateToAutoBatchQueue(item) { | ||
async processRunOperation(item, immediatelyTriggerBatch) { | ||
const oldTimeout = this.autoBatchTimeout; | ||
clearTimeout(this.autoBatchTimeout); | ||
this.autoBatchTimeout = undefined; | ||
this.pendingAutoBatchedRuns.push(item); | ||
while (this.pendingAutoBatchedRuns.length >= this.pendingAutoBatchedRunLimit) { | ||
const batch = this.pendingAutoBatchedRuns.slice(0, this.pendingAutoBatchedRunLimit); | ||
this.pendingAutoBatchedRuns = this.pendingAutoBatchedRuns.slice(this.pendingAutoBatchedRunLimit); | ||
void this.triggerAutoBatchSend(batch); | ||
const itemPromise = this.autoBatchQueue.push(item); | ||
if (immediatelyTriggerBatch) { | ||
await this.triggerAutoBatchSend(); | ||
} | ||
if (this.pendingAutoBatchedRuns.length > 0) { | ||
if (!oldTimeout) { | ||
this.autoBatchTimeout = setTimeout(() => { | ||
this.autoBatchTimeout = undefined; | ||
void this.triggerAutoBatchSend(); | ||
}, this.autoBatchInitialDelayMs); | ||
} | ||
else { | ||
this.autoBatchTimeout = setTimeout(() => { | ||
this.autoBatchTimeout = undefined; | ||
void this.triggerAutoBatchSend(); | ||
}, this.autoBatchAggregationDelayMs); | ||
} | ||
while (this.autoBatchQueue.size >= this.pendingAutoBatchedRunLimit) { | ||
await this.triggerAutoBatchSend(); | ||
} | ||
if (this.autoBatchQueue.size > 0) { | ||
this.autoBatchTimeout = setTimeout(() => { | ||
this.autoBatchTimeout = undefined; | ||
void this.triggerAutoBatchSend(); | ||
}, oldTimeout | ||
? this.autoBatchAggregationDelayMs | ||
: this.autoBatchInitialDelayMs); | ||
} | ||
return itemPromise; | ||
} | ||
@@ -434,3 +469,3 @@ async batchEndpointIsSupported() { | ||
runCreate.dotted_order !== undefined) { | ||
this.appendRunCreateToAutoBatchQueue({ | ||
void this.processRunOperation({ | ||
action: "create", | ||
@@ -537,3 +572,11 @@ item: runCreate, | ||
data.dotted_order !== undefined) { | ||
this.appendRunCreateToAutoBatchQueue({ action: "update", item: data }); | ||
if (run.end_time !== undefined && data.parent_run_id === undefined) { | ||
// Trigger a batch as soon as a root trace ends and block to ensure trace finishes | ||
// in serverless environments. | ||
await this.processRunOperation({ action: "update", item: data }, true); | ||
return; | ||
} | ||
else { | ||
void this.processRunOperation({ action: "update", item: data }); | ||
} | ||
return; | ||
@@ -540,0 +583,0 @@ } |
export { Client } from "./client.js"; | ||
export { Dataset, Example, TracerSession, Run, Feedback } from "./schemas.js"; | ||
export { RunTree, RunTreeConfig } from "./run_trees.js"; | ||
export declare const __version__ = "0.0.70-rc.0"; | ||
export declare const __version__ = "0.0.69"; |
export { Client } from "./client.js"; | ||
export { RunTree } from "./run_trees.js"; | ||
// Update using yarn bump-version | ||
export const __version__ = "0.0.70-rc.0"; | ||
export const __version__ = "0.0.69"; |
{ | ||
"name": "langsmith", | ||
"version": "0.0.70-rc.0", | ||
"version": "0.0.70-rc.1", | ||
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.", | ||
@@ -5,0 +5,0 @@ "packageManager": "yarn@1.22.19", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
224113
5576
63