Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
isahers1 committed Dec 11, 2024
1 parent 630e27f commit e2761ba
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ export class Client implements LangSmithTracingClientInterface {
);
}

private async _getMultiPartSupport(): Promise<boolean> {
const serverInfo = await this._ensureServerInfo();
return serverInfo.instance_flags?.dataset_examples_multipart_enabled ?? false;
}

private drainAutoBatchQueue(batchSizeLimit: number) {
while (this.autoBatchQueue.items.length > 0) {
const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
Expand Down Expand Up @@ -2726,8 +2731,7 @@ export class Client implements LangSmithTracingClientInterface {
const { attachment_urls, ...rest } = rawExample;
const example: Example = rest;
if (attachment_urls) {
const attachmentsArray = await Promise.all(
Object.entries(attachment_urls).map(async ([key, value]) => {
const attachmentsArray = Object.entries(attachment_urls).map(([key, value]) => {
async function* fetchReader() {
const response = await fetch(value.presigned_url);
yield* IterableReadableStream.fromReadableStream(response.body!);

Check warning on line 2737 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Forbidden non-null assertion
Expand All @@ -2739,8 +2743,8 @@ export class Client implements LangSmithTracingClientInterface {
reader: IterableReadableStream.fromAsyncGenerator(fetchReader()),
},
};
})
);
});
// add attachments back to the example
example.attachments = attachmentsArray.reduce((acc, { key, value }) => {
if (value.reader != null) {
acc[
Expand Down Expand Up @@ -2835,8 +2839,7 @@ export class Client implements LangSmithTracingClientInterface {
const { attachment_urls, ...rest } = rawExample;
const example: Example = rest;
if (attachment_urls) {
const attachmentsArray = await Promise.all(
Object.entries(attachment_urls).map(async ([key, value]) => {
const attachmentsArray = Object.entries(attachment_urls).map(([key, value]) => {
async function* fetchReader() {
const response = await fetch(value.presigned_url);
yield* IterableReadableStream.fromReadableStream(
Expand All @@ -2852,8 +2855,8 @@ export class Client implements LangSmithTracingClientInterface {
),
},
};
})
);
});
// add attachments back to the example
example.attachments = attachmentsArray.reduce(
(acc, { key, value }) => {
if (value.reader != null) {
Expand Down Expand Up @@ -3935,6 +3938,11 @@ export class Client implements LangSmithTracingClientInterface {
datasetId: string,
updates: ExampleUpdateWithAttachments[] = []
): Promise<UpdateExamplesResponse> {
if (!(await this._getMultiPartSupport())) {
throw new Error(
"Your LangSmith version does not allow using the multipart examples endpoint, please update to the latest version."
);
}
const formData = new FormData();

for (const example of updates) {
Expand Down Expand Up @@ -4022,6 +4030,11 @@ export class Client implements LangSmithTracingClientInterface {
datasetId: string,
uploads: ExampleUploadWithAttachments[] = []
): Promise<UploadExamplesResponse> {
if (!(await this._getMultiPartSupport())) {
throw new Error(
"Your LangSmith version does not allow using the multipart examples endpoint, please update to the latest version."
);
}
const formData = new FormData();

for (const example of uploads) {
Expand Down

0 comments on commit e2761ba

Please sign in to comment.