notdiamond 2.0.0-rc10 → 2.0.0-rc13
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 +27 -0
- package/LICENSE +1 -1
- package/README.md +61 -171
- package/client.d.mts +11 -11
- package/client.d.mts.map +1 -1
- package/client.d.ts +11 -11
- package/client.d.ts.map +1 -1
- package/client.js +38 -38
- package/client.js.map +1 -1
- package/client.mjs +36 -36
- 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/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/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/prompt-adaptation.d.mts +5 -5
- package/resources/prompt-adaptation.d.mts.map +1 -1
- package/resources/prompt-adaptation.d.ts +5 -5
- package/resources/prompt-adaptation.d.ts.map +1 -1
- package/resources/prompt-adaptation.js +2 -2
- package/resources/prompt-adaptation.js.map +1 -1
- package/resources/prompt-adaptation.mjs +2 -2
- package/resources/prompt-adaptation.mjs.map +1 -1
- package/src/client.ts +24 -24
- 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/index.ts +2 -2
- package/src/resources/prompt-adaptation.ts +8 -8
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/client.ts
CHANGED
|
@@ -40,8 +40,8 @@ import {
|
|
|
40
40
|
GoldenRecord,
|
|
41
41
|
JobStatus,
|
|
42
42
|
PromptAdaptation,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
PromptAdaptationAdaptParams,
|
|
44
|
+
PromptAdaptationAdaptResponse,
|
|
45
45
|
PromptAdaptationGetAdaptResultsResponse,
|
|
46
46
|
PromptAdaptationGetAdaptStatusResponse,
|
|
47
47
|
PromptAdaptationGetCostsResponse,
|
|
@@ -70,7 +70,7 @@ export interface ClientOptions {
|
|
|
70
70
|
/**
|
|
71
71
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
72
72
|
*
|
|
73
|
-
* Defaults to process.env['
|
|
73
|
+
* Defaults to process.env['NOTDIAMOND_BASE_URL'].
|
|
74
74
|
*/
|
|
75
75
|
baseURL?: string | null | undefined;
|
|
76
76
|
|
|
@@ -124,7 +124,7 @@ export interface ClientOptions {
|
|
|
124
124
|
/**
|
|
125
125
|
* Set the log level.
|
|
126
126
|
*
|
|
127
|
-
* Defaults to process.env['
|
|
127
|
+
* Defaults to process.env['NOTDIAMOND_LOG'] or 'warn' if it isn't set.
|
|
128
128
|
*/
|
|
129
129
|
logLevel?: LogLevel | undefined;
|
|
130
130
|
|
|
@@ -137,9 +137,9 @@ export interface ClientOptions {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
* API Client for interfacing with the
|
|
140
|
+
* API Client for interfacing with the Notdiamond API.
|
|
141
141
|
*/
|
|
142
|
-
export class
|
|
142
|
+
export class Notdiamond {
|
|
143
143
|
apiKey: string;
|
|
144
144
|
|
|
145
145
|
baseURL: string;
|
|
@@ -155,10 +155,10 @@ export class NotDiamond {
|
|
|
155
155
|
private _options: ClientOptions;
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
|
-
* API Client for interfacing with the
|
|
158
|
+
* API Client for interfacing with the Notdiamond API.
|
|
159
159
|
*
|
|
160
160
|
* @param {string | undefined} [opts.apiKey=process.env['NOT_DIAMOND_API_KEY'] ?? undefined]
|
|
161
|
-
* @param {string} [opts.baseURL=process.env['
|
|
161
|
+
* @param {string} [opts.baseURL=process.env['NOTDIAMOND_BASE_URL'] ?? https://api.notdiamond.ai] - Override the default base URL for the API.
|
|
162
162
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
163
163
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
164
164
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -167,13 +167,13 @@ export class NotDiamond {
|
|
|
167
167
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
168
168
|
*/
|
|
169
169
|
constructor({
|
|
170
|
-
baseURL = readEnv('
|
|
170
|
+
baseURL = readEnv('NOTDIAMOND_BASE_URL'),
|
|
171
171
|
apiKey = readEnv('NOT_DIAMOND_API_KEY'),
|
|
172
172
|
...opts
|
|
173
173
|
}: ClientOptions = {}) {
|
|
174
174
|
if (apiKey === undefined) {
|
|
175
|
-
throw new Errors.
|
|
176
|
-
"The NOT_DIAMOND_API_KEY environment variable is missing or empty; either provide it, or instantiate the
|
|
175
|
+
throw new Errors.NotdiamondError(
|
|
176
|
+
"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' }).",
|
|
177
177
|
);
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -184,14 +184,14 @@ export class NotDiamond {
|
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
this.baseURL = options.baseURL!;
|
|
187
|
-
this.timeout = options.timeout ??
|
|
187
|
+
this.timeout = options.timeout ?? Notdiamond.DEFAULT_TIMEOUT /* 1 minute */;
|
|
188
188
|
this.logger = options.logger ?? console;
|
|
189
189
|
const defaultLogLevel = 'warn';
|
|
190
190
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
191
191
|
this.logLevel = defaultLogLevel;
|
|
192
192
|
this.logLevel =
|
|
193
193
|
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
194
|
-
parseLogLevel(readEnv('
|
|
194
|
+
parseLogLevel(readEnv('NOTDIAMOND_LOG'), "process.env['NOTDIAMOND_LOG']", this) ??
|
|
195
195
|
defaultLogLevel;
|
|
196
196
|
this.fetchOptions = options.fetchOptions;
|
|
197
197
|
this.maxRetries = options.maxRetries ?? 2;
|
|
@@ -710,10 +710,10 @@ export class NotDiamond {
|
|
|
710
710
|
}
|
|
711
711
|
}
|
|
712
712
|
|
|
713
|
-
static
|
|
713
|
+
static Notdiamond = this;
|
|
714
714
|
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
715
715
|
|
|
716
|
-
static
|
|
716
|
+
static NotdiamondError = Errors.NotdiamondError;
|
|
717
717
|
static APIError = Errors.APIError;
|
|
718
718
|
static APIConnectionError = Errors.APIConnectionError;
|
|
719
719
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -737,14 +737,14 @@ export class NotDiamond {
|
|
|
737
737
|
models: API.Models = new API.Models(this);
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
740
|
+
Notdiamond.ModelRouter = ModelRouter;
|
|
741
|
+
Notdiamond.Report = Report;
|
|
742
|
+
Notdiamond.Preferences = Preferences;
|
|
743
|
+
Notdiamond.PromptAdaptation = PromptAdaptation;
|
|
744
|
+
Notdiamond.CustomRouter = CustomRouter;
|
|
745
|
+
Notdiamond.Models = Models;
|
|
746
746
|
|
|
747
|
-
export declare namespace
|
|
747
|
+
export declare namespace Notdiamond {
|
|
748
748
|
export type RequestOptions = Opts.RequestOptions;
|
|
749
749
|
|
|
750
750
|
export {
|
|
@@ -769,11 +769,11 @@ export declare namespace NotDiamond {
|
|
|
769
769
|
type GoldenRecord as GoldenRecord,
|
|
770
770
|
type JobStatus as JobStatus,
|
|
771
771
|
type RequestProvider as RequestProvider,
|
|
772
|
-
type
|
|
772
|
+
type PromptAdaptationAdaptResponse as PromptAdaptationAdaptResponse,
|
|
773
773
|
type PromptAdaptationGetAdaptResultsResponse as PromptAdaptationGetAdaptResultsResponse,
|
|
774
774
|
type PromptAdaptationGetAdaptStatusResponse as PromptAdaptationGetAdaptStatusResponse,
|
|
775
775
|
type PromptAdaptationGetCostsResponse as PromptAdaptationGetCostsResponse,
|
|
776
|
-
type
|
|
776
|
+
type PromptAdaptationAdaptParams as PromptAdaptationAdaptParams,
|
|
777
777
|
};
|
|
778
778
|
|
|
779
779
|
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 => {
|
package/src/resources/index.ts
CHANGED
|
@@ -24,10 +24,10 @@ export {
|
|
|
24
24
|
type GoldenRecord,
|
|
25
25
|
type JobStatus,
|
|
26
26
|
type RequestProvider,
|
|
27
|
-
type
|
|
27
|
+
type PromptAdaptationAdaptResponse,
|
|
28
28
|
type PromptAdaptationGetAdaptResultsResponse,
|
|
29
29
|
type PromptAdaptationGetAdaptStatusResponse,
|
|
30
30
|
type PromptAdaptationGetCostsResponse,
|
|
31
|
-
type
|
|
31
|
+
type PromptAdaptationAdaptParams,
|
|
32
32
|
} from './prompt-adaptation';
|
|
33
33
|
export { Report } from './report/report';
|
|
@@ -74,7 +74,7 @@ export class PromptAdaptation extends APIResource {
|
|
|
74
74
|
*
|
|
75
75
|
* @example
|
|
76
76
|
* ```ts
|
|
77
|
-
* const
|
|
77
|
+
* const response = await client.promptAdaptation.adapt({
|
|
78
78
|
* fields: ['question'],
|
|
79
79
|
* system_prompt: 'You are a helpful assistant that answers questions accurately.',
|
|
80
80
|
* target_models: [
|
|
@@ -119,10 +119,10 @@ export class PromptAdaptation extends APIResource {
|
|
|
119
119
|
* });
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
|
-
|
|
123
|
-
body:
|
|
122
|
+
adapt(
|
|
123
|
+
body: PromptAdaptationAdaptParams,
|
|
124
124
|
options?: RequestOptions,
|
|
125
|
-
): APIPromise<
|
|
125
|
+
): APIPromise<PromptAdaptationAdaptResponse> {
|
|
126
126
|
return this._client.post('/v2/prompt/adapt', { body, ...options });
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -363,7 +363,7 @@ export interface RequestProvider {
|
|
|
363
363
|
* /v2/prompt/adaptResults/{adaptation_run_id}
|
|
364
364
|
* 4. Use the optimized prompts with your target models
|
|
365
365
|
*/
|
|
366
|
-
export interface
|
|
366
|
+
export interface PromptAdaptationAdaptResponse {
|
|
367
367
|
/**
|
|
368
368
|
* Unique identifier for this adaptation run. Use this to poll status and retrieve
|
|
369
369
|
* optimized prompts when complete
|
|
@@ -697,7 +697,7 @@ export namespace PromptAdaptationGetCostsResponse {
|
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
|
|
700
|
-
export interface
|
|
700
|
+
export interface PromptAdaptationAdaptParams {
|
|
701
701
|
/**
|
|
702
702
|
* List of field names that will be substituted into the template. Must match keys
|
|
703
703
|
* in golden records
|
|
@@ -761,10 +761,10 @@ export declare namespace PromptAdaptation {
|
|
|
761
761
|
type GoldenRecord as GoldenRecord,
|
|
762
762
|
type JobStatus as JobStatus,
|
|
763
763
|
type RequestProvider as RequestProvider,
|
|
764
|
-
type
|
|
764
|
+
type PromptAdaptationAdaptResponse as PromptAdaptationAdaptResponse,
|
|
765
765
|
type PromptAdaptationGetAdaptResultsResponse as PromptAdaptationGetAdaptResultsResponse,
|
|
766
766
|
type PromptAdaptationGetAdaptStatusResponse as PromptAdaptationGetAdaptStatusResponse,
|
|
767
767
|
type PromptAdaptationGetCostsResponse as PromptAdaptationGetCostsResponse,
|
|
768
|
-
type
|
|
768
|
+
type PromptAdaptationAdaptParams as PromptAdaptationAdaptParams,
|
|
769
769
|
};
|
|
770
770
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '2.0.0-
|
|
1
|
+
export const VERSION = '2.0.0-rc13'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-
|
|
1
|
+
export declare const VERSION = "2.0.0-rc13";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-
|
|
1
|
+
export declare const VERSION = "2.0.0-rc13";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '2.0.0-
|
|
1
|
+
export const VERSION = '2.0.0-rc13'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|