Skip to content

Commit

Permalink
time
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Feb 9, 2024
1 parent 4314216 commit 1ac6da9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 80 deletions.
80 changes: 42 additions & 38 deletions js/src/tests/batch_client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test.concurrent(
autoBatchTracing: true,
callerOptions: { maxRetries: 0 },
});
const projectName = "__test_persist_update_run_batch";
const projectName = "__test_persist_update_run_batch_1";
await deleteProject(langchainClient, projectName);

const runId = uuidv4();
Expand Down Expand Up @@ -90,46 +90,50 @@ test.concurrent(
180_000
);

test("Test persist update runs above the batch size limit", async () => {
const langchainClient = new Client({
autoBatchTracing: true,
callerOptions: { maxRetries: 0 },
pendingAutoBatchedRunLimit: 2,
});
const projectName = "__test_persist_update_run_batch";
await deleteProject(langchainClient, projectName);

const createRun = async () => {
const runId = uuidv4();
const dottedOrder = convertToDottedOrderFormat(
new Date().getTime() / 1000,
runId
);
await langchainClient.createRun({
id: runId,
project_name: projectName,
name: "test_run",
run_type: "llm",
inputs: { text: "hello world" },
trace_id: runId,
dotted_order: dottedOrder,
test.concurrent(
"Test persist update runs above the batch size limit",
async () => {
const langchainClient = new Client({
autoBatchTracing: true,
callerOptions: { maxRetries: 0 },
pendingAutoBatchedRunLimit: 2,
});
const projectName = "__test_persist_update_run_batch_above_bs_limit";
await deleteProject(langchainClient, projectName);

await langchainClient.updateRun(runId, {
outputs: { output: ["Hi"] },
dotted_order: dottedOrder,
trace_id: runId,
end_time: Math.floor(new Date().getTime() / 1000),
});
await waitUntilRunFound(langchainClient, runId, true);
const storedRun = await langchainClient.readRun(runId);
expect(storedRun.id).toEqual(runId);
};
const createRun = async () => {
const runId = uuidv4();
const dottedOrder = convertToDottedOrderFormat(
new Date().getTime() / 1000,
runId
);
await langchainClient.createRun({
id: runId,
project_name: projectName,
name: "test_run",
run_type: "llm",
inputs: { text: "hello world" },
trace_id: runId,
dotted_order: dottedOrder,
});

await langchainClient.updateRun(runId, {
outputs: { output: ["Hi"] },
dotted_order: dottedOrder,
trace_id: runId,
end_time: Math.floor(new Date().getTime() / 1000),
});
await waitUntilRunFound(langchainClient, runId, true);
const storedRun = await langchainClient.readRun(runId);
expect(storedRun.id).toEqual(runId);
};

await Promise.all([createRun(), createRun(), createRun()]);
await Promise.all([createRun(), createRun(), createRun()]);

await langchainClient.deleteProject({ projectName });
}, 180_000);
await langchainClient.deleteProject({ projectName });
},
180_000
);

test.concurrent(
"Test persist update run with delay",
Expand All @@ -138,7 +142,7 @@ test.concurrent(
autoBatchTracing: true,
callerOptions: { maxRetries: 0 },
});
const projectName = "__test_persist_update_run_batch";
const projectName = "__test_persist_update_run_batch_with_delay";
await deleteProject(langchainClient, projectName);

const runId = uuidv4();
Expand Down
50 changes: 8 additions & 42 deletions js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ test.concurrent(

const projectName = "__test_evaluate_run" + Date.now();
const datasetName = "__test_evaluate_run_dataset" + Date.now();
await deleteProject(langchainClient, projectName);
await deleteDataset(langchainClient, datasetName);

const dataset = await langchainClient.createDataset(datasetName);
const predicted = "abcd";
const groundTruth = "bcde";
Expand All @@ -179,17 +176,6 @@ test.concurrent(
await parentRun.end({ output: predicted });
await parentRun.patchRun();

await waitUntilRunFound(
langchainClient,
parentRun.id,
(run: Run | undefined) => Object.keys(run?.outputs || {}).length !== 0
);

const run = await langchainClient.readRun(parentRun.id);
expect(run.outputs).toEqual({ output: predicted });
const runUrl = await langchainClient.getRunUrl({ runId: run.id });
expect(runUrl).toContain(run.id);

function jaccardChars(output: string, answer: string): number {
const predictionChars = new Set(output.trim().toLowerCase());
const answerChars = new Set(answer.trim().toLowerCase());
Expand Down Expand Up @@ -221,35 +207,16 @@ test.concurrent(
evaluationName: "Jaccard",
gradingFunction: grader,
});
const feedback = await langchainClient.evaluateRun(parentRun, evaluator);

const runs = langchainClient.listRuns({
projectName: projectName,
executionOrder: 1,
error: false,
});

const project = await langchainClient.readProject({
projectName: projectName,
});
const projectWithStats = await langchainClient.readProject({
projectId: project.id,
});
expect(projectWithStats.name).toBe(project.name);

const allFeedback: Feedback[] = [];
for await (const run of runs) {
allFeedback.push(await langchainClient.evaluateRun(run, evaluator));
}

expect(allFeedback.length).toEqual(1);
await waitUntil(
async () => {
try {
const listSuccess =
(
await toArray(
langchainClient.listFeedback({
runIds: [run.id],
runIds: [parentRun.id],
feedbackKeys: ["jaccard"],
feedbackSourceTypes: ["model"],
})
Expand All @@ -266,12 +233,12 @@ test.concurrent(

const fetchedFeedback: Feedback[] = await toArray(
langchainClient.listFeedback({
runIds: [run.id],
runIds: [parentRun.id],
feedbackKeys: ["jaccard"],
feedbackSourceTypes: ["model"],
})
);
expect(fetchedFeedback[0].id).toEqual(allFeedback[0].id);
expect(fetchedFeedback[0].id).toEqual(feedback.id);
expect(fetchedFeedback[0].score).toEqual(
jaccardChars(predicted, groundTruth)
);
Expand All @@ -284,15 +251,14 @@ test.concurrent(
console.log(e);
}
},
180_000
360_000
);

test.concurrent(
"Test persist update run",
async () => {
const langchainClient = new Client({ autoBatchTracing: false });
const projectName = "__test_persist_update_run";
await deleteProject(langchainClient, projectName);
const projectName = "__test_persist_update_run" + Date.now();

const runId = uuidv4();
await langchainClient.createRun({
Expand All @@ -311,9 +277,9 @@ test.concurrent(
);
const storedRun = await langchainClient.readRun(runId);
expect(storedRun.id).toEqual(runId);
await langchainClient.deleteProject({ projectName });
await deleteProject(langchainClient, projectName);
},
180_000
360_000
);

test.concurrent(
Expand Down

0 comments on commit 1ac6da9

Please sign in to comment.