Skip to content

Commit 0de80ed

Browse files
feat(api): add test evaluation method
1 parent 39b5704 commit 0de80ed

File tree

6 files changed

+155
-2
lines changed

6 files changed

+155
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
configured_endpoints: 18
1+
configured_endpoints: 19
22
openapi_spec_hash: 6a7cafc3d32e6701301e925175ab6614
3-
config_hash: 6dcf08c4324405f152d1da9fc11ab04a
3+
config_hash: 00442fdab71911b02ab1e10f9ec05b79

api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,13 @@ Types:
122122
Methods:
123123

124124
- <code title="post /storage/presigned-url">client.storage.presignedURL.<a href="./src/resources/storage/presigned-url.ts">create</a>({ ...params }) -> PresignedURLCreateResponse</code>
125+
126+
# Tests
127+
128+
Types:
129+
130+
- <code><a href="./src/resources/tests.ts">TestEvaluateResponse</a></code>
131+
132+
Methods:
133+
134+
- <code title="post /tests/{testId}/evaluate">client.tests.<a href="./src/resources/tests.ts">evaluate</a>(testID, { ...params }) -> TestEvaluateResponse</code>

src/client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as Errors from './core/error';
1717
import * as Uploads from './core/uploads';
1818
import * as API from './resources/index';
1919
import { APIPromise } from './core/api-promise';
20+
import { TestEvaluateParams, TestEvaluateResponse, Tests } from './resources/tests';
2021
import { CommitRetrieveResponse, Commits } from './resources/commits/commits';
2122
import {
2223
InferencePipelineRetrieveParams,
@@ -724,12 +725,14 @@ export class Openlayer {
724725
commits: API.Commits = new API.Commits(this);
725726
inferencePipelines: API.InferencePipelines = new API.InferencePipelines(this);
726727
storage: API.Storage = new API.Storage(this);
728+
tests: API.Tests = new API.Tests(this);
727729
}
728730

729731
Openlayer.Projects = Projects;
730732
Openlayer.Commits = Commits;
731733
Openlayer.InferencePipelines = InferencePipelines;
732734
Openlayer.Storage = Storage;
735+
Openlayer.Tests = Tests;
733736

734737
export declare namespace Openlayer {
735738
export type RequestOptions = Opts.RequestOptions;
@@ -753,4 +756,10 @@ export declare namespace Openlayer {
753756
};
754757

755758
export { Storage as Storage };
759+
760+
export {
761+
Tests as Tests,
762+
type TestEvaluateResponse as TestEvaluateResponse,
763+
type TestEvaluateParams as TestEvaluateParams,
764+
};
756765
}

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export {
1616
type ProjectListParams,
1717
} from './projects/projects';
1818
export { Storage } from './storage/storage';
19+
export { Tests, type TestEvaluateResponse, type TestEvaluateParams } from './tests';

src/resources/tests.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../core/resource';
4+
import { APIPromise } from '../core/api-promise';
5+
import { RequestOptions } from '../internal/request-options';
6+
import { path } from '../internal/utils/path';
7+
8+
export class Tests extends APIResource {
9+
/**
10+
* Triggers one-off evaluation of a specific monitoring test for a custom timestamp
11+
* range. This allows evaluating tests for historical data or custom time periods
12+
* outside the regular evaluation window schedule. It also allows overwriting the
13+
* existing test results.
14+
*
15+
* @example
16+
* ```ts
17+
* const response = await client.tests.evaluate(
18+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
19+
* { endTimestamp: 1700006400, startTimestamp: 1699920000 },
20+
* );
21+
* ```
22+
*/
23+
evaluate(
24+
testID: string,
25+
body: TestEvaluateParams,
26+
options?: RequestOptions,
27+
): APIPromise<TestEvaluateResponse> {
28+
return this._client.post(path`/tests/${testID}/evaluate`, { body, ...options });
29+
}
30+
}
31+
32+
export interface TestEvaluateResponse {
33+
message: string;
34+
35+
/**
36+
* Number of inference pipelines the test was queued for evaluation on
37+
*/
38+
pipelineCount: number;
39+
40+
/**
41+
* The end timestamp you requested (in seconds)
42+
*/
43+
requestedEndTimestamp: number;
44+
45+
/**
46+
* The start timestamp you requested (in seconds)
47+
*/
48+
requestedStartTimestamp: number;
49+
50+
/**
51+
* Array of background task information for each pipeline evaluation
52+
*/
53+
tasks: Array<TestEvaluateResponse.Task>;
54+
}
55+
56+
export namespace TestEvaluateResponse {
57+
export interface Task {
58+
/**
59+
* ID of the inference pipeline this task is for
60+
*/
61+
pipelineId: string;
62+
63+
/**
64+
* ID of the background task
65+
*/
66+
taskResultId: string;
67+
68+
/**
69+
* URL to check the status of this background task
70+
*/
71+
taskResultUrl: string;
72+
}
73+
}
74+
75+
export interface TestEvaluateParams {
76+
/**
77+
* End timestamp in seconds (Unix epoch)
78+
*/
79+
endTimestamp: number;
80+
81+
/**
82+
* Start timestamp in seconds (Unix epoch)
83+
*/
84+
startTimestamp: number;
85+
86+
/**
87+
* ID of the inference pipeline to evaluate. If not provided, all inference
88+
* pipelines the test applies to will be evaluated.
89+
*/
90+
inferencePipelineId?: string;
91+
92+
/**
93+
* Whether to overwrite existing test results
94+
*/
95+
overwriteResults?: boolean;
96+
}
97+
98+
export declare namespace Tests {
99+
export { type TestEvaluateResponse as TestEvaluateResponse, type TestEvaluateParams as TestEvaluateParams };
100+
}

tests/api-resources/tests.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Openlayer from 'openlayer';
4+
5+
const client = new Openlayer({
6+
apiKey: 'My API Key',
7+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
8+
});
9+
10+
describe('resource tests', () => {
11+
test('evaluate: only required params', async () => {
12+
const responsePromise = client.tests.evaluate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
13+
endTimestamp: 1700006400,
14+
startTimestamp: 1699920000,
15+
});
16+
const rawResponse = await responsePromise.asResponse();
17+
expect(rawResponse).toBeInstanceOf(Response);
18+
const response = await responsePromise;
19+
expect(response).not.toBeInstanceOf(Response);
20+
const dataAndResponse = await responsePromise.withResponse();
21+
expect(dataAndResponse.data).toBe(response);
22+
expect(dataAndResponse.response).toBe(rawResponse);
23+
});
24+
25+
test('evaluate: required and optional params', async () => {
26+
const response = await client.tests.evaluate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
27+
endTimestamp: 1700006400,
28+
startTimestamp: 1699920000,
29+
inferencePipelineId: '123e4567-e89b-12d3-a456-426614174000',
30+
overwriteResults: false,
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)