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

feat(js): Use new multipart endpoint when available #1106

Merged
merged 10 commits into from
Oct 23, 2024
Prev Previous commit
Next Next commit
Adds support for run attachments
  • Loading branch information
jacoblee93 committed Oct 20, 2024
commit 6552a3e55db3bd2e4c06a426e9bb5c7f64e41bf6
43 changes: 34 additions & 9 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
// If there is an item on the queue we were unable to pop,
// just return it as a single batch.
if (popped.length === 0 && this.items.length > 0) {
const item = this.items.shift()!;

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

View workflow job for this annotation

GitHub Actions / Check linting

Forbidden non-null assertion
popped.push(item);
poppedSizeBytes += item.size;
this.sizeBytes -= item.size;
Expand Down Expand Up @@ -1013,14 +1013,22 @@
return;
}
// transform and convert to dicts
let preparedCreateParams =
runCreates?.map((create) =>
this.prepareRunCreateOrUpdateInputs(create)
) ?? [];
let preparedUpdateParams =
runUpdates?.map((update) =>
this.prepareRunCreateOrUpdateInputs(update)
) ?? [];
const allAttachments: Record<
string,
Record<string, [string, Uint8Array]>
> = {};
let preparedCreateParams = [];
for (const create of runCreates ?? []) {
preparedCreateParams.push(this.prepareRunCreateOrUpdateInputs(create));
if (create.id !== undefined && create.attachments !== undefined) {
allAttachments[create.id] = create.attachments;
}
delete create.attachments;
}
let preparedUpdateParams = [];
for (const update of runUpdates ?? []) {
preparedUpdateParams.push(this.prepareRunCreateOrUpdateInputs(update));
}

// require trace_id and dotted_order
const invalidRunCreate = preparedCreateParams.find((runCreate) => {
Expand Down Expand Up @@ -1107,7 +1115,23 @@
}),
});
}

// encode the attachments
if (payload.id !== undefined) {
const attachments = allAttachments[payload.id];
if (attachments) {
delete allAttachments[payload.id];
for (const [name, [contentType, content]] of Object.entries(
attachments
)) {
accumulatedParts.push({
name: `attachment.${payload.id}.${name}`,
payload: new Blob([content], {
type: `${contentType}; length=${content.length}`,
}),
});
}
}
}
// compute context
accumulatedContext.push(`trace=${payload.trace_id},id=${payload.id}`);
}
Expand Down Expand Up @@ -1139,6 +1163,7 @@
);
} catch (e) {
let errorMessage = "Failed to multipart ingest runs";
// eslint-disable-next-line no-instanceof/no-instanceof
if (e instanceof Error) {
errorMessage += `: ${e.stack || e.message}`;
} else {
Expand Down Expand Up @@ -1502,7 +1527,7 @@
treeFilter?: string;
isRoot?: boolean;
dataSourceType?: string;
}): Promise<any> {

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

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
let projectIds_ = projectIds || [];
if (projectNames) {
projectIds_ = [
Expand Down Expand Up @@ -1790,7 +1815,7 @@
`Failed to list shared examples: ${response.status} ${response.statusText}`
);
}
return result.map((example: any) => ({

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

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
...example,
_hostUrl: this.getHostUrl(),
}));
Expand Down Expand Up @@ -2933,7 +2958,7 @@
}

const feedbackResult = await evaluator.evaluateRun(run_, referenceExample);
const [_, feedbacks] = await this._logEvaluationFeedback(

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

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
feedbackResult,
run_,
sourceInfo
Expand Down Expand Up @@ -3267,7 +3292,7 @@
async _logEvaluationFeedback(
evaluatorResponse: EvaluationResult | EvaluationResults,
run?: Run,
sourceInfo?: { [key: string]: any }

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

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
): Promise<[results: EvaluationResult[], feedbacks: Feedback[]]> {
const evalResults: Array<EvaluationResult> =
this._selectEvalResults(evaluatorResponse);
Expand Down Expand Up @@ -3306,7 +3331,7 @@
public async logEvaluationFeedback(
evaluatorResponse: EvaluationResult | EvaluationResults,
run?: Run,
sourceInfo?: { [key: string]: any }

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

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
): Promise<EvaluationResult[]> {
const [results] = await this._logEvaluationFeedback(
evaluatorResponse,
Expand Down Expand Up @@ -3574,7 +3599,7 @@
promptIdentifier: string,
like: boolean
): Promise<LikePromptResponse> {
const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

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

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
const response = await this.caller.call(
_getFetchImplementation(),
`${this.apiUrl}/likes/${owner}/${promptName}`,
Expand Down Expand Up @@ -3679,7 +3704,7 @@
}

public async getPrompt(promptIdentifier: string): Promise<Prompt | null> {
const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

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

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
const response = await this.caller.call(
_getFetchImplementation(),
`${this.apiUrl}/repos/${owner}/${promptName}`,
Expand Down Expand Up @@ -3723,7 +3748,7 @@
);
}

const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

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

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
if (!(await this._currentTenantIsOwner(owner))) {
throw await this._ownerConflictError("create a prompt", owner);
}
Expand Down Expand Up @@ -3756,7 +3781,7 @@

public async createCommit(
promptIdentifier: string,
object: any,

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

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
options?: {
parentCommitHash?: string;
}
Expand Down
Loading