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 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
82 changes: 80 additions & 2 deletions 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;
reviewer: { id: string; email: 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;
}[];
}

interface ClientArgs {
apiKey?: string;
timeout?: TimeDelta;
Expand Down Expand Up @@ -151,7 +204,9 @@ export class AutoblocksAPIClient {
if (args.cursor) {
params.set('cursor', args.cursor);
}
return this.get(`/views/${args.viewId}/traces?${params.toString()}`);
return this.get(
`/views/${encodeURIComponent(args.viewId)}/traces?${params.toString()}`,
);
}

public async searchTraces(args: {
Expand All @@ -175,4 +230,27 @@ 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 getTestCasesForHumanReviewJob(args: {
jobId: string;
}): Promise<HumanReviewJobWithTestCases> {
return this.get(
`/human-review/jobs/${encodeURIComponent(args.jobId)}/test-cases`,
);
}

public async getTestCaseResultForHumanReviewJob(args: {
jobId: string;
testCaseId: string;
}): Promise<HumanReviewJobTestCaseResult> {
return this.get(
`/human-review/jobs/${encodeURIComponent(args.jobId)}/test-cases/${encodeURIComponent(
args.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',
}