notdiamond 2.0.0-rc5 → 2.0.0
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 +156 -0
- package/LICENSE +1 -1
- package/README.md +294 -166
- package/client.d.mts +20 -23
- package/client.d.mts.map +1 -1
- package/client.d.ts +20 -23
- package/client.d.ts.map +1 -1
- package/client.js +41 -44
- package/client.js.map +1 -1
- package/client.mjs +39 -42
- 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/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 +3 -3
- package/resources/{pzn.d.mts → custom-router.d.mts} +16 -96
- package/resources/custom-router.d.mts.map +1 -0
- package/resources/{pzn.d.ts → custom-router.d.ts} +16 -96
- package/resources/custom-router.d.ts.map +1 -0
- package/resources/{pzn.js → custom-router.js} +13 -50
- package/resources/custom-router.js.map +1 -0
- package/resources/{pzn.mjs → custom-router.mjs} +11 -48
- package/resources/custom-router.mjs.map +1 -0
- package/resources/index.d.mts +4 -5
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +4 -5
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -7
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -3
- package/resources/index.mjs.map +1 -1
- package/resources/model-router.d.mts +6 -123
- package/resources/model-router.d.mts.map +1 -1
- package/resources/model-router.d.ts +6 -123
- package/resources/model-router.d.ts.map +1 -1
- package/resources/model-router.js +3 -32
- package/resources/model-router.js.map +1 -1
- package/resources/model-router.mjs +3 -32
- package/resources/model-router.mjs.map +1 -1
- package/resources/preferences.d.mts +4 -23
- package/resources/preferences.d.mts.map +1 -1
- package/resources/preferences.d.ts +4 -23
- package/resources/preferences.d.ts.map +1 -1
- package/resources/preferences.js +3 -25
- package/resources/preferences.js.map +1 -1
- package/resources/preferences.mjs +3 -25
- package/resources/preferences.mjs.map +1 -1
- package/resources/prompt-adaptation.d.mts +684 -0
- package/resources/prompt-adaptation.d.mts.map +1 -0
- package/resources/prompt-adaptation.d.ts +684 -0
- package/resources/prompt-adaptation.d.ts.map +1 -0
- package/resources/prompt-adaptation.js +258 -0
- package/resources/prompt-adaptation.js.map +1 -0
- package/resources/prompt-adaptation.mjs +254 -0
- package/resources/prompt-adaptation.mjs.map +1 -0
- package/src/client.ts +47 -54
- 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/log.ts +3 -3
- package/src/internal/utils/path.ts +2 -2
- package/src/internal/utils/values.ts +6 -6
- package/src/resources/{pzn.ts → custom-router.ts} +17 -122
- package/src/resources/index.ts +14 -16
- package/src/resources/model-router.ts +5 -139
- package/src/resources/preferences.ts +3 -34
- package/src/resources/prompt-adaptation.ts +777 -0
- 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/prompt/adapt.d.mts +0 -352
- package/resources/prompt/adapt.d.mts.map +0 -1
- package/resources/prompt/adapt.d.ts +0 -352
- package/resources/prompt/adapt.d.ts.map +0 -1
- package/resources/prompt/adapt.js +0 -154
- package/resources/prompt/adapt.js.map +0 -1
- package/resources/prompt/adapt.mjs +0 -150
- package/resources/prompt/adapt.mjs.map +0 -1
- package/resources/prompt/index.d.mts +0 -3
- package/resources/prompt/index.d.mts.map +0 -1
- package/resources/prompt/index.d.ts +0 -3
- package/resources/prompt/index.d.ts.map +0 -1
- package/resources/prompt/index.js +0 -9
- package/resources/prompt/index.js.map +0 -1
- package/resources/prompt/index.mjs +0 -4
- package/resources/prompt/index.mjs.map +0 -1
- package/resources/prompt/prompt.d.mts +0 -338
- package/resources/prompt/prompt.d.mts.map +0 -1
- package/resources/prompt/prompt.d.ts +0 -338
- package/resources/prompt/prompt.d.ts.map +0 -1
- package/resources/prompt/prompt.js +0 -128
- package/resources/prompt/prompt.js.map +0 -1
- package/resources/prompt/prompt.mjs +0 -123
- package/resources/prompt/prompt.mjs.map +0 -1
- package/resources/prompt.d.mts +0 -2
- package/resources/prompt.d.mts.map +0 -1
- package/resources/prompt.d.ts +0 -2
- package/resources/prompt.d.ts.map +0 -1
- package/resources/prompt.js +0 -6
- package/resources/prompt.js.map +0 -1
- package/resources/prompt.mjs +0 -3
- package/resources/prompt.mjs.map +0 -1
- package/resources/pzn.d.mts.map +0 -1
- package/resources/pzn.d.ts.map +0 -1
- package/resources/pzn.js.map +0 -1
- package/resources/pzn.mjs.map +0 -1
- package/resources/report/index.d.mts +0 -3
- package/resources/report/index.d.mts.map +0 -1
- package/resources/report/index.d.ts +0 -3
- package/resources/report/index.d.ts.map +0 -1
- package/resources/report/index.js +0 -9
- package/resources/report/index.js.map +0 -1
- package/resources/report/index.mjs +0 -4
- package/resources/report/index.mjs.map +0 -1
- package/resources/report/metrics.d.mts +0 -87
- package/resources/report/metrics.d.mts.map +0 -1
- package/resources/report/metrics.d.ts +0 -87
- package/resources/report/metrics.d.ts.map +0 -1
- package/resources/report/metrics.js +0 -57
- package/resources/report/metrics.js.map +0 -1
- package/resources/report/metrics.mjs +0 -53
- package/resources/report/metrics.mjs.map +0 -1
- package/resources/report/report.d.mts +0 -10
- package/resources/report/report.d.mts.map +0 -1
- package/resources/report/report.d.ts +0 -10
- package/resources/report/report.d.ts.map +0 -1
- package/resources/report/report.js +0 -17
- package/resources/report/report.js.map +0 -1
- package/resources/report/report.mjs +0 -12
- package/resources/report/report.mjs.map +0 -1
- package/resources/report.d.mts +0 -2
- package/resources/report.d.mts.map +0 -1
- package/resources/report.d.ts +0 -2
- package/resources/report.d.ts.map +0 -1
- package/resources/report.js +0 -6
- package/resources/report.js.map +0 -1
- package/resources/report.mjs +0 -3
- package/resources/report.mjs.map +0 -1
- package/src/resources/prompt/adapt.ts +0 -402
- package/src/resources/prompt/index.ts +0 -16
- package/src/resources/prompt/prompt.ts +0 -398
- package/src/resources/prompt.ts +0 -3
- package/src/resources/report/index.ts +0 -4
- package/src/resources/report/metrics.ts +0 -99
- package/src/resources/report/report.ts +0 -19
- package/src/resources/report.ts +0 -3
package/src/client.ts
CHANGED
|
@@ -17,10 +17,13 @@ import * as Errors from './core/error';
|
|
|
17
17
|
import * as Uploads from './core/uploads';
|
|
18
18
|
import * as API from './resources/index';
|
|
19
19
|
import { APIPromise } from './core/api-promise';
|
|
20
|
+
import {
|
|
21
|
+
CustomRouter,
|
|
22
|
+
CustomRouterTrainCustomRouterParams,
|
|
23
|
+
CustomRouterTrainCustomRouterResponse,
|
|
24
|
+
} from './resources/custom-router';
|
|
20
25
|
import {
|
|
21
26
|
ModelRouter,
|
|
22
|
-
ModelRouterOpenHandsSelectParams,
|
|
23
|
-
ModelRouterOpenHandsSelectResponse,
|
|
24
27
|
ModelRouterSelectModelParams,
|
|
25
28
|
ModelRouterSelectModelResponse,
|
|
26
29
|
} from './resources/model-router';
|
|
@@ -29,26 +32,21 @@ import {
|
|
|
29
32
|
PreferenceCreateParams,
|
|
30
33
|
PreferenceCreateResponse,
|
|
31
34
|
PreferenceDeleteResponse,
|
|
32
|
-
PreferenceRetrieveParams,
|
|
33
|
-
PreferenceRetrieveResponse,
|
|
34
35
|
PreferenceUpdateParams,
|
|
35
36
|
PreferenceUpdateResponse,
|
|
36
37
|
Preferences,
|
|
37
38
|
} from './resources/preferences';
|
|
38
39
|
import {
|
|
39
|
-
|
|
40
|
-
PznSubmitSurveyResponseParams,
|
|
41
|
-
PznSubmitSurveyResponseResponse,
|
|
42
|
-
PznTrainCustomRouterParams,
|
|
43
|
-
PznTrainCustomRouterResponse,
|
|
44
|
-
} from './resources/pzn';
|
|
45
|
-
import {
|
|
40
|
+
GoldenRecord,
|
|
46
41
|
JobStatus,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
PromptAdaptation,
|
|
43
|
+
PromptAdaptationAdaptParams,
|
|
44
|
+
PromptAdaptationAdaptResponse,
|
|
45
|
+
PromptAdaptationGetAdaptResultsResponse,
|
|
46
|
+
PromptAdaptationGetAdaptStatusResponse,
|
|
47
|
+
PromptAdaptationGetCostResponse,
|
|
48
|
+
RequestProvider,
|
|
49
|
+
} from './resources/prompt-adaptation';
|
|
52
50
|
import { type Fetch } from './internal/builtin-types';
|
|
53
51
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
54
52
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
@@ -71,7 +69,7 @@ export interface ClientOptions {
|
|
|
71
69
|
/**
|
|
72
70
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
73
71
|
*
|
|
74
|
-
* Defaults to process.env['
|
|
72
|
+
* Defaults to process.env['NOTDIAMOND_BASE_URL'].
|
|
75
73
|
*/
|
|
76
74
|
baseURL?: string | null | undefined;
|
|
77
75
|
|
|
@@ -125,7 +123,7 @@ export interface ClientOptions {
|
|
|
125
123
|
/**
|
|
126
124
|
* Set the log level.
|
|
127
125
|
*
|
|
128
|
-
* Defaults to process.env['
|
|
126
|
+
* Defaults to process.env['NOTDIAMOND_LOG'] or 'warn' if it isn't set.
|
|
129
127
|
*/
|
|
130
128
|
logLevel?: LogLevel | undefined;
|
|
131
129
|
|
|
@@ -138,15 +136,15 @@ export interface ClientOptions {
|
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
/**
|
|
141
|
-
* API Client for interfacing with the
|
|
139
|
+
* API Client for interfacing with the Notdiamond API.
|
|
142
140
|
*/
|
|
143
|
-
export class
|
|
141
|
+
export class Notdiamond {
|
|
144
142
|
apiKey: string;
|
|
145
143
|
|
|
146
144
|
baseURL: string;
|
|
147
145
|
maxRetries: number;
|
|
148
146
|
timeout: number;
|
|
149
|
-
logger: Logger
|
|
147
|
+
logger: Logger;
|
|
150
148
|
logLevel: LogLevel | undefined;
|
|
151
149
|
fetchOptions: MergedRequestInit | undefined;
|
|
152
150
|
|
|
@@ -156,10 +154,10 @@ export class NotDiamond {
|
|
|
156
154
|
private _options: ClientOptions;
|
|
157
155
|
|
|
158
156
|
/**
|
|
159
|
-
* API Client for interfacing with the
|
|
157
|
+
* API Client for interfacing with the Notdiamond API.
|
|
160
158
|
*
|
|
161
159
|
* @param {string | undefined} [opts.apiKey=process.env['NOT_DIAMOND_API_KEY'] ?? undefined]
|
|
162
|
-
* @param {string} [opts.baseURL=process.env['
|
|
160
|
+
* @param {string} [opts.baseURL=process.env['NOTDIAMOND_BASE_URL'] ?? https://api.notdiamond.ai] - Override the default base URL for the API.
|
|
163
161
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
164
162
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
165
163
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -168,13 +166,13 @@ export class NotDiamond {
|
|
|
168
166
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
169
167
|
*/
|
|
170
168
|
constructor({
|
|
171
|
-
baseURL = readEnv('
|
|
169
|
+
baseURL = readEnv('NOTDIAMOND_BASE_URL'),
|
|
172
170
|
apiKey = readEnv('NOT_DIAMOND_API_KEY'),
|
|
173
171
|
...opts
|
|
174
172
|
}: ClientOptions = {}) {
|
|
175
173
|
if (apiKey === undefined) {
|
|
176
|
-
throw new Errors.
|
|
177
|
-
"The NOT_DIAMOND_API_KEY environment variable is missing or empty; either provide it, or instantiate the
|
|
174
|
+
throw new Errors.NotdiamondError(
|
|
175
|
+
"The NOT_DIAMOND_API_KEY environment variable is missing or empty; either provide it, or instantiate the Notdiamond client with an apiKey option, like new Notdiamond({ apiKey: 'My API Key' }).",
|
|
178
176
|
);
|
|
179
177
|
}
|
|
180
178
|
|
|
@@ -185,14 +183,14 @@ export class NotDiamond {
|
|
|
185
183
|
};
|
|
186
184
|
|
|
187
185
|
this.baseURL = options.baseURL!;
|
|
188
|
-
this.timeout = options.timeout ??
|
|
186
|
+
this.timeout = options.timeout ?? Notdiamond.DEFAULT_TIMEOUT /* 1 minute */;
|
|
189
187
|
this.logger = options.logger ?? console;
|
|
190
188
|
const defaultLogLevel = 'warn';
|
|
191
189
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
192
190
|
this.logLevel = defaultLogLevel;
|
|
193
191
|
this.logLevel =
|
|
194
192
|
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
195
|
-
parseLogLevel(readEnv('
|
|
193
|
+
parseLogLevel(readEnv('NOTDIAMOND_LOG'), "process.env['NOTDIAMOND_LOG']", this) ??
|
|
196
194
|
defaultLogLevel;
|
|
197
195
|
this.fetchOptions = options.fetchOptions;
|
|
198
196
|
this.maxRetries = options.maxRetries ?? 2;
|
|
@@ -711,10 +709,10 @@ export class NotDiamond {
|
|
|
711
709
|
}
|
|
712
710
|
}
|
|
713
711
|
|
|
714
|
-
static
|
|
712
|
+
static Notdiamond = this;
|
|
715
713
|
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
716
714
|
|
|
717
|
-
static
|
|
715
|
+
static NotdiamondError = Errors.NotdiamondError;
|
|
718
716
|
static APIError = Errors.APIError;
|
|
719
717
|
static APIConnectionError = Errors.APIConnectionError;
|
|
720
718
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -731,57 +729,52 @@ export class NotDiamond {
|
|
|
731
729
|
static toFile = Uploads.toFile;
|
|
732
730
|
|
|
733
731
|
modelRouter: API.ModelRouter = new API.ModelRouter(this);
|
|
734
|
-
report: API.Report = new API.Report(this);
|
|
735
732
|
preferences: API.Preferences = new API.Preferences(this);
|
|
736
|
-
|
|
737
|
-
|
|
733
|
+
promptAdaptation: API.PromptAdaptation = new API.PromptAdaptation(this);
|
|
734
|
+
customRouter: API.CustomRouter = new API.CustomRouter(this);
|
|
738
735
|
models: API.Models = new API.Models(this);
|
|
739
736
|
}
|
|
740
737
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
NotDiamond.Models = Models;
|
|
738
|
+
Notdiamond.ModelRouter = ModelRouter;
|
|
739
|
+
Notdiamond.Preferences = Preferences;
|
|
740
|
+
Notdiamond.PromptAdaptation = PromptAdaptation;
|
|
741
|
+
Notdiamond.CustomRouter = CustomRouter;
|
|
742
|
+
Notdiamond.Models = Models;
|
|
747
743
|
|
|
748
|
-
export declare namespace
|
|
744
|
+
export declare namespace Notdiamond {
|
|
749
745
|
export type RequestOptions = Opts.RequestOptions;
|
|
750
746
|
|
|
751
747
|
export {
|
|
752
748
|
ModelRouter as ModelRouter,
|
|
753
|
-
type ModelRouterOpenHandsSelectResponse as ModelRouterOpenHandsSelectResponse,
|
|
754
749
|
type ModelRouterSelectModelResponse as ModelRouterSelectModelResponse,
|
|
755
|
-
type ModelRouterOpenHandsSelectParams as ModelRouterOpenHandsSelectParams,
|
|
756
750
|
type ModelRouterSelectModelParams as ModelRouterSelectModelParams,
|
|
757
751
|
};
|
|
758
752
|
|
|
759
|
-
export { Report as Report };
|
|
760
|
-
|
|
761
753
|
export {
|
|
762
754
|
Preferences as Preferences,
|
|
763
755
|
type PreferenceCreateResponse as PreferenceCreateResponse,
|
|
764
|
-
type PreferenceRetrieveResponse as PreferenceRetrieveResponse,
|
|
765
756
|
type PreferenceUpdateResponse as PreferenceUpdateResponse,
|
|
766
757
|
type PreferenceDeleteResponse as PreferenceDeleteResponse,
|
|
767
758
|
type PreferenceCreateParams as PreferenceCreateParams,
|
|
768
|
-
type PreferenceRetrieveParams as PreferenceRetrieveParams,
|
|
769
759
|
type PreferenceUpdateParams as PreferenceUpdateParams,
|
|
770
760
|
};
|
|
771
761
|
|
|
772
762
|
export {
|
|
773
|
-
|
|
763
|
+
PromptAdaptation as PromptAdaptation,
|
|
764
|
+
type GoldenRecord as GoldenRecord,
|
|
774
765
|
type JobStatus as JobStatus,
|
|
775
|
-
type
|
|
776
|
-
type
|
|
766
|
+
type RequestProvider as RequestProvider,
|
|
767
|
+
type PromptAdaptationAdaptResponse as PromptAdaptationAdaptResponse,
|
|
768
|
+
type PromptAdaptationGetAdaptResultsResponse as PromptAdaptationGetAdaptResultsResponse,
|
|
769
|
+
type PromptAdaptationGetAdaptStatusResponse as PromptAdaptationGetAdaptStatusResponse,
|
|
770
|
+
type PromptAdaptationGetCostResponse as PromptAdaptationGetCostResponse,
|
|
771
|
+
type PromptAdaptationAdaptParams as PromptAdaptationAdaptParams,
|
|
777
772
|
};
|
|
778
773
|
|
|
779
774
|
export {
|
|
780
|
-
|
|
781
|
-
type
|
|
782
|
-
type
|
|
783
|
-
type PznSubmitSurveyResponseParams as PznSubmitSurveyResponseParams,
|
|
784
|
-
type PznTrainCustomRouterParams as PznTrainCustomRouterParams,
|
|
775
|
+
CustomRouter as CustomRouter,
|
|
776
|
+
type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse,
|
|
777
|
+
type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams,
|
|
785
778
|
};
|
|
786
779
|
|
|
787
780
|
export {
|
package/src/core/api-promise.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type Notdiamond } from '../client';
|
|
4
4
|
|
|
5
5
|
import { type PromiseOrValue } from '../internal/types';
|
|
6
6
|
import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
@@ -11,13 +11,13 @@ import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
|
11
11
|
*/
|
|
12
12
|
export class APIPromise<T> extends Promise<T> {
|
|
13
13
|
private parsedPromise: Promise<T> | undefined;
|
|
14
|
-
#client:
|
|
14
|
+
#client: Notdiamond;
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
|
-
client:
|
|
17
|
+
client: Notdiamond,
|
|
18
18
|
private responsePromise: Promise<APIResponseProps>,
|
|
19
19
|
private parseResponse: (
|
|
20
|
-
client:
|
|
20
|
+
client: Notdiamond,
|
|
21
21
|
props: APIResponseProps,
|
|
22
22
|
) => PromiseOrValue<T> = defaultParseResponse,
|
|
23
23
|
) {
|
package/src/core/error.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError } from '../internal/errors';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class NotdiamondError extends Error {}
|
|
6
6
|
|
|
7
7
|
export class APIError<
|
|
8
8
|
TStatus extends number | undefined = number | undefined,
|
|
9
9
|
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
10
|
TError extends Object | undefined = Object | undefined,
|
|
11
|
-
> extends
|
|
11
|
+
> extends NotdiamondError {
|
|
12
12
|
/** HTTP status for the response that caused the error */
|
|
13
13
|
readonly status: TStatus;
|
|
14
14
|
/** HTTP headers for the response that caused the error */
|
package/src/core/resource.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Notdiamond } from '../client';
|
|
4
4
|
|
|
5
5
|
export abstract class APIResource {
|
|
6
|
-
protected _client:
|
|
6
|
+
protected _client: Notdiamond;
|
|
7
7
|
|
|
8
|
-
constructor(client:
|
|
8
|
+
constructor(client: Notdiamond) {
|
|
9
9
|
this._client = client;
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Notdiamond as default } from './client';
|
|
4
4
|
|
|
5
5
|
export { type Uploadable, toFile } from './core/uploads';
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
|
-
export {
|
|
7
|
+
export { Notdiamond, type ClientOptions } from './client';
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
NotdiamondError,
|
|
10
10
|
APIError,
|
|
11
11
|
APIConnectionError,
|
|
12
12
|
APIConnectionTimeoutError,
|
package/src/internal/parse.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Notdiamond } from '../client';
|
|
5
5
|
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
6
|
|
|
7
7
|
export type APIResponseProps = {
|
|
@@ -13,7 +13,7 @@ export type APIResponseProps = {
|
|
|
13
13
|
startTime: number;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export async function defaultParseResponse<T>(client:
|
|
16
|
+
export async function defaultParseResponse<T>(client: Notdiamond, props: APIResponseProps): Promise<T> {
|
|
17
17
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
18
|
const body = await (async () => {
|
|
19
19
|
// fetch refuses to read the body when the status code is 204.
|
package/src/internal/shims.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function getDefaultFetch(): Fetch {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
throw new Error(
|
|
19
|
-
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new
|
|
19
|
+
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Notdiamond({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
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
|
};
|
|
@@ -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 => {
|
|
@@ -3,55 +3,10 @@
|
|
|
3
3
|
import { APIResource } from '../core/resource';
|
|
4
4
|
import { APIPromise } from '../core/api-promise';
|
|
5
5
|
import { type Uploadable } from '../core/uploads';
|
|
6
|
-
import { buildHeaders } from '../internal/headers';
|
|
7
6
|
import { RequestOptions } from '../internal/request-options';
|
|
8
7
|
import { multipartFormRequestOptions } from '../internal/uploads';
|
|
9
8
|
|
|
10
|
-
export class
|
|
11
|
-
/**
|
|
12
|
-
* Submit a survey response for personalized routing setup.
|
|
13
|
-
*
|
|
14
|
-
* This admin endpoint processes survey responses to set up personalized routing
|
|
15
|
-
* configurations for users based on their use case, LLM preferences, and
|
|
16
|
-
* constraints.
|
|
17
|
-
*
|
|
18
|
-
* **Survey Data:**
|
|
19
|
-
*
|
|
20
|
-
* - User information and use case description
|
|
21
|
-
* - Preferred LLM providers and models
|
|
22
|
-
* - Constraint priorities (quality, cost, latency)
|
|
23
|
-
* - Optional prompts and evaluation datasets
|
|
24
|
-
*
|
|
25
|
-
* **File Uploads:**
|
|
26
|
-
*
|
|
27
|
-
* - `prompt_file`: Optional CSV file with prompts
|
|
28
|
-
* - `dataset_file`: Optional CSV file with evaluation dataset
|
|
29
|
-
*
|
|
30
|
-
* **Note:** This is an admin-only endpoint for internal use.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* const response = await client.pzn.submitSurveyResponse({
|
|
35
|
-
* constraint_priorities: 'constraint_priorities',
|
|
36
|
-
* email: 'email',
|
|
37
|
-
* llm_providers: 'llm_providers',
|
|
38
|
-
* use_case_desc: 'use_case_desc',
|
|
39
|
-
* user_id: 'user_id',
|
|
40
|
-
* 'x-token': 'x-token',
|
|
41
|
-
* });
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
submitSurveyResponse(params: PznSubmitSurveyResponseParams, options?: RequestOptions): APIPromise<unknown> {
|
|
45
|
-
const { 'x-token': xToken, ...body } = params;
|
|
46
|
-
return this._client.post(
|
|
47
|
-
'/v2/pzn/surveyResponse',
|
|
48
|
-
multipartFormRequestOptions(
|
|
49
|
-
{ body, ...options, headers: buildHeaders([{ 'x-token': xToken }, options?.headers]) },
|
|
50
|
-
this._client,
|
|
51
|
-
),
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
9
|
+
export class CustomRouter extends APIResource {
|
|
55
10
|
/**
|
|
56
11
|
* Train a custom router on your evaluation data to optimize routing for your
|
|
57
12
|
* specific use case.
|
|
@@ -111,20 +66,21 @@ export class Pzn extends APIResource {
|
|
|
111
66
|
*
|
|
112
67
|
* @example
|
|
113
68
|
* ```ts
|
|
114
|
-
* const response =
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
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
|
+
* });
|
|
122
78
|
* ```
|
|
123
79
|
*/
|
|
124
80
|
trainCustomRouter(
|
|
125
|
-
body:
|
|
81
|
+
body: CustomRouterTrainCustomRouterParams,
|
|
126
82
|
options?: RequestOptions,
|
|
127
|
-
): APIPromise<
|
|
83
|
+
): APIPromise<CustomRouterTrainCustomRouterResponse> {
|
|
128
84
|
return this._client.post(
|
|
129
85
|
'/v2/pzn/trainCustomRouter',
|
|
130
86
|
multipartFormRequestOptions({ body, ...options }, this._client),
|
|
@@ -132,8 +88,6 @@ export class Pzn extends APIResource {
|
|
|
132
88
|
}
|
|
133
89
|
}
|
|
134
90
|
|
|
135
|
-
export type PznSubmitSurveyResponseResponse = unknown;
|
|
136
|
-
|
|
137
91
|
/**
|
|
138
92
|
* Response model for POST /v2/pzn/trainCustomRouter endpoint.
|
|
139
93
|
*
|
|
@@ -155,7 +109,7 @@ export type PznSubmitSurveyResponseResponse = unknown;
|
|
|
155
109
|
* - No need to poll status - you can start using it immediately (will use default
|
|
156
110
|
* until ready)
|
|
157
111
|
*/
|
|
158
|
-
export interface
|
|
112
|
+
export interface CustomRouterTrainCustomRouterResponse {
|
|
159
113
|
/**
|
|
160
114
|
* Unique identifier for the custom router. Use this in model_select() calls to
|
|
161
115
|
* enable routing with your custom-trained router
|
|
@@ -163,64 +117,7 @@ export interface PznTrainCustomRouterResponse {
|
|
|
163
117
|
preference_id: string;
|
|
164
118
|
}
|
|
165
119
|
|
|
166
|
-
export interface
|
|
167
|
-
/**
|
|
168
|
-
* Body param: JSON string of constraint priorities object
|
|
169
|
-
*/
|
|
170
|
-
constraint_priorities: string;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Body param: User email address
|
|
174
|
-
*/
|
|
175
|
-
email: string;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Body param: JSON string of LLM providers array
|
|
179
|
-
*/
|
|
180
|
-
llm_providers: string;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Body param: Description of the user's use case
|
|
184
|
-
*/
|
|
185
|
-
use_case_desc: string;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Body param: User ID from Supabase
|
|
189
|
-
*/
|
|
190
|
-
user_id: string;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Header param:
|
|
194
|
-
*/
|
|
195
|
-
'x-token': string;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Body param: Optional additional preferences text
|
|
199
|
-
*/
|
|
200
|
-
additional_preferences?: string | null;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Body param: Optional CSV file with evaluation dataset
|
|
204
|
-
*/
|
|
205
|
-
dataset_file?: Uploadable | null;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Body param: Optional preference name
|
|
209
|
-
*/
|
|
210
|
-
name?: string | null;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Body param: Optional CSV file with prompts
|
|
214
|
-
*/
|
|
215
|
-
prompt_file?: Uploadable | null;
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Body param: Optional JSON string of prompts array
|
|
219
|
-
*/
|
|
220
|
-
prompts?: string | null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export interface PznTrainCustomRouterParams {
|
|
120
|
+
export interface CustomRouterTrainCustomRouterParams {
|
|
224
121
|
/**
|
|
225
122
|
* CSV file containing evaluation data with prompt column and score/response
|
|
226
123
|
* columns for each model
|
|
@@ -263,11 +160,9 @@ export interface PznTrainCustomRouterParams {
|
|
|
263
160
|
preference_id?: string | null;
|
|
264
161
|
}
|
|
265
162
|
|
|
266
|
-
export declare namespace
|
|
163
|
+
export declare namespace CustomRouter {
|
|
267
164
|
export {
|
|
268
|
-
type
|
|
269
|
-
type
|
|
270
|
-
type PznSubmitSurveyResponseParams as PznSubmitSurveyResponseParams,
|
|
271
|
-
type PznTrainCustomRouterParams as PznTrainCustomRouterParams,
|
|
165
|
+
type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse,
|
|
166
|
+
type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams,
|
|
272
167
|
};
|
|
273
168
|
}
|