notdiamond 2.0.0-rc1 → 2.0.0-rc11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/LICENSE +1 -1
- package/README.md +327 -124
- package/client.d.mts +28 -42
- package/client.d.mts.map +1 -1
- package/client.d.ts +28 -42
- package/client.d.ts.map +1 -1
- package/client.js +52 -68
- package/client.js.map +1 -1
- package/client.mjs +50 -66
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +2 -2
- package/core/api-promise.d.ts +2 -2
- package/core/error.d.mts +2 -2
- package/core/error.d.ts +2 -2
- package/core/error.js +4 -4
- package/core/error.mjs +2 -2
- package/core/resource.d.mts +3 -3
- package/core/resource.d.ts +3 -3
- package/index.d.mts +3 -3
- package/index.d.ts +3 -3
- package/index.js +4 -4
- package/index.mjs +3 -3
- package/internal/parse.d.mts +2 -2
- package/internal/parse.d.ts +2 -2
- package/internal/shims.js +1 -1
- package/internal/shims.mjs +1 -1
- package/internal/tslib.js +17 -17
- package/internal/uploads.d.mts +4 -4
- package/internal/uploads.d.ts +4 -4
- package/internal/utils/base64.js +2 -2
- package/internal/utils/base64.mjs +3 -3
- package/internal/utils/env.d.mts.map +1 -1
- package/internal/utils/env.d.ts.map +1 -1
- package/internal/utils/env.js +4 -2
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +4 -2
- package/internal/utils/env.mjs.map +1 -1
- package/internal/utils/log.d.mts +3 -3
- package/internal/utils/log.d.ts +3 -3
- package/internal/utils/path.js +1 -1
- package/internal/utils/path.mjs +2 -2
- package/internal/utils/values.js +5 -5
- package/internal/utils/values.mjs +6 -6
- package/package.json +11 -12
- package/resources/custom-router.d.mts +145 -0
- package/resources/custom-router.d.mts.map +1 -0
- package/resources/custom-router.d.ts +145 -0
- package/resources/custom-router.d.ts.map +1 -0
- package/resources/custom-router.js +83 -0
- package/resources/custom-router.js.map +1 -0
- package/resources/custom-router.mjs +79 -0
- package/resources/custom-router.mjs.map +1 -0
- package/resources/index.d.mts +6 -6
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +6 -6
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +6 -6
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +3 -3
- package/resources/index.mjs.map +1 -1
- package/resources/model-router.d.mts +196 -0
- package/resources/model-router.d.mts.map +1 -0
- package/resources/model-router.d.ts +196 -0
- package/resources/model-router.d.ts.map +1 -0
- package/resources/model-router.js +70 -0
- package/resources/model-router.js.map +1 -0
- package/resources/model-router.mjs +66 -0
- package/resources/model-router.mjs.map +1 -0
- package/resources/models.d.mts +50 -25
- package/resources/models.d.mts.map +1 -1
- package/resources/models.d.ts +50 -25
- package/resources/models.d.ts.map +1 -1
- package/resources/models.js +5 -0
- package/resources/models.js.map +1 -1
- package/resources/models.mjs +5 -0
- package/resources/models.mjs.map +1 -1
- package/resources/preferences.d.mts +34 -48
- package/resources/preferences.d.mts.map +1 -1
- package/resources/preferences.d.ts +34 -48
- package/resources/preferences.d.ts.map +1 -1
- package/resources/preferences.js +14 -36
- package/resources/preferences.js.map +1 -1
- package/resources/preferences.mjs +14 -36
- package/resources/preferences.mjs.map +1 -1
- package/resources/prompt-adaptation.d.mts +339 -234
- package/resources/prompt-adaptation.d.mts.map +1 -1
- package/resources/prompt-adaptation.d.ts +339 -234
- package/resources/prompt-adaptation.d.ts.map +1 -1
- package/resources/prompt-adaptation.js +30 -53
- package/resources/prompt-adaptation.js.map +1 -1
- package/resources/prompt-adaptation.mjs +30 -53
- package/resources/prompt-adaptation.mjs.map +1 -1
- package/resources/report/index.d.mts +3 -0
- package/resources/report/index.d.mts.map +1 -0
- package/resources/report/index.d.ts +3 -0
- package/resources/report/index.d.ts.map +1 -0
- package/resources/report/index.js +9 -0
- package/resources/report/index.js.map +1 -0
- package/resources/report/index.mjs +4 -0
- package/resources/report/index.mjs.map +1 -0
- package/resources/report/metrics.d.mts +87 -0
- package/resources/report/metrics.d.mts.map +1 -0
- package/resources/report/metrics.d.ts +87 -0
- package/resources/report/metrics.d.ts.map +1 -0
- package/resources/report/metrics.js +57 -0
- package/resources/report/metrics.js.map +1 -0
- package/resources/report/metrics.mjs +53 -0
- package/resources/report/metrics.mjs.map +1 -0
- package/resources/report/report.d.mts +10 -0
- package/resources/report/report.d.mts.map +1 -0
- package/resources/report/report.d.ts +10 -0
- package/resources/report/report.d.ts.map +1 -0
- package/resources/report/report.js +17 -0
- package/resources/report/report.js.map +1 -0
- package/resources/report/report.mjs +12 -0
- package/resources/report/report.mjs.map +1 -0
- package/resources/report.d.mts +1 -244
- package/resources/report.d.mts.map +1 -1
- package/resources/report.d.ts +1 -244
- package/resources/report.d.ts.map +1 -1
- package/resources/report.js +2 -82
- package/resources/report.js.map +1 -1
- package/resources/report.mjs +1 -80
- package/resources/report.mjs.map +1 -1
- package/src/client.ts +80 -131
- package/src/core/api-promise.ts +4 -4
- package/src/core/error.ts +2 -2
- package/src/core/resource.ts +3 -3
- package/src/index.ts +3 -3
- package/src/internal/parse.ts +2 -2
- package/src/internal/shims.ts +1 -1
- package/src/internal/uploads.ts +5 -5
- package/src/internal/utils/base64.ts +3 -3
- package/src/internal/utils/env.ts +4 -2
- package/src/internal/utils/log.ts +3 -3
- package/src/internal/utils/path.ts +2 -2
- package/src/internal/utils/values.ts +6 -6
- package/src/resources/custom-router.ts +168 -0
- package/src/resources/index.ts +23 -34
- package/src/resources/model-router.ts +224 -0
- package/src/resources/models.ts +55 -32
- package/src/resources/preferences.ts +40 -77
- package/src/resources/prompt-adaptation.ts +361 -291
- package/src/resources/report/index.ts +4 -0
- package/src/resources/report/metrics.ts +99 -0
- package/src/resources/report/report.ts +19 -0
- package/src/resources/report.ts +1 -298
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/resources/admin.d.mts +0 -4
- package/resources/admin.d.mts.map +0 -1
- package/resources/admin.d.ts +0 -4
- package/resources/admin.d.ts.map +0 -1
- package/resources/admin.js +0 -9
- package/resources/admin.js.map +0 -1
- package/resources/admin.mjs +0 -5
- package/resources/admin.mjs.map +0 -1
- package/resources/routing.d.mts +0 -391
- package/resources/routing.d.mts.map +0 -1
- package/resources/routing.d.ts +0 -391
- package/resources/routing.d.ts.map +0 -1
- package/resources/routing.js +0 -163
- package/resources/routing.js.map +0 -1
- package/resources/routing.mjs +0 -159
- package/resources/routing.mjs.map +0 -1
- package/src/resources/admin.ts +0 -5
- package/src/resources/routing.ts +0 -476
package/src/internal/uploads.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RequestOptions } from './request-options';
|
|
2
2
|
import type { FilePropertyBag, Fetch } from './builtin-types';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Notdiamond } from '../client';
|
|
4
4
|
import { ReadableStreamFrom } from './shims';
|
|
5
5
|
|
|
6
6
|
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
@@ -74,7 +74,7 @@ export const isAsyncIterable = (value: any): value is AsyncIterable<any> =>
|
|
|
74
74
|
*/
|
|
75
75
|
export const maybeMultipartFormRequestOptions = async (
|
|
76
76
|
opts: RequestOptions,
|
|
77
|
-
fetch:
|
|
77
|
+
fetch: Notdiamond | Fetch,
|
|
78
78
|
): Promise<RequestOptions> => {
|
|
79
79
|
if (!hasUploadableValue(opts.body)) return opts;
|
|
80
80
|
|
|
@@ -85,7 +85,7 @@ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknow
|
|
|
85
85
|
|
|
86
86
|
export const multipartFormRequestOptions = async (
|
|
87
87
|
opts: MultipartFormRequestOptions,
|
|
88
|
-
fetch:
|
|
88
|
+
fetch: Notdiamond | Fetch,
|
|
89
89
|
): Promise<RequestOptions> => {
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
@@ -98,7 +98,7 @@ const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>
|
|
|
98
98
|
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
99
99
|
* confusing error messages later on.
|
|
100
100
|
*/
|
|
101
|
-
function supportsFormData(fetchObject:
|
|
101
|
+
function supportsFormData(fetchObject: Notdiamond | Fetch): Promise<boolean> {
|
|
102
102
|
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
|
103
103
|
const cached = supportsFormDataMap.get(fetch);
|
|
104
104
|
if (cached) return cached;
|
|
@@ -124,7 +124,7 @@ function supportsFormData(fetchObject: NotDiamond | Fetch): Promise<boolean> {
|
|
|
124
124
|
|
|
125
125
|
export const createForm = async <T = Record<string, unknown>>(
|
|
126
126
|
body: T | undefined,
|
|
127
|
-
fetch:
|
|
127
|
+
fetch: Notdiamond | Fetch,
|
|
128
128
|
): Promise<FormData> => {
|
|
129
129
|
if (!(await supportsFormData(fetch))) {
|
|
130
130
|
throw new TypeError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NotdiamondError } from '../../core/error';
|
|
4
4
|
import { encodeUTF8 } from './bytes';
|
|
5
5
|
|
|
6
6
|
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
@@ -18,7 +18,7 @@ export const toBase64 = (data: string | Uint8Array | null | undefined): string =
|
|
|
18
18
|
return btoa(String.fromCharCode.apply(null, data as any));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
throw new
|
|
21
|
+
throw new NotdiamondError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const fromBase64 = (str: string): Uint8Array => {
|
|
@@ -36,5 +36,5 @@ export const fromBase64 = (str: string): Uint8Array => {
|
|
|
36
36
|
return buf;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
throw new
|
|
39
|
+
throw new NotdiamondError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
40
40
|
};
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export const readEnv = (env: string): string | undefined => {
|
|
11
11
|
if (typeof (globalThis as any).process !== 'undefined') {
|
|
12
|
-
|
|
12
|
+
const value = (globalThis as any).process.env?.[env]?.trim() ?? undefined;
|
|
13
|
+
return value === '' ? undefined : value;
|
|
13
14
|
}
|
|
14
15
|
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
15
|
-
|
|
16
|
+
const value = (globalThis as any).Deno.env?.get?.(env)?.trim();
|
|
17
|
+
return value === '' ? undefined : value;
|
|
16
18
|
}
|
|
17
19
|
return undefined;
|
|
18
20
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { hasOwn } from './values';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Notdiamond } from '../../client';
|
|
5
5
|
import { RequestOptions } from '../request-options';
|
|
6
6
|
|
|
7
7
|
type LogFn = (message: string, ...rest: unknown[]) => void;
|
|
@@ -24,7 +24,7 @@ const levelNumbers = {
|
|
|
24
24
|
export const parseLogLevel = (
|
|
25
25
|
maybeLevel: string | undefined,
|
|
26
26
|
sourceName: string,
|
|
27
|
-
client:
|
|
27
|
+
client: Notdiamond,
|
|
28
28
|
): LogLevel | undefined => {
|
|
29
29
|
if (!maybeLevel) {
|
|
30
30
|
return undefined;
|
|
@@ -60,7 +60,7 @@ const noopLogger = {
|
|
|
60
60
|
|
|
61
61
|
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
|
-
export function loggerFor(client:
|
|
63
|
+
export function loggerFor(client: Notdiamond): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
65
65
|
const logLevel = client.logLevel ?? 'off';
|
|
66
66
|
if (!logger) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotdiamondError } from '../../core/error';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
@@ -72,7 +72,7 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
72
72
|
return acc + spaces + arrows;
|
|
73
73
|
}, '');
|
|
74
74
|
|
|
75
|
-
throw new
|
|
75
|
+
throw new NotdiamondError(
|
|
76
76
|
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
77
|
.map((e) => e.error)
|
|
78
78
|
.join('\n')}\n${path}\n${underline}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NotdiamondError } from '../../core/error';
|
|
4
4
|
|
|
5
5
|
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
6
|
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
@@ -39,7 +39,7 @@ export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
|
39
39
|
|
|
40
40
|
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
41
41
|
if (value == null) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new NotdiamondError(`Expected a value to be given but received ${value} instead.`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
return value;
|
|
@@ -47,10 +47,10 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
|
47
47
|
|
|
48
48
|
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
49
49
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new NotdiamondError(`${name} must be an integer`);
|
|
51
51
|
}
|
|
52
52
|
if (n < 0) {
|
|
53
|
-
throw new
|
|
53
|
+
throw new NotdiamondError(`${name} must be a positive integer`);
|
|
54
54
|
}
|
|
55
55
|
return n;
|
|
56
56
|
};
|
|
@@ -59,14 +59,14 @@ export const coerceInteger = (value: unknown): number => {
|
|
|
59
59
|
if (typeof value === 'number') return Math.round(value);
|
|
60
60
|
if (typeof value === 'string') return parseInt(value, 10);
|
|
61
61
|
|
|
62
|
-
throw new
|
|
62
|
+
throw new NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
export const coerceFloat = (value: unknown): number => {
|
|
66
66
|
if (typeof value === 'number') return value;
|
|
67
67
|
if (typeof value === 'string') return parseFloat(value);
|
|
68
68
|
|
|
69
|
-
throw new
|
|
69
|
+
throw new NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export const coerceBoolean = (value: unknown): boolean => {
|
|
@@ -0,0 +1,168 @@
|
|
|
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 { type Uploadable } from '../core/uploads';
|
|
6
|
+
import { RequestOptions } from '../internal/request-options';
|
|
7
|
+
import { multipartFormRequestOptions } from '../internal/uploads';
|
|
8
|
+
|
|
9
|
+
export class CustomRouter extends APIResource {
|
|
10
|
+
/**
|
|
11
|
+
* Train a custom router on your evaluation data to optimize routing for your
|
|
12
|
+
* specific use case.
|
|
13
|
+
*
|
|
14
|
+
* This endpoint allows you to train a domain-specific router that learns which
|
|
15
|
+
* models perform best for different types of queries in your application. The
|
|
16
|
+
* router analyzes your evaluation dataset, clusters similar queries, and learns
|
|
17
|
+
* model performance patterns.
|
|
18
|
+
*
|
|
19
|
+
* **Training Process:**
|
|
20
|
+
*
|
|
21
|
+
* 1. Upload a CSV file with your evaluation data
|
|
22
|
+
* 2. Specify which models to route between
|
|
23
|
+
* 3. Define the evaluation metric (score column)
|
|
24
|
+
* 4. The system trains asynchronously and returns a preference_id
|
|
25
|
+
* 5. Use the preference_id in model_select() calls once training completes
|
|
26
|
+
*
|
|
27
|
+
* **Dataset Requirements:**
|
|
28
|
+
*
|
|
29
|
+
* - Format: CSV file
|
|
30
|
+
* - Minimum samples: 25 (more is better for accuracy)
|
|
31
|
+
* - Required columns:
|
|
32
|
+
* - Prompt column (specified in prompt_column parameter)
|
|
33
|
+
* - For each model: `{provider}/{model}/score` and `{provider}/{model}/response`
|
|
34
|
+
*
|
|
35
|
+
* **Example CSV structure:**
|
|
36
|
+
*
|
|
37
|
+
* ```
|
|
38
|
+
* prompt,openai/gpt-4o/score,openai/gpt-4o/response,anthropic/claude-sonnet-4-5-20250929/score,anthropic/claude-sonnet-4-5-20250929/response
|
|
39
|
+
* "Explain quantum computing",0.95,"Quantum computing uses...",0.87,"Quantum computers leverage..."
|
|
40
|
+
* "Write a Python function",0.82,"def my_function()...",0.91,"Here's a Python function..."
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* **Model Selection:**
|
|
44
|
+
*
|
|
45
|
+
* - Specify standard models: `{"provider": "openai", "model": "gpt-4o"}`
|
|
46
|
+
* - Or custom models with pricing:
|
|
47
|
+
* `{"provider": "custom", "model": "my-model", "is_custom": true, "input_price": 10.0, "output_price": 30.0, "context_length": 8192, "latency": 1.5}`
|
|
48
|
+
*
|
|
49
|
+
* **Training Time:**
|
|
50
|
+
*
|
|
51
|
+
* - Training is asynchronous and typically takes 5-15 minutes
|
|
52
|
+
* - Larger datasets or more models take longer
|
|
53
|
+
* - You'll receive a preference_id immediately
|
|
54
|
+
* - Check training status by attempting to use the preference_id in model_select()
|
|
55
|
+
*
|
|
56
|
+
* **Best Practices:**
|
|
57
|
+
*
|
|
58
|
+
* 1. Use diverse, representative examples from your production workload
|
|
59
|
+
* 2. Include at least 50-100 samples for best results
|
|
60
|
+
* 3. Ensure consistent evaluation metrics across all models
|
|
61
|
+
* 4. Use the same models you plan to route between in production
|
|
62
|
+
*
|
|
63
|
+
* **Related Documentation:** See
|
|
64
|
+
* https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models for detailed
|
|
65
|
+
* guide.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const response =
|
|
70
|
+
* await client.customRouter.trainCustomRouter({
|
|
71
|
+
* dataset_file: fs.createReadStream('path/to/file'),
|
|
72
|
+
* language: 'english',
|
|
73
|
+
* llm_providers:
|
|
74
|
+
* '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
|
|
75
|
+
* maximize: true,
|
|
76
|
+
* prompt_column: 'prompt',
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
trainCustomRouter(
|
|
81
|
+
body: CustomRouterTrainCustomRouterParams,
|
|
82
|
+
options?: RequestOptions,
|
|
83
|
+
): APIPromise<CustomRouterTrainCustomRouterResponse> {
|
|
84
|
+
return this._client.post(
|
|
85
|
+
'/v2/pzn/trainCustomRouter',
|
|
86
|
+
multipartFormRequestOptions({ body, ...options }, this._client),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Response model for POST /v2/pzn/trainCustomRouter endpoint.
|
|
93
|
+
*
|
|
94
|
+
* Returned immediately after submitting a custom router training request. The
|
|
95
|
+
* training process runs asynchronously (typically 5-15 minutes), so use the
|
|
96
|
+
* returned preference_id to make routing calls once training completes.
|
|
97
|
+
*
|
|
98
|
+
* **Next steps:**
|
|
99
|
+
*
|
|
100
|
+
* 1. Store the preference_id
|
|
101
|
+
* 2. Wait for training to complete (typically 5-15 minutes)
|
|
102
|
+
* 3. Use this preference_id in POST /v2/modelRouter/modelSelect requests
|
|
103
|
+
* 4. The router will use your custom-trained model to make routing decisions
|
|
104
|
+
*
|
|
105
|
+
* **How to use the preference_id:**
|
|
106
|
+
*
|
|
107
|
+
* - Include it in the 'preference_id' field of model_select() calls
|
|
108
|
+
* - The system automatically uses your custom router once training is complete
|
|
109
|
+
* - No need to poll status - you can start using it immediately (will use default
|
|
110
|
+
* until ready)
|
|
111
|
+
*/
|
|
112
|
+
export interface CustomRouterTrainCustomRouterResponse {
|
|
113
|
+
/**
|
|
114
|
+
* Unique identifier for the custom router. Use this in model_select() calls to
|
|
115
|
+
* enable routing with your custom-trained router
|
|
116
|
+
*/
|
|
117
|
+
preference_id: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface CustomRouterTrainCustomRouterParams {
|
|
121
|
+
/**
|
|
122
|
+
* CSV file containing evaluation data with prompt column and score/response
|
|
123
|
+
* columns for each model
|
|
124
|
+
*/
|
|
125
|
+
dataset_file: Uploadable;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Language of the evaluation data. Use 'english' for English-only data or
|
|
129
|
+
* 'multilingual' for multi-language support
|
|
130
|
+
*/
|
|
131
|
+
language: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* JSON string array of LLM providers to train the router on. Format:
|
|
135
|
+
* '[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model":
|
|
136
|
+
* "claude-sonnet-4-5-20250929"}]'
|
|
137
|
+
*/
|
|
138
|
+
llm_providers: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Whether higher scores are better. Set to true if higher scores indicate better
|
|
142
|
+
* performance, false otherwise
|
|
143
|
+
*/
|
|
144
|
+
maximize: boolean;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Name of the column in the CSV file that contains the prompts
|
|
148
|
+
*/
|
|
149
|
+
prompt_column: string;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Whether to override an existing custom router for this preference_id
|
|
153
|
+
*/
|
|
154
|
+
override?: boolean | null;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Optional preference ID to update an existing router. If not provided, a new
|
|
158
|
+
* preference will be created
|
|
159
|
+
*/
|
|
160
|
+
preference_id?: string | null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export declare namespace CustomRouter {
|
|
164
|
+
export {
|
|
165
|
+
type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse,
|
|
166
|
+
type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams,
|
|
167
|
+
};
|
|
168
|
+
}
|
package/src/resources/index.ts
CHANGED
|
@@ -1,44 +1,33 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
4
|
-
|
|
3
|
+
export {
|
|
4
|
+
CustomRouter,
|
|
5
|
+
type CustomRouterTrainCustomRouterResponse,
|
|
6
|
+
type CustomRouterTrainCustomRouterParams,
|
|
7
|
+
} from './custom-router';
|
|
8
|
+
export {
|
|
9
|
+
ModelRouter,
|
|
10
|
+
type ModelRouterSelectModelResponse,
|
|
11
|
+
type ModelRouterSelectModelParams,
|
|
12
|
+
} from './model-router';
|
|
13
|
+
export { Models, type Model, type ModelListResponse, type ModelListParams } from './models';
|
|
5
14
|
export {
|
|
6
15
|
Preferences,
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
type PreferenceCreateUserPreferenceParams,
|
|
13
|
-
type PreferenceUpdateUserPreferenceParams,
|
|
16
|
+
type PreferenceCreateResponse,
|
|
17
|
+
type PreferenceUpdateResponse,
|
|
18
|
+
type PreferenceDeleteResponse,
|
|
19
|
+
type PreferenceCreateParams,
|
|
20
|
+
type PreferenceUpdateParams,
|
|
14
21
|
} from './preferences';
|
|
15
22
|
export {
|
|
16
23
|
PromptAdaptation,
|
|
17
|
-
type
|
|
24
|
+
type GoldenRecord,
|
|
18
25
|
type JobStatus,
|
|
19
|
-
type
|
|
20
|
-
type
|
|
26
|
+
type RequestProvider,
|
|
27
|
+
type PromptAdaptationCreateResponse,
|
|
28
|
+
type PromptAdaptationGetAdaptResultsResponse,
|
|
21
29
|
type PromptAdaptationGetAdaptStatusResponse,
|
|
22
|
-
type
|
|
23
|
-
type
|
|
24
|
-
type PromptAdaptationGetAdaptRunResultsParams,
|
|
25
|
-
type PromptAdaptationGetAdaptRunsParams,
|
|
30
|
+
type PromptAdaptationGetCostsResponse,
|
|
31
|
+
type PromptAdaptationCreateParams,
|
|
26
32
|
} from './prompt-adaptation';
|
|
27
|
-
export {
|
|
28
|
-
Report,
|
|
29
|
-
type ReportEvaluateHallucinationResponse,
|
|
30
|
-
type ReportLatencyResponse,
|
|
31
|
-
type ReportSubmitFeedbackResponse,
|
|
32
|
-
type ReportEvaluateHallucinationParams,
|
|
33
|
-
type ReportLatencyParams,
|
|
34
|
-
type ReportSubmitFeedbackParams,
|
|
35
|
-
} from './report';
|
|
36
|
-
export {
|
|
37
|
-
Routing,
|
|
38
|
-
type RoutingCreateSurveyResponseResponse,
|
|
39
|
-
type RoutingSelectModelResponse,
|
|
40
|
-
type RoutingTrainCustomRouterResponse,
|
|
41
|
-
type RoutingCreateSurveyResponseParams,
|
|
42
|
-
type RoutingSelectModelParams,
|
|
43
|
-
type RoutingTrainCustomRouterParams,
|
|
44
|
-
} from './routing';
|
|
33
|
+
export { Report } from './report/report';
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
import * as PromptAdaptationAPI from './prompt-adaptation';
|
|
5
|
+
import { APIPromise } from '../core/api-promise';
|
|
6
|
+
import { RequestOptions } from '../internal/request-options';
|
|
7
|
+
|
|
8
|
+
export class ModelRouter extends APIResource {
|
|
9
|
+
/**
|
|
10
|
+
* Select the optimal LLM to handle your query based on Not Diamond's routing
|
|
11
|
+
* algorithm.
|
|
12
|
+
*
|
|
13
|
+
* This endpoint analyzes your messages and returns the best-suited model from your
|
|
14
|
+
* specified providers. The router considers factors like query complexity, model
|
|
15
|
+
* capabilities, cost, and latency based on your preferences.
|
|
16
|
+
*
|
|
17
|
+
* **Key Features:**
|
|
18
|
+
*
|
|
19
|
+
* - Intelligent routing across multiple LLM providers
|
|
20
|
+
* - Support for custom routers trained on your evaluation data
|
|
21
|
+
* - Optional cost/latency optimization
|
|
22
|
+
* - Function calling support for compatible models
|
|
23
|
+
* - Privacy-preserving content hashing
|
|
24
|
+
*
|
|
25
|
+
* **Usage:**
|
|
26
|
+
*
|
|
27
|
+
* 1. Pass your messages in OpenAI format (array of objects with 'role' and
|
|
28
|
+
* 'content')
|
|
29
|
+
* 2. Specify which LLM providers you want to route between
|
|
30
|
+
* 3. Optionally provide a preference_id for personalized routing
|
|
31
|
+
* 4. Receive a recommended model and session_id
|
|
32
|
+
* 5. Use the session_id to submit feedback and improve routing
|
|
33
|
+
*
|
|
34
|
+
* **Related Endpoints:**
|
|
35
|
+
*
|
|
36
|
+
* - `POST /v2/preferences/userPreferenceCreate` - Create a preference ID for
|
|
37
|
+
* personalized routing
|
|
38
|
+
* - `POST /v2/report/metrics/feedback` - Submit feedback on routing decisions
|
|
39
|
+
* - `POST /v2/pzn/trainCustomRouter` - Train a custom router on your evaluation
|
|
40
|
+
* data
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const response = await client.modelRouter.selectModel({
|
|
45
|
+
* llm_providers: [
|
|
46
|
+
* { provider: 'openai', model: 'gpt-4o' },
|
|
47
|
+
* {
|
|
48
|
+
* provider: 'anthropic',
|
|
49
|
+
* model: 'claude-sonnet-4-5-20250929',
|
|
50
|
+
* },
|
|
51
|
+
* { provider: 'google', model: 'gemini-2.5-flash' },
|
|
52
|
+
* ],
|
|
53
|
+
* messages: [
|
|
54
|
+
* {
|
|
55
|
+
* role: 'system',
|
|
56
|
+
* content: 'You are a helpful assistant.',
|
|
57
|
+
* },
|
|
58
|
+
* {
|
|
59
|
+
* role: 'user',
|
|
60
|
+
* content: 'Explain quantum computing in simple terms',
|
|
61
|
+
* },
|
|
62
|
+
* ],
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
selectModel(
|
|
67
|
+
params: ModelRouterSelectModelParams,
|
|
68
|
+
options?: RequestOptions,
|
|
69
|
+
): APIPromise<ModelRouterSelectModelResponse> {
|
|
70
|
+
const { type, ...body } = params;
|
|
71
|
+
return this._client.post('/v2/modelRouter/modelSelect', { query: { type }, body, ...options });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Response from model selection endpoint.
|
|
77
|
+
*/
|
|
78
|
+
export interface ModelRouterSelectModelResponse {
|
|
79
|
+
/**
|
|
80
|
+
* List containing the selected provider
|
|
81
|
+
*/
|
|
82
|
+
providers: Array<ModelRouterSelectModelResponse.Provider>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Unique session ID for this routing decision
|
|
86
|
+
*/
|
|
87
|
+
session_id: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export namespace ModelRouterSelectModelResponse {
|
|
91
|
+
/**
|
|
92
|
+
* Selected LLM provider information from model selection endpoints.
|
|
93
|
+
*
|
|
94
|
+
* Part of ModelSelectResponse. Contains the provider and model that Not Diamond's
|
|
95
|
+
* routing algorithm selected as optimal for your query. Use these values to make
|
|
96
|
+
* your LLM API call to the recommended model.
|
|
97
|
+
*/
|
|
98
|
+
export interface Provider {
|
|
99
|
+
/**
|
|
100
|
+
* Model identifier for the selected model (e.g., 'gpt-4o',
|
|
101
|
+
* 'claude-3-opus-20240229')
|
|
102
|
+
*/
|
|
103
|
+
model: string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Provider name for the selected model (e.g., 'openai', 'anthropic', 'google')
|
|
107
|
+
*/
|
|
108
|
+
provider: string;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface ModelRouterSelectModelParams {
|
|
113
|
+
/**
|
|
114
|
+
* Body param: List of LLM providers to route between. Specify at least one
|
|
115
|
+
* provider in format {provider, model}
|
|
116
|
+
*/
|
|
117
|
+
llm_providers: Array<PromptAdaptationAPI.RequestProvider | ModelRouterSelectModelParams.OpenRouterProvider>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Body param: Array of message objects in OpenAI format (with 'role' and 'content'
|
|
121
|
+
* keys)
|
|
122
|
+
*/
|
|
123
|
+
messages: Array<{ [key: string]: string | Array<unknown> }> | string;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Query param: Optional format type. Use 'openrouter' to accept and return
|
|
127
|
+
* OpenRouter-format model identifiers
|
|
128
|
+
*/
|
|
129
|
+
type?: string | null;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Body param: Whether to hash message content for privacy
|
|
133
|
+
*/
|
|
134
|
+
hash_content?: boolean;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Body param: Maximum number of models to consider for routing. If not specified,
|
|
138
|
+
* considers all provided models
|
|
139
|
+
*/
|
|
140
|
+
max_model_depth?: number | null;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Body param: Optimization metric for model selection
|
|
144
|
+
*/
|
|
145
|
+
metric?: string;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Body param: Preference ID for personalized routing. Create one via POST
|
|
149
|
+
* /v2/preferences/userPreferenceCreate
|
|
150
|
+
*/
|
|
151
|
+
preference_id?: string | null;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Body param: Previous session ID to link related requests
|
|
155
|
+
*/
|
|
156
|
+
previous_session?: string | null;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Body param: OpenAI-format function calling tools
|
|
160
|
+
*/
|
|
161
|
+
tools?: Array<{ [key: string]: unknown }> | null;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Body param: Optimization tradeoff strategy. Use 'cost' to prioritize cost
|
|
165
|
+
* savings or 'latency' to prioritize speed
|
|
166
|
+
*/
|
|
167
|
+
tradeoff?: string | null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export namespace ModelRouterSelectModelParams {
|
|
171
|
+
/**
|
|
172
|
+
* Model for specifying an LLM provider using OpenRouter format.
|
|
173
|
+
*
|
|
174
|
+
* Used in model routing requests when you want to specify providers using the
|
|
175
|
+
* OpenRouter naming convention (combined 'provider/model' format). This is an
|
|
176
|
+
* alternative to the standard RequestProvider which uses separate provider and
|
|
177
|
+
* model fields.
|
|
178
|
+
*
|
|
179
|
+
* **When to use:**
|
|
180
|
+
*
|
|
181
|
+
* - When working with OpenRouter-compatible systems
|
|
182
|
+
* - When you prefer the unified 'provider/model' format
|
|
183
|
+
* - For models accessed via OpenRouter proxy
|
|
184
|
+
*/
|
|
185
|
+
export interface OpenRouterProvider {
|
|
186
|
+
/**
|
|
187
|
+
* OpenRouter model identifier in 'provider/model' format (e.g., 'openai/gpt-4o',
|
|
188
|
+
* 'anthropic/claude-sonnet-4-5-20250929')
|
|
189
|
+
*/
|
|
190
|
+
model: string;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Maximum context length for the model (required for custom models)
|
|
194
|
+
*/
|
|
195
|
+
context_length?: number | null;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Input token price per million tokens in USD (required for custom models)
|
|
199
|
+
*/
|
|
200
|
+
input_price?: number | null;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether this is a custom model not in Not Diamond's supported model list
|
|
204
|
+
*/
|
|
205
|
+
is_custom?: boolean;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Average latency in seconds (required for custom models)
|
|
209
|
+
*/
|
|
210
|
+
latency?: number | null;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Output token price per million tokens in USD (required for custom models)
|
|
214
|
+
*/
|
|
215
|
+
output_price?: number | null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export declare namespace ModelRouter {
|
|
220
|
+
export {
|
|
221
|
+
type ModelRouterSelectModelResponse as ModelRouterSelectModelResponse,
|
|
222
|
+
type ModelRouterSelectModelParams as ModelRouterSelectModelParams,
|
|
223
|
+
};
|
|
224
|
+
}
|