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

Add Human Review Client Endpoints #211

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
72 changes: 71 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TimeDelta } from './types';
import type { HumanReviewFieldContentType, TimeDelta } from './types';
import {
convertTimeDeltaToMilliSeconds,
readEnv,
Expand Down Expand Up @@ -69,6 +69,59 @@ export enum SystemEventFilterKey {
LABEL = 'SYSTEM:label',
}

export interface HumanReviewJob {
id: string;
name: string;
reviewer: { id: string; email: string };
}

export interface HumanReviewJobWithTestCases extends HumanReviewJob {
testCases: { id: string; status: 'Submitted' | 'Pending' }[];
}

export interface HumanReviewJobTestCaseResult {
id: string;
reviewerEmail: string;
status: 'Submitted' | 'Pending';
grades: { name: string; grade: number }[];
automatedEvaluations: {
id: string;
originalScore: number;
overrideScore: number;
overrideReason?: string;
}[];
inputFields: {
id: string;
name: string;
value: string;
contentType: HumanReviewFieldContentType;
}[];
outputFields: {
id: string;
name: string;
value: string;
contentType: HumanReviewFieldContentType;
}[];
fieldComments: {
fieldId: string;
startIdx?: number;
endIdx?: number;
value: string;
inRelationToGradeName?: string;
inRelationToAutomatedEvaluationId?: string;
}[];
inputComments: {
value: string;
inRelationToGradeName?: string;
inRelationToAutomatedEvaluationId?: string;
}[];
outputComments: {
value: string;
inRelationToGradeName?: string;
inRelationToAutomatedEvaluationId?: string;
}[];
}
Copy link

Choose a reason for hiding this comment

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

Inconsistent representation of reviewer information

In HumanReviewJob, the reviewer is represented as an object with id and email:

reviewer: { id: string; email: string };

However, in HumanReviewJobTestCaseResult, the reviewer is represented by a single reviewerEmail string property:

reviewerEmail: string;

For consistency and future extensibility, consider representing the reviewer in HumanReviewJobTestCaseResult as an object similar to HumanReviewJob.


interface ClientArgs {
apiKey?: string;
timeout?: TimeDelta;
Expand Down Expand Up @@ -175,4 +228,21 @@ export class AutoblocksAPIClient {
}): Promise<{ testCases: ManagedTestCase<T>[] }> {
return this.get(`/test-suites/${args.testSuiteId}/test-cases`);
}

public async getHumanReviewJobs(): Promise<{ jobs: HumanReviewJob[] }> {
return this.get('/human-review/jobs');
}
Comment on lines +234 to +236
Copy link

Choose a reason for hiding this comment

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

Consider consistent return types for methods

The getHumanReviewJobs method returns Promise<{ jobs: HumanReviewJob[] }>, wrapping the array in an object. However, other methods like getViews() return arrays directly as Promise<View[]>.

For consistency, consider returning Promise<HumanReviewJob[]> directly, unless the API response necessitates the wrapping object.


public async getHumanReviewJobTestCases(
jobId: string,
): Promise<HumanReviewJobWithTestCases> {
return this.get(`/human-review/jobs/${jobId}/test-cases`);
}
Copy link

Choose a reason for hiding this comment

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

Ensure proper encoding of jobId in URL

When constructing the URL in getHumanReviewJobTestCases, consider encoding jobId to handle any special characters that may be present.

Apply this diff to encode the jobId:

-        return this.get(`/human-review/jobs/${jobId}/test-cases`);
+        return this.get(`/human-review/jobs/${encodeURIComponent(jobId)}/test-cases`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public async getHumanReviewJobTestCases(
jobId: string,
): Promise<HumanReviewJobWithTestCases> {
return this.get(`/human-review/jobs/${jobId}/test-cases`);
}
public async getHumanReviewJobTestCases(
jobId: string,
): Promise<HumanReviewJobWithTestCases> {
return this.get(`/human-review/jobs/${encodeURIComponent(jobId)}/test-cases`);
}


public async getHumanReviewJobTestCaseResult(
jobId: string,
testCaseId: string,
): Promise<HumanReviewJobTestCaseResult> {
return this.get(`/human-review/jobs/${jobId}/test-cases/${testCaseId}`);
}
Copy link

Choose a reason for hiding this comment

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

Add unit tests for new API methods

Consider adding unit tests for the newly added methods to ensure they function correctly and handle potential errors.

Copy link

Choose a reason for hiding this comment

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

Ensure proper encoding of jobId and testCaseId in URL

In getHumanReviewJobTestCaseResult, to prevent issues with special characters in jobId and testCaseId, consider encoding these parameters when constructing the URL.

Apply this diff to encode the parameters:

-        return this.get(`/human-review/jobs/${jobId}/test-cases/${testCaseId}`);
+        return this.get(`/human-review/jobs/${encodeURIComponent(jobId)}/test-cases/${encodeURIComponent(testCaseId)}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public async getHumanReviewJobTestCaseResult(
jobId: string,
testCaseId: string,
): Promise<HumanReviewJobTestCaseResult> {
return this.get(`/human-review/jobs/${jobId}/test-cases/${testCaseId}`);
}
public async getHumanReviewJobTestCaseResult(
jobId: string,
testCaseId: string,
): Promise<HumanReviewJobTestCaseResult> {
return this.get(`/human-review/jobs/${encodeURIComponent(jobId)}/test-cases/${encodeURIComponent(testCaseId)}`);
}

}
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export { AutoblocksTracer, flush } from './tracer';
export { AutoblocksAPIClient, SystemEventFilterKey } from './client';
export { dedent } from './util';
export type { View, Event, Trace } from './client';
export type { TimeDelta } from './types';
export type {
View,
Event,
Trace,
HumanReviewJob,
HumanReviewJobWithTestCases,
HumanReviewJobTestCaseResult,
} from './client';
export type { TimeDelta, HumanReviewFieldContentType } from './types';
2 changes: 1 addition & 1 deletion src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export {
type EvaluationOverrideField,
type ScoreChoice,
type HumanReviewField,
HumanReviewFieldContentType,
} from './models';
export { HumanReviewFieldContentType } from '../types';
export { RunManager } from './run-manager';
export { gridSearchAsyncLocalStorage } from '../asyncLocalStorage';
export {
Expand Down
8 changes: 1 addition & 7 deletions src/testing/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArbitraryProperties } from '../types';
import { HumanReviewFieldContentType } from '../types';

export interface Threshold {
lt?: number;
Expand Down Expand Up @@ -87,13 +88,6 @@ export abstract class BaseEvaluator<TestCaseType, OutputType>
}): Evaluation | Promise<Evaluation>;
}

export enum HumanReviewFieldContentType {
TEXT = 'text',
LINK = 'link',
HTML = 'html',
MARKDOWN = 'markdown',
}

export interface HumanReviewField {
name: string;
value: string;
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ export const zPromptSchema = z.object({
});

export type Prompt = z.infer<typeof zPromptSchema>;

export enum HumanReviewFieldContentType {
TEXT = 'text',
MARKDOWN = 'markdown',
HTML = 'html',
LINK = 'link',
}