Skip to content

Commit

Permalink
Merge branch 'main' into bagatur/rfc_set_test_vals
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan committed Jan 14, 2025
2 parents 88e6f63 + 4864506 commit 43509c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2770,6 +2770,7 @@ export class Client implements LangSmithTracingClientInterface {
(acc, [key, value]) => {
acc[key.slice("attachment.".length)] = {
presigned_url: value.presigned_url,
mime_type: value.mime_type,
};
return acc;
},
Expand Down Expand Up @@ -2867,6 +2868,7 @@ export class Client implements LangSmithTracingClientInterface {
(acc, [key, value]) => {
acc[key.slice("attachment.".length)] = {
presigned_url: value.presigned_url,
mime_type: value.mime_type || undefined,
};
return acc;
},
Expand Down
2 changes: 2 additions & 0 deletions js/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface BaseExample {

export interface AttachmentInfo {
presigned_url: string;
mime_type?: string;
}

export type AttachmentData = Uint8Array | ArrayBuffer;
Expand Down Expand Up @@ -300,6 +301,7 @@ export interface Example extends BaseExample {
interface RawAttachmentInfo {
presigned_url: string;
s3_url: string;
mime_type?: string;
}
export interface RawExample extends BaseExample {
id: string;
Expand Down
56 changes: 32 additions & 24 deletions js/src/tests/evaluate_attachments.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@ test("evaluate can handle examples with attachments", async () => {
config?: TargetConfigT
) => {
// Verify we receive the attachment data
if (!config?.attachments?.["image"]) {
if (!config?.attachments?.image) {
throw new Error("Image attachment not found");
}
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentMimeType = config?.attachments?.image.mime_type;
if (attachmentMimeType !== "image/png") {
throw new Error("Image attachment has incorrect mime type");
}
const attachmentData: Uint8Array | undefined = config?.attachments?.[
"image"
].presigned_url
? new Uint8Array(
(await fetch(config?.attachments?.["image"].presigned_url).then(
(res) => res.arrayBuffer()
(await fetch(config?.attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
: undefined;
Expand All @@ -57,14 +61,18 @@ test("evaluate can handle examples with attachments", async () => {

const customEvaluator = async ({ attachments }: { attachments?: any }) => {
expect(attachments).toBeDefined();
expect(attachments?.["image"]).toBeDefined();
expect(attachments?.image).toBeDefined();
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentData: Uint8Array | undefined = attachments?.["image"]
const attachmentMimeType = attachments?.image.mime_type;
if (attachmentMimeType !== "image/png") {
throw new Error("Image attachment has incorrect mime type");
}
const attachmentData: Uint8Array | undefined = attachments?.image
.presigned_url
? new Uint8Array(
(await fetch(attachments?.["image"].presigned_url).then((res) =>
(await fetch(attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
Expand Down Expand Up @@ -134,14 +142,14 @@ test("evaluate with attachments not in target function", async () => {

const customEvaluator = async ({ attachments }: { attachments?: any }) => {
expect(attachments).toBeDefined();
expect(attachments?.["image"]).toBeDefined();
expect(attachments?.image).toBeDefined();
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentData: Uint8Array | undefined = attachments?.["image"]
const attachmentData: Uint8Array | undefined = attachments?.image
.presigned_url
? new Uint8Array(
(await fetch(attachments?.["image"].presigned_url).then((res) =>
(await fetch(attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
Expand Down Expand Up @@ -210,7 +218,7 @@ test("multiple evaluators with attachments", async () => {
config?: TargetConfigT
) => {
// Verify we receive the attachment data
if (!config?.attachments?.["image"]) {
if (!config?.attachments?.image) {
throw new Error("Image attachment not found");
}
const expectedData = new Uint8Array(
Expand All @@ -220,8 +228,8 @@ test("multiple evaluators with attachments", async () => {
"image"
].presigned_url
? new Uint8Array(
(await fetch(config?.attachments?.["image"].presigned_url).then(
(res) => res.arrayBuffer()
(await fetch(config?.attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
: undefined;
Expand All @@ -233,14 +241,14 @@ test("multiple evaluators with attachments", async () => {

const customEvaluatorOne = async ({ attachments }: { attachments?: any }) => {
expect(attachments).toBeDefined();
expect(attachments?.["image"]).toBeDefined();
expect(attachments?.image).toBeDefined();
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentData: Uint8Array | undefined = attachments?.["image"]
const attachmentData: Uint8Array | undefined = attachments?.image
.presigned_url
? new Uint8Array(
(await fetch(attachments?.["image"].presigned_url).then((res) =>
(await fetch(attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
Expand All @@ -256,14 +264,14 @@ test("multiple evaluators with attachments", async () => {

const customEvaluatorTwo = async ({ attachments }: { attachments?: any }) => {
expect(attachments).toBeDefined();
expect(attachments?.["image"]).toBeDefined();
expect(attachments?.image).toBeDefined();
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentData: Uint8Array | undefined = attachments?.["image"]
const attachmentData: Uint8Array | undefined = attachments?.image
.presigned_url
? new Uint8Array(
(await fetch(attachments?.["image"].presigned_url).then((res) =>
(await fetch(attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
Expand Down Expand Up @@ -329,7 +337,7 @@ test("evaluate with attachments runnable target function", async () => {
await client.uploadExamplesMultipart(dataset.id, [example]);

const myFunction = async (_input: any, config?: any) => {
if (!config?.attachments?.["image"]) {
if (!config?.attachments?.image) {
throw new Error("Image attachment not found");
}
const expectedData = new Uint8Array(
Expand All @@ -339,8 +347,8 @@ test("evaluate with attachments runnable target function", async () => {
"image"
].presigned_url
? new Uint8Array(
(await fetch(config?.attachments?.["image"].presigned_url).then(
(res) => res.arrayBuffer()
(await fetch(config?.attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
: undefined;
Expand All @@ -355,14 +363,14 @@ test("evaluate with attachments runnable target function", async () => {

const customEvaluator = async ({ attachments }: { attachments?: any }) => {
expect(attachments).toBeDefined();
expect(attachments?.["image"]).toBeDefined();
expect(attachments?.image).toBeDefined();
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentData: Uint8Array | undefined = attachments?.["image"]
const attachmentData: Uint8Array | undefined = attachments?.image
.presigned_url
? new Uint8Array(
(await fetch(attachments?.["image"].presigned_url).then((res) =>
(await fetch(attachments?.image.presigned_url).then((res) =>
res.arrayBuffer()
)) as ArrayBuffer
)
Expand Down

0 comments on commit 43509c2

Please sign in to comment.