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/resources/report.js
CHANGED
|
@@ -1,86 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class Report extends resource_1.APIResource {
|
|
7
|
-
/**
|
|
8
|
-
* Evaluate Hallucination
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const response = await client.report.evaluateHallucination({
|
|
13
|
-
* context: 'context',
|
|
14
|
-
* prompt: 'prompt',
|
|
15
|
-
* provider: { model: 'gpt-4o', provider: 'openai' },
|
|
16
|
-
* response: 'response',
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
evaluateHallucination(body, options) {
|
|
21
|
-
return this._client.post('/v2/report/hallucination', { body, ...options });
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Report Latency
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const response = await client.report.latency({
|
|
29
|
-
* feedback: { accuracy: 'bar' },
|
|
30
|
-
* provider: { model: 'gpt-4o', provider: 'openai' },
|
|
31
|
-
* session_id: 'session_id',
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
latency(body, options) {
|
|
36
|
-
return this._client.post('/v2/report/metrics/latency', { body, ...options });
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Submit feedback on a routing decision to improve future recommendations.
|
|
40
|
-
*
|
|
41
|
-
* This endpoint allows you to provide feedback on whether the router selected the
|
|
42
|
-
* right model for your query. Your feedback is used to:
|
|
43
|
-
*
|
|
44
|
-
* 1. Personalize routing decisions for your preference_id
|
|
45
|
-
* 2. Improve the overall routing quality
|
|
46
|
-
* 3. Train and refine custom routers
|
|
47
|
-
*
|
|
48
|
-
* **Feedback Format:**
|
|
49
|
-
*
|
|
50
|
-
* - `accuracy: 1` - Thumbs up (the model performed well)
|
|
51
|
-
* - `accuracy: 0` - Thumbs down (the model did not perform well)
|
|
52
|
-
*
|
|
53
|
-
* **Requirements:**
|
|
54
|
-
*
|
|
55
|
-
* - You must have used a preference_id in the original model_select() call
|
|
56
|
-
* - The session_id must be valid and belong to your account
|
|
57
|
-
* - The provider must match one of the providers returned by model_select()
|
|
58
|
-
*
|
|
59
|
-
* **How Feedback Works:** When you submit thumbs down, the router will:
|
|
60
|
-
*
|
|
61
|
-
* - Decrease the ranking of the selected model for similar queries
|
|
62
|
-
* - Consider alternative models more favorably
|
|
63
|
-
*
|
|
64
|
-
* When you submit thumbs up, the router will:
|
|
65
|
-
*
|
|
66
|
-
* - Increase the ranking of the selected model for similar queries
|
|
67
|
-
* - Prioritize this model for similar future requests
|
|
68
|
-
*
|
|
69
|
-
* **Note:** Feedback requires a valid preference_id. Create one via POST
|
|
70
|
-
* /v2/preferences/userPreferenceCreate
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```ts
|
|
74
|
-
* const response = await client.report.submitFeedback({
|
|
75
|
-
* feedback: { accuracy: 1 },
|
|
76
|
-
* provider: { provider: 'openai', model: 'gpt-4o' },
|
|
77
|
-
* session_id: '550e8400-e29b-41d4-a716-446655440000',
|
|
78
|
-
* });
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
submitFeedback(body, options) {
|
|
82
|
-
return this._client.post('/v2/report/metrics/feedback', { body, ...options });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.Report = Report;
|
|
4
|
+
const tslib_1 = require("../internal/tslib.js");
|
|
5
|
+
tslib_1.__exportStar(require("./report/index.js"), exports);
|
|
86
6
|
//# sourceMappingURL=report.js.map
|
package/resources/report.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","sourceRoot":"","sources":["../src/resources/report.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,
|
|
1
|
+
{"version":3,"file":"report.js","sourceRoot":"","sources":["../src/resources/report.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,4DAA+B"}
|
package/resources/report.mjs
CHANGED
|
@@ -1,82 +1,3 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
-
|
|
3
|
-
export class Report extends APIResource {
|
|
4
|
-
/**
|
|
5
|
-
* Evaluate Hallucination
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const response = await client.report.evaluateHallucination({
|
|
10
|
-
* context: 'context',
|
|
11
|
-
* prompt: 'prompt',
|
|
12
|
-
* provider: { model: 'gpt-4o', provider: 'openai' },
|
|
13
|
-
* response: 'response',
|
|
14
|
-
* });
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
evaluateHallucination(body, options) {
|
|
18
|
-
return this._client.post('/v2/report/hallucination', { body, ...options });
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Report Latency
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const response = await client.report.latency({
|
|
26
|
-
* feedback: { accuracy: 'bar' },
|
|
27
|
-
* provider: { model: 'gpt-4o', provider: 'openai' },
|
|
28
|
-
* session_id: 'session_id',
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
latency(body, options) {
|
|
33
|
-
return this._client.post('/v2/report/metrics/latency', { body, ...options });
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Submit feedback on a routing decision to improve future recommendations.
|
|
37
|
-
*
|
|
38
|
-
* This endpoint allows you to provide feedback on whether the router selected the
|
|
39
|
-
* right model for your query. Your feedback is used to:
|
|
40
|
-
*
|
|
41
|
-
* 1. Personalize routing decisions for your preference_id
|
|
42
|
-
* 2. Improve the overall routing quality
|
|
43
|
-
* 3. Train and refine custom routers
|
|
44
|
-
*
|
|
45
|
-
* **Feedback Format:**
|
|
46
|
-
*
|
|
47
|
-
* - `accuracy: 1` - Thumbs up (the model performed well)
|
|
48
|
-
* - `accuracy: 0` - Thumbs down (the model did not perform well)
|
|
49
|
-
*
|
|
50
|
-
* **Requirements:**
|
|
51
|
-
*
|
|
52
|
-
* - You must have used a preference_id in the original model_select() call
|
|
53
|
-
* - The session_id must be valid and belong to your account
|
|
54
|
-
* - The provider must match one of the providers returned by model_select()
|
|
55
|
-
*
|
|
56
|
-
* **How Feedback Works:** When you submit thumbs down, the router will:
|
|
57
|
-
*
|
|
58
|
-
* - Decrease the ranking of the selected model for similar queries
|
|
59
|
-
* - Consider alternative models more favorably
|
|
60
|
-
*
|
|
61
|
-
* When you submit thumbs up, the router will:
|
|
62
|
-
*
|
|
63
|
-
* - Increase the ranking of the selected model for similar queries
|
|
64
|
-
* - Prioritize this model for similar future requests
|
|
65
|
-
*
|
|
66
|
-
* **Note:** Feedback requires a valid preference_id. Create one via POST
|
|
67
|
-
* /v2/preferences/userPreferenceCreate
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* const response = await client.report.submitFeedback({
|
|
72
|
-
* feedback: { accuracy: 1 },
|
|
73
|
-
* provider: { provider: 'openai', model: 'gpt-4o' },
|
|
74
|
-
* session_id: '550e8400-e29b-41d4-a716-446655440000',
|
|
75
|
-
* });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
submitFeedback(body, options) {
|
|
79
|
-
return this._client.post('/v2/report/metrics/feedback', { body, ...options });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
2
|
+
export * from "./report/index.mjs";
|
|
82
3
|
//# sourceMappingURL=report.mjs.map
|
package/resources/report.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.mjs","sourceRoot":"","sources":["../src/resources/report.ts"],"names":[],"mappings":"AAAA,sFAAsF
|
|
1
|
+
{"version":3,"file":"report.mjs","sourceRoot":"","sources":["../src/resources/report.ts"],"names":[],"mappings":"AAAA,sFAAsF"}
|
package/src/client.ts
CHANGED
|
@@ -17,48 +17,37 @@ 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 { Admin } from './resources/admin';
|
|
21
|
-
import { ModelListParams, ModelListResponse, Models } from './resources/models';
|
|
22
20
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
CustomRouter,
|
|
22
|
+
CustomRouterTrainCustomRouterParams,
|
|
23
|
+
CustomRouterTrainCustomRouterResponse,
|
|
24
|
+
} from './resources/custom-router';
|
|
25
|
+
import {
|
|
26
|
+
ModelRouter,
|
|
27
|
+
ModelRouterSelectModelParams,
|
|
28
|
+
ModelRouterSelectModelResponse,
|
|
29
|
+
} from './resources/model-router';
|
|
30
|
+
import { Model, ModelListParams, ModelListResponse, Models } from './resources/models';
|
|
31
|
+
import {
|
|
32
|
+
PreferenceCreateParams,
|
|
33
|
+
PreferenceCreateResponse,
|
|
34
|
+
PreferenceDeleteResponse,
|
|
35
|
+
PreferenceUpdateParams,
|
|
36
|
+
PreferenceUpdateResponse,
|
|
30
37
|
Preferences,
|
|
31
38
|
} from './resources/preferences';
|
|
32
39
|
import {
|
|
33
|
-
|
|
40
|
+
GoldenRecord,
|
|
34
41
|
JobStatus,
|
|
35
42
|
PromptAdaptation,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
PromptAdaptationGetAdaptRunsParams,
|
|
40
|
-
PromptAdaptationGetAdaptRunsResponse,
|
|
43
|
+
PromptAdaptationCreateParams,
|
|
44
|
+
PromptAdaptationCreateResponse,
|
|
45
|
+
PromptAdaptationGetAdaptResultsResponse,
|
|
41
46
|
PromptAdaptationGetAdaptStatusResponse,
|
|
42
|
-
|
|
47
|
+
PromptAdaptationGetCostsResponse,
|
|
48
|
+
RequestProvider,
|
|
43
49
|
} from './resources/prompt-adaptation';
|
|
44
|
-
import {
|
|
45
|
-
Report,
|
|
46
|
-
ReportEvaluateHallucinationParams,
|
|
47
|
-
ReportEvaluateHallucinationResponse,
|
|
48
|
-
ReportLatencyParams,
|
|
49
|
-
ReportLatencyResponse,
|
|
50
|
-
ReportSubmitFeedbackParams,
|
|
51
|
-
ReportSubmitFeedbackResponse,
|
|
52
|
-
} from './resources/report';
|
|
53
|
-
import {
|
|
54
|
-
Routing,
|
|
55
|
-
RoutingCreateSurveyResponseParams,
|
|
56
|
-
RoutingCreateSurveyResponseResponse,
|
|
57
|
-
RoutingSelectModelParams,
|
|
58
|
-
RoutingSelectModelResponse,
|
|
59
|
-
RoutingTrainCustomRouterParams,
|
|
60
|
-
RoutingTrainCustomRouterResponse,
|
|
61
|
-
} from './resources/routing';
|
|
50
|
+
import { Report } from './resources/report/report';
|
|
62
51
|
import { type Fetch } from './internal/builtin-types';
|
|
63
52
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
64
53
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
@@ -72,31 +61,16 @@ import {
|
|
|
72
61
|
} from './internal/utils/log';
|
|
73
62
|
import { isEmptyObj } from './internal/utils/values';
|
|
74
63
|
|
|
75
|
-
const environments = {
|
|
76
|
-
production: 'https://api.notdiamond.ai',
|
|
77
|
-
staging: 'https://staging-api.notdiamond.ai',
|
|
78
|
-
};
|
|
79
|
-
type Environment = keyof typeof environments;
|
|
80
|
-
|
|
81
64
|
export interface ClientOptions {
|
|
82
65
|
/**
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
apiKey?: string | null | undefined;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Specifies the environment to use for the API.
|
|
89
|
-
*
|
|
90
|
-
* Each environment maps to a different base URL:
|
|
91
|
-
* - `production` corresponds to `https://api.notdiamond.ai`
|
|
92
|
-
* - `staging` corresponds to `https://staging-api.notdiamond.ai`
|
|
66
|
+
* API key authentication using Bearer token
|
|
93
67
|
*/
|
|
94
|
-
|
|
68
|
+
apiKey?: string | undefined;
|
|
95
69
|
|
|
96
70
|
/**
|
|
97
71
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
98
72
|
*
|
|
99
|
-
* Defaults to process.env['
|
|
73
|
+
* Defaults to process.env['NOTDIAMOND_BASE_URL'].
|
|
100
74
|
*/
|
|
101
75
|
baseURL?: string | null | undefined;
|
|
102
76
|
|
|
@@ -150,7 +124,7 @@ export interface ClientOptions {
|
|
|
150
124
|
/**
|
|
151
125
|
* Set the log level.
|
|
152
126
|
*
|
|
153
|
-
* Defaults to process.env['
|
|
127
|
+
* Defaults to process.env['NOTDIAMOND_LOG'] or 'warn' if it isn't set.
|
|
154
128
|
*/
|
|
155
129
|
logLevel?: LogLevel | undefined;
|
|
156
130
|
|
|
@@ -163,10 +137,10 @@ export interface ClientOptions {
|
|
|
163
137
|
}
|
|
164
138
|
|
|
165
139
|
/**
|
|
166
|
-
* API Client for interfacing with the
|
|
140
|
+
* API Client for interfacing with the Notdiamond API.
|
|
167
141
|
*/
|
|
168
|
-
export class
|
|
169
|
-
apiKey: string
|
|
142
|
+
export class Notdiamond {
|
|
143
|
+
apiKey: string;
|
|
170
144
|
|
|
171
145
|
baseURL: string;
|
|
172
146
|
maxRetries: number;
|
|
@@ -181,11 +155,10 @@ export class NotDiamond {
|
|
|
181
155
|
private _options: ClientOptions;
|
|
182
156
|
|
|
183
157
|
/**
|
|
184
|
-
* API Client for interfacing with the
|
|
158
|
+
* API Client for interfacing with the Notdiamond API.
|
|
185
159
|
*
|
|
186
|
-
* @param {string |
|
|
187
|
-
* @param {
|
|
188
|
-
* @param {string} [opts.baseURL=process.env['NOT_DIAMOND_BASE_URL'] ?? https://api.notdiamond.ai] - Override the default base URL for the API.
|
|
160
|
+
* @param {string | undefined} [opts.apiKey=process.env['NOT_DIAMOND_API_KEY'] ?? undefined]
|
|
161
|
+
* @param {string} [opts.baseURL=process.env['NOTDIAMOND_BASE_URL'] ?? https://api.notdiamond.ai] - Override the default base URL for the API.
|
|
189
162
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
190
163
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
191
164
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -194,32 +167,31 @@ export class NotDiamond {
|
|
|
194
167
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
195
168
|
*/
|
|
196
169
|
constructor({
|
|
197
|
-
baseURL = readEnv('
|
|
198
|
-
apiKey = readEnv('NOT_DIAMOND_API_KEY')
|
|
170
|
+
baseURL = readEnv('NOTDIAMOND_BASE_URL'),
|
|
171
|
+
apiKey = readEnv('NOT_DIAMOND_API_KEY'),
|
|
199
172
|
...opts
|
|
200
173
|
}: ClientOptions = {}) {
|
|
174
|
+
if (apiKey === undefined) {
|
|
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
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
201
180
|
const options: ClientOptions = {
|
|
202
181
|
apiKey,
|
|
203
182
|
...opts,
|
|
204
|
-
baseURL
|
|
205
|
-
environment: opts.environment ?? 'production',
|
|
183
|
+
baseURL: baseURL || `https://api.notdiamond.ai`,
|
|
206
184
|
};
|
|
207
185
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
'Ambiguous URL; The `baseURL` option (or NOT_DIAMOND_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
this.baseURL = options.baseURL || environments[options.environment || 'production'];
|
|
215
|
-
this.timeout = options.timeout ?? NotDiamond.DEFAULT_TIMEOUT /* 1 minute */;
|
|
186
|
+
this.baseURL = options.baseURL!;
|
|
187
|
+
this.timeout = options.timeout ?? Notdiamond.DEFAULT_TIMEOUT /* 1 minute */;
|
|
216
188
|
this.logger = options.logger ?? console;
|
|
217
189
|
const defaultLogLevel = 'warn';
|
|
218
190
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
219
191
|
this.logLevel = defaultLogLevel;
|
|
220
192
|
this.logLevel =
|
|
221
193
|
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
222
|
-
parseLogLevel(readEnv('
|
|
194
|
+
parseLogLevel(readEnv('NOTDIAMOND_LOG'), "process.env['NOTDIAMOND_LOG']", this) ??
|
|
223
195
|
defaultLogLevel;
|
|
224
196
|
this.fetchOptions = options.fetchOptions;
|
|
225
197
|
this.maxRetries = options.maxRetries ?? 2;
|
|
@@ -237,8 +209,7 @@ export class NotDiamond {
|
|
|
237
209
|
withOptions(options: Partial<ClientOptions>): this {
|
|
238
210
|
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
239
211
|
...this._options,
|
|
240
|
-
|
|
241
|
-
baseURL: options.environment ? undefined : this.baseURL,
|
|
212
|
+
baseURL: this.baseURL,
|
|
242
213
|
maxRetries: this.maxRetries,
|
|
243
214
|
timeout: this.timeout,
|
|
244
215
|
logger: this.logger,
|
|
@@ -255,7 +226,7 @@ export class NotDiamond {
|
|
|
255
226
|
* Check whether the base URL is set to its default.
|
|
256
227
|
*/
|
|
257
228
|
#baseURLOverridden(): boolean {
|
|
258
|
-
return this.baseURL !==
|
|
229
|
+
return this.baseURL !== 'https://api.notdiamond.ai';
|
|
259
230
|
}
|
|
260
231
|
|
|
261
232
|
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
@@ -263,22 +234,10 @@ export class NotDiamond {
|
|
|
263
234
|
}
|
|
264
235
|
|
|
265
236
|
protected validateHeaders({ values, nulls }: NullableHeaders) {
|
|
266
|
-
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (nulls.has('authorization')) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
throw new Error(
|
|
274
|
-
'Could not resolve authentication method. Expected the apiKey to be set. Or for the "Authorization" headers to be explicitly omitted',
|
|
275
|
-
);
|
|
237
|
+
return;
|
|
276
238
|
}
|
|
277
239
|
|
|
278
240
|
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
279
|
-
if (this.apiKey == null) {
|
|
280
|
-
return undefined;
|
|
281
|
-
}
|
|
282
241
|
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
|
|
283
242
|
}
|
|
284
243
|
|
|
@@ -751,10 +710,10 @@ export class NotDiamond {
|
|
|
751
710
|
}
|
|
752
711
|
}
|
|
753
712
|
|
|
754
|
-
static
|
|
713
|
+
static Notdiamond = this;
|
|
755
714
|
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
756
715
|
|
|
757
|
-
static
|
|
716
|
+
static NotdiamondError = Errors.NotdiamondError;
|
|
758
717
|
static APIError = Errors.APIError;
|
|
759
718
|
static APIConnectionError = Errors.APIConnectionError;
|
|
760
719
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -770,73 +729,63 @@ export class NotDiamond {
|
|
|
770
729
|
|
|
771
730
|
static toFile = Uploads.toFile;
|
|
772
731
|
|
|
773
|
-
|
|
732
|
+
modelRouter: API.ModelRouter = new API.ModelRouter(this);
|
|
733
|
+
report: API.Report = new API.Report(this);
|
|
774
734
|
preferences: API.Preferences = new API.Preferences(this);
|
|
775
735
|
promptAdaptation: API.PromptAdaptation = new API.PromptAdaptation(this);
|
|
776
|
-
|
|
736
|
+
customRouter: API.CustomRouter = new API.CustomRouter(this);
|
|
777
737
|
models: API.Models = new API.Models(this);
|
|
778
|
-
admin: API.Admin = new API.Admin(this);
|
|
779
738
|
}
|
|
780
739
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
740
|
+
Notdiamond.ModelRouter = ModelRouter;
|
|
741
|
+
Notdiamond.Report = Report;
|
|
742
|
+
Notdiamond.Preferences = Preferences;
|
|
743
|
+
Notdiamond.PromptAdaptation = PromptAdaptation;
|
|
744
|
+
Notdiamond.CustomRouter = CustomRouter;
|
|
745
|
+
Notdiamond.Models = Models;
|
|
787
746
|
|
|
788
|
-
export declare namespace
|
|
747
|
+
export declare namespace Notdiamond {
|
|
789
748
|
export type RequestOptions = Opts.RequestOptions;
|
|
790
749
|
|
|
791
750
|
export {
|
|
792
|
-
|
|
793
|
-
type
|
|
794
|
-
type
|
|
795
|
-
type RoutingTrainCustomRouterResponse as RoutingTrainCustomRouterResponse,
|
|
796
|
-
type RoutingCreateSurveyResponseParams as RoutingCreateSurveyResponseParams,
|
|
797
|
-
type RoutingSelectModelParams as RoutingSelectModelParams,
|
|
798
|
-
type RoutingTrainCustomRouterParams as RoutingTrainCustomRouterParams,
|
|
751
|
+
ModelRouter as ModelRouter,
|
|
752
|
+
type ModelRouterSelectModelResponse as ModelRouterSelectModelResponse,
|
|
753
|
+
type ModelRouterSelectModelParams as ModelRouterSelectModelParams,
|
|
799
754
|
};
|
|
800
755
|
|
|
756
|
+
export { Report as Report };
|
|
757
|
+
|
|
801
758
|
export {
|
|
802
759
|
Preferences as Preferences,
|
|
803
|
-
type
|
|
804
|
-
type
|
|
805
|
-
type
|
|
806
|
-
type
|
|
807
|
-
type
|
|
808
|
-
type PreferenceCreateUserPreferenceParams as PreferenceCreateUserPreferenceParams,
|
|
809
|
-
type PreferenceUpdateUserPreferenceParams as PreferenceUpdateUserPreferenceParams,
|
|
760
|
+
type PreferenceCreateResponse as PreferenceCreateResponse,
|
|
761
|
+
type PreferenceUpdateResponse as PreferenceUpdateResponse,
|
|
762
|
+
type PreferenceDeleteResponse as PreferenceDeleteResponse,
|
|
763
|
+
type PreferenceCreateParams as PreferenceCreateParams,
|
|
764
|
+
type PreferenceUpdateParams as PreferenceUpdateParams,
|
|
810
765
|
};
|
|
811
766
|
|
|
812
767
|
export {
|
|
813
768
|
PromptAdaptation as PromptAdaptation,
|
|
814
|
-
type
|
|
769
|
+
type GoldenRecord as GoldenRecord,
|
|
815
770
|
type JobStatus as JobStatus,
|
|
816
|
-
type
|
|
817
|
-
type
|
|
771
|
+
type RequestProvider as RequestProvider,
|
|
772
|
+
type PromptAdaptationCreateResponse as PromptAdaptationCreateResponse,
|
|
773
|
+
type PromptAdaptationGetAdaptResultsResponse as PromptAdaptationGetAdaptResultsResponse,
|
|
818
774
|
type PromptAdaptationGetAdaptStatusResponse as PromptAdaptationGetAdaptStatusResponse,
|
|
819
|
-
type
|
|
820
|
-
type
|
|
821
|
-
type PromptAdaptationGetAdaptRunResultsParams as PromptAdaptationGetAdaptRunResultsParams,
|
|
822
|
-
type PromptAdaptationGetAdaptRunsParams as PromptAdaptationGetAdaptRunsParams,
|
|
775
|
+
type PromptAdaptationGetCostsResponse as PromptAdaptationGetCostsResponse,
|
|
776
|
+
type PromptAdaptationCreateParams as PromptAdaptationCreateParams,
|
|
823
777
|
};
|
|
824
778
|
|
|
825
779
|
export {
|
|
826
|
-
|
|
827
|
-
type
|
|
828
|
-
type
|
|
829
|
-
type ReportSubmitFeedbackResponse as ReportSubmitFeedbackResponse,
|
|
830
|
-
type ReportEvaluateHallucinationParams as ReportEvaluateHallucinationParams,
|
|
831
|
-
type ReportLatencyParams as ReportLatencyParams,
|
|
832
|
-
type ReportSubmitFeedbackParams as ReportSubmitFeedbackParams,
|
|
780
|
+
CustomRouter as CustomRouter,
|
|
781
|
+
type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse,
|
|
782
|
+
type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams,
|
|
833
783
|
};
|
|
834
784
|
|
|
835
785
|
export {
|
|
836
786
|
Models as Models,
|
|
787
|
+
type Model as Model,
|
|
837
788
|
type ModelListResponse as ModelListResponse,
|
|
838
789
|
type ModelListParams as ModelListParams,
|
|
839
790
|
};
|
|
840
|
-
|
|
841
|
-
export { Admin as Admin };
|
|
842
791
|
}
|
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
|
|