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

surface mime type when passing attachments to user #1409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
RunEvaluator,
} from "./evaluation/evaluator.js";
import { __version__ } from "./index.js";
import { assertUuid } from "./utils/_uuid.js";
import { assertUuid } from "./utils/uuid.js";
import { warnOnce } from "./utils/warn.js";
import { parsePromptIdentifier } from "./utils/prompts.js";
import { raiseForStatus } from "./utils/error.js";
Expand Down 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 || undefined,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need || undefined, just 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: 1 addition & 1 deletion js/src/evaluation/_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "../schemas.js";
import { traceable } from "../traceable.js";
import { getDefaultRevisionId, getGitInfo } from "../utils/_git.js";
import { assertUuid } from "../utils/_uuid.js";
import { assertUuid } from "../utils/uuid.js";
import { AsyncCaller } from "../utils/async_caller.js";
import { atee } from "../utils/atee.js";
import { getLangChainEnvVarsMetadata } from "../utils/env.js";
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
8 changes: 8 additions & 0 deletions js/src/tests/evaluate_attachments.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ test("evaluate can handle examples with attachments", async () => {
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
const attachmentMimeType = config?.attachments?.["image"].mime_type;
Copy link
Collaborator

Choose a reason for hiding this comment

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

config?.attachments?.image.mime_type; is more conventional

For JS you only use box notation like that for things that have characters that can be represented inline e.g. if you were to do:

config?.attachments?.["foo-bar"].mime_type;

if (attachmentMimeType !== "image/png") {
throw new Error("Image attachment has incorrect mime type");
}
const attachmentData: Uint8Array | undefined = config?.attachments?.[
"image"
].presigned_url
Expand All @@ -61,6 +65,10 @@ test("evaluate can handle examples with attachments", async () => {
const expectedData = new Uint8Array(
Buffer.from("fake image data for testing")
);
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(
Expand Down
Loading