Skip to content

Commit

Permalink
Adds test for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Oct 21, 2024
1 parent 39c8f74 commit 2457d6a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
12 changes: 8 additions & 4 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,11 +1019,15 @@ export class Client {
> = {};
let preparedCreateParams = [];
for (const create of runCreates ?? []) {
preparedCreateParams.push(this.prepareRunCreateOrUpdateInputs(create));
if (create.id !== undefined && create.attachments !== undefined) {
allAttachments[create.id] = create.attachments;
const preparedCreate = this.prepareRunCreateOrUpdateInputs(create);
if (
preparedCreate.id !== undefined &&
preparedCreate.attachments !== undefined
) {
allAttachments[preparedCreate.id] = preparedCreate.attachments;
}
delete create.attachments;
delete preparedCreate.attachments;
preparedCreateParams.push(preparedCreate);
}

let preparedUpdateParams = [];
Expand Down
58 changes: 57 additions & 1 deletion js/src/tests/batch_client.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { v4 as uuidv4 } from "uuid";
import * as fs from "node:fs";
import * as path from "node:path";
import { fileURLToPath } from "node:url";

import { Client } from "../client.js";
import { RunTree, convertToDottedOrderFormat } from "../run_trees.js";
import { v4 as uuidv4 } from "uuid";
import {
deleteProject,
waitUntilProjectFound,
Expand Down Expand Up @@ -185,3 +189,55 @@ test.concurrent(
},
180_000
);

test.concurrent(
"Test persist run with attachment",
async () => {
const langchainClient = new Client({
autoBatchTracing: true,
callerOptions: { maxRetries: 2 },
timeout_ms: 30_000,
});
const projectName = "__test_create_attachment" + uuidv4().substring(0, 4);
await deleteProject(langchainClient, projectName);

const runId = uuidv4();
const dottedOrder = convertToDottedOrderFormat(
new Date().getTime() / 1000,
runId
);
const pathname = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"test_data",
"parrot-icon.png"
);
await langchainClient.createRun({
id: runId,
project_name: projectName,
name: "test_run",
run_type: "llm",
inputs: { text: "hello world" },
trace_id: runId,
dotted_order: dottedOrder,
attachments: {
testimage: ["image/png", fs.readFileSync(pathname)],
},
});

await langchainClient.updateRun(runId, {
outputs: { output: ["Hi"] },
dotted_order: dottedOrder,
trace_id: runId,
});

await Promise.all([
waitUntilRunFound(langchainClient, runId, true),
waitUntilProjectFound(langchainClient, projectName),
]);

const storedRun = await langchainClient.readRun(runId);
expect(storedRun.id).toEqual(runId);
await langchainClient.deleteProject({ projectName });
},
180_000
);
Binary file added js/src/tests/test_data/parrot-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2457d6a

Please sign in to comment.