notdiamond 1.1.4 → 2.0.0-rc10
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 +143 -0
- package/LICENSE +201 -0
- package/README.md +642 -96
- package/api-promise.d.mts +2 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +2 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +2 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +192 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +192 -0
- package/client.d.ts.map +1 -0
- package/client.js +463 -0
- package/client.js.map +1 -0
- package/client.mjs +459 -0
- package/client.mjs.map +1 -0
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +74 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +70 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +46 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +46 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +113 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +97 -0
- package/core/error.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +2 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +6 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +30 -0
- package/index.js.map +1 -0
- package/index.mjs +7 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +20 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +20 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +12 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +12 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +35 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +32 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/qs/formats.d.mts +7 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.mts +15 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/request-options.d.mts +75 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +75 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +20 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +20 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +69 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +69 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +141 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +131 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +24 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +20 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +85 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +79 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +18 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +18 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +112 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +94 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +11 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +129 -123
- package/resource.d.mts +2 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +2 -0
- package/resource.mjs.map +1 -0
- 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 +7 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +7 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +17 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +8 -0
- package/resources/index.mjs.map +1 -0
- 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 +110 -0
- package/resources/models.d.mts.map +1 -0
- package/resources/models.d.ts +110 -0
- package/resources/models.d.ts.map +1 -0
- package/resources/models.js +49 -0
- package/resources/models.js.map +1 -0
- package/resources/models.mjs +45 -0
- package/resources/models.mjs.map +1 -0
- package/resources/preferences.d.mts +97 -0
- package/resources/preferences.d.mts.map +1 -0
- package/resources/preferences.d.ts +97 -0
- package/resources/preferences.d.ts.map +1 -0
- package/resources/preferences.js +70 -0
- package/resources/preferences.js.map +1 -0
- package/resources/preferences.mjs +66 -0
- package/resources/preferences.mjs.map +1 -0
- package/resources/prompt-adaptation.d.mts +679 -0
- package/resources/prompt-adaptation.d.mts.map +1 -0
- package/resources/prompt-adaptation.d.ts +679 -0
- package/resources/prompt-adaptation.d.ts.map +1 -0
- package/resources/prompt-adaptation.js +266 -0
- package/resources/prompt-adaptation.js.map +1 -0
- package/resources/prompt-adaptation.mjs +262 -0
- package/resources/prompt-adaptation.mjs.map +1 -0
- 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 +2 -0
- package/resources/report.d.mts.map +1 -0
- package/resources/report.d.ts +2 -0
- package/resources/report.d.ts.map +1 -0
- package/resources/report.js +6 -0
- package/resources/report.js.map +1 -0
- package/resources/report.mjs +3 -0
- package/resources/report.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +791 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +92 -0
- package/src/core/error.ts +130 -0
- package/src/core/resource.ts +11 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/index.ts +22 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +97 -0
- package/src/internal/parse.ts +50 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/request-options.ts +91 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +95 -0
- package/src/internal/uploads.ts +187 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +20 -0
- package/src/internal/utils/log.ts +126 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +105 -0
- package/src/internal/utils.ts +8 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +2 -0
- package/src/resources/custom-router.ts +168 -0
- package/src/resources/index.ts +33 -0
- package/src/resources/model-router.ts +224 -0
- package/src/resources/models.ts +133 -0
- package/src/resources/preferences.ts +121 -0
- package/src/resources/prompt-adaptation.ts +770 -0
- 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 +3 -0
- package/src/resources.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -0
- package/src/version.ts +1 -0
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +2 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +2 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
- package/LICENCE +0 -21
- package/dist/index.cjs +0 -601
- package/dist/index.d.cts +0 -228
- package/dist/index.d.mts +0 -228
- package/dist/index.d.ts +0 -228
- package/dist/index.mjs +0 -580
package/README.md
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Not Diamond TypeScript API Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[>)](https://npmjs.org/package/notdiamond) 
|
|
4
|
+
|
|
5
|
+
This library provides convenient access to the Not Diamond REST API from server-side TypeScript or JavaScript.
|
|
6
|
+
|
|
7
|
+
The library includes type definitions for all request params and response fields.
|
|
8
|
+
|
|
9
|
+
It is generated with [Stainless](https://www.stainless.com/).
|
|
10
|
+
|
|
11
|
+
## What is Prompt Adaptation?
|
|
12
|
+
|
|
13
|
+
Not Diamond specializes in **Prompt Adaptation** - automatically optimizing your prompts to work optimally across different LLMs. Each language model has unique characteristics, instruction-following patterns, and preferred prompt formats. A prompt that works perfectly for GPT-4 might perform poorly on Claude or Gemini.
|
|
14
|
+
|
|
15
|
+
**The Problem**: Manually rewriting prompts for each model is time-consuming and requires deep expertise in each model's quirks.
|
|
16
|
+
|
|
17
|
+
**The Solution**: Not Diamond automatically adapts your prompts through:
|
|
18
|
+
|
|
19
|
+
- Systematic optimization using your evaluation dataset
|
|
20
|
+
- Automated testing across target models
|
|
21
|
+
- Performance metrics to validate improvements
|
|
22
|
+
- Both system prompt and user message template optimization
|
|
23
|
+
|
|
24
|
+
## Documentation
|
|
25
|
+
|
|
26
|
+
The REST API documentation can be found on [docs.notdiamond.ai](https://docs.notdiamond.ai). The full API of this library can be found in [api.md](api.md).
|
|
4
27
|
|
|
5
28
|
## Installation
|
|
6
29
|
|
|
@@ -8,135 +31,658 @@ This library provides convenient access to the NotDiamond model routing API from
|
|
|
8
31
|
npm install notdiamond
|
|
9
32
|
```
|
|
10
33
|
|
|
11
|
-
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Prompt Adaptation
|
|
37
|
+
|
|
38
|
+
Automatically optimize your prompts to work better across different language models. Each model has unique characteristics and preferences - what works well for GPT-4 might not work as well for Claude or Gemini. Prompt Adaptation helps you get optimal performance from each model.
|
|
39
|
+
|
|
40
|
+
#### Quick Start
|
|
41
|
+
|
|
42
|
+
<!-- prettier-ignore -->
|
|
43
|
+
```ts
|
|
44
|
+
import NotDiamond from 'notdiamond';
|
|
45
|
+
|
|
46
|
+
const client = new NotDiamond({
|
|
47
|
+
apiKey: process.env['NOT_DIAMOND_API_KEY'], // This is the default and can be omitted
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Step 1: Start a prompt adaptation job
|
|
51
|
+
const adaptation = await client.prompt.adapt.create({
|
|
52
|
+
fields: ['question'],
|
|
53
|
+
system_prompt: 'You are a helpful assistant that answers questions accurately.',
|
|
54
|
+
target_models: [
|
|
55
|
+
{
|
|
56
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
57
|
+
provider: 'anthropic',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
model: 'gemini-2.5-flash',
|
|
61
|
+
provider: 'google',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
template: 'Question: {question}\nAnswer:',
|
|
65
|
+
train_goldens: [
|
|
66
|
+
{ fields: { question: 'What is 2+2?' }, answer: '4' },
|
|
67
|
+
{ fields: { question: 'What is the capital of France?' }, answer: 'Paris' },
|
|
68
|
+
{ fields: { question: 'Who wrote Romeo and Juliet?' }, answer: 'William Shakespeare' },
|
|
69
|
+
// Add at least 25 training examples for best results
|
|
70
|
+
// More examples = better adaptation quality
|
|
71
|
+
],
|
|
72
|
+
test_goldens: [
|
|
73
|
+
{ fields: { question: 'What is 3*3?' }, answer: '9' },
|
|
74
|
+
{ fields: { question: 'What is the largest ocean?' }, answer: 'Pacific Ocean' },
|
|
75
|
+
// Add test examples to validate performance
|
|
76
|
+
],
|
|
77
|
+
evaluation_metric: 'LLMaaJ:Sem_Sim_1', // Or use custom evaluation
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
console.log(`Adaptation started: ${adaptation.adaptation_run_id}`);
|
|
81
|
+
|
|
82
|
+
// Step 2: Poll for completion (typically takes 10-30 minutes)
|
|
83
|
+
let status;
|
|
84
|
+
while (true) {
|
|
85
|
+
status = await client.prompt.getAdaptStatus(adaptation.adaptation_run_id);
|
|
86
|
+
console.log(`Status: ${status.status}`);
|
|
87
|
+
|
|
88
|
+
if (status.status === 'queued') {
|
|
89
|
+
console.log(`Queue position: ${status.queue_position}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (status.status === 'completed' || status.status === 'failed') {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await new Promise(resolve => setTimeout(resolve, 30000)); // Poll every 30 seconds
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Step 3: Get the optimized prompts
|
|
100
|
+
if (status.status === 'completed') {
|
|
101
|
+
const results = await client.prompt.getAdaptResults(adaptation.adaptation_run_id);
|
|
102
|
+
|
|
103
|
+
console.log(`\nOrigin model baseline: ${results.origin_model.score.toFixed(2)}`);
|
|
104
|
+
|
|
105
|
+
for (const target of results.target_models) {
|
|
106
|
+
console.log('\n' + '='.repeat(50));
|
|
107
|
+
console.log(`Model: ${target.model.model} (${target.model.provider})`);
|
|
108
|
+
console.log(`Optimized System Prompt:\n${target.system_prompt}`);
|
|
109
|
+
console.log(`Optimized Template:\n${target.user_message_template}`);
|
|
110
|
+
console.log(`Pre-optimization score: ${target.pre_optimization_score.toFixed(2)}`);
|
|
111
|
+
console.log(`Post-optimization score: ${target.post_optimization_score.toFixed(2)}`);
|
|
112
|
+
console.log(`Improvement: ${((target.post_optimization_score / target.pre_optimization_score - 1) * 100).toFixed(1)}%`);
|
|
113
|
+
console.log(`Cost: $${target.cost.toFixed(4)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Key Features
|
|
119
|
+
|
|
120
|
+
- **Automatic Optimization**: Adapts both system prompts and user message templates
|
|
121
|
+
- **Evaluation Metrics**: Choose from standard metrics (semantic similarity, JSON matching, SQL) or provide custom evaluation
|
|
122
|
+
- **Dataset Requirements**: Minimum 25 training examples (more examples = better results)
|
|
123
|
+
- **Processing Time**: Typically 10-30 minutes depending on dataset size and number of target models
|
|
124
|
+
- **Subscription Tiers**: Support for 1-10 target models depending on your plan
|
|
125
|
+
|
|
126
|
+
#### Evaluation Metrics
|
|
127
|
+
|
|
128
|
+
Choose from standard metrics:
|
|
129
|
+
|
|
130
|
+
- `LLMaaJ:Sem_Sim_1`, `LLMaaJ:Sem_Sim_3`, `LLMaaJ:Sem_Sim_10` - Semantic similarity
|
|
131
|
+
- `LLMaaJ:SQL` - SQL query validation
|
|
132
|
+
- `JSON_Match` - JSON structure matching
|
|
133
|
+
|
|
134
|
+
Or provide custom evaluation configuration with your own LLM judge.
|
|
135
|
+
|
|
136
|
+
#### Best Practices
|
|
137
|
+
|
|
138
|
+
1. **Use Representative Examples**: Include diverse examples from your production workload
|
|
139
|
+
2. **Sufficient Dataset Size**: Use at least 25 training examples (50+ recommended)
|
|
140
|
+
3. **Train/Test Split**: Separate train_goldens and test_goldens for proper validation
|
|
141
|
+
4. **A/B Test Results**: Validate optimized prompts in production before full deployment
|
|
142
|
+
|
|
143
|
+
For more details, see the [Prompt Adaptation documentation](https://docs.notdiamond.ai/docs/adapting-prompts-to-new-models).
|
|
144
|
+
|
|
145
|
+
### Model Routing
|
|
146
|
+
|
|
147
|
+
Not Diamond also provides intelligent model routing to select the best model for your query:
|
|
148
|
+
|
|
149
|
+
<!-- prettier-ignore -->
|
|
150
|
+
```ts
|
|
151
|
+
const response = await client.modelRouter.selectModel({
|
|
152
|
+
llm_providers: [
|
|
153
|
+
{ model: 'gpt-4o', provider: 'openai' },
|
|
154
|
+
{ model: 'claude-sonnet-4-5-20250929', provider: 'anthropic' },
|
|
155
|
+
{ model: 'gemini-2.5-flash', provider: 'google' },
|
|
156
|
+
],
|
|
157
|
+
messages: [
|
|
158
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
159
|
+
{ role: 'user', content: 'Explain quantum computing in simple terms' },
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
console.log(response.providers);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Request & Response types
|
|
167
|
+
|
|
168
|
+
This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
|
|
12
169
|
|
|
170
|
+
<!-- prettier-ignore -->
|
|
13
171
|
```ts
|
|
14
|
-
import
|
|
172
|
+
import NotDiamond from 'notdiamond';
|
|
173
|
+
|
|
174
|
+
const client = new NotDiamond({
|
|
175
|
+
apiKey: process.env['NOT_DIAMOND_API_KEY'], // This is the default and can be omitted
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const params: NotDiamond.PromptAdaptCreateParams = {
|
|
179
|
+
fields: ['question', 'context'],
|
|
180
|
+
system_prompt: 'You are a helpful assistant.',
|
|
181
|
+
target_models: [
|
|
182
|
+
{
|
|
183
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
184
|
+
provider: 'anthropic',
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
template: 'Context: {context}\nQuestion: {question}\nAnswer:',
|
|
188
|
+
train_goldens: [
|
|
189
|
+
{
|
|
190
|
+
fields: {
|
|
191
|
+
question: 'What is 2+2?',
|
|
192
|
+
context: 'Basic arithmetic',
|
|
193
|
+
},
|
|
194
|
+
answer: '4',
|
|
195
|
+
},
|
|
196
|
+
// Add at least 25 examples for best results
|
|
197
|
+
],
|
|
198
|
+
test_goldens: [
|
|
199
|
+
{
|
|
200
|
+
fields: {
|
|
201
|
+
question: 'What is 3*3?',
|
|
202
|
+
context: 'Basic arithmetic',
|
|
203
|
+
},
|
|
204
|
+
answer: '9',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
const response: NotDiamond.PromptAdaptCreateResponse = await client.prompt.adapt.create(params);
|
|
209
|
+
console.log(response.adaptation_run_id);
|
|
15
210
|
```
|
|
16
211
|
|
|
17
|
-
|
|
212
|
+
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
|
|
213
|
+
|
|
214
|
+
## File uploads
|
|
18
215
|
|
|
19
|
-
|
|
216
|
+
Request parameters that correspond to file uploads can be passed in many different forms:
|
|
20
217
|
|
|
21
|
-
|
|
218
|
+
- `File` (or an object with the same structure)
|
|
219
|
+
- a `fetch` `Response` (or an object with the same structure)
|
|
220
|
+
- an `fs.ReadStream`
|
|
221
|
+
- the return value of our `toFile` helper
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import fs from 'fs';
|
|
225
|
+
import NotDiamond, { toFile } from 'notdiamond';
|
|
226
|
+
|
|
227
|
+
const client = new NotDiamond();
|
|
228
|
+
|
|
229
|
+
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
|
|
230
|
+
await client.customRouter.trainCustomRouter({
|
|
231
|
+
dataset_file: fs.createReadStream('/path/to/file'),
|
|
232
|
+
language: 'english',
|
|
233
|
+
llm_providers:
|
|
234
|
+
'[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
|
|
235
|
+
maximize: true,
|
|
236
|
+
prompt_column: 'prompt',
|
|
237
|
+
});
|
|
22
238
|
|
|
23
|
-
|
|
239
|
+
// Or if you have the web `File` API you can pass a `File` instance:
|
|
240
|
+
await client.customRouter.trainCustomRouter({
|
|
241
|
+
dataset_file: new File(['my bytes'], 'file'),
|
|
242
|
+
language: 'english',
|
|
243
|
+
llm_providers:
|
|
244
|
+
'[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
|
|
245
|
+
maximize: true,
|
|
246
|
+
prompt_column: 'prompt',
|
|
247
|
+
});
|
|
24
248
|
|
|
25
|
-
|
|
26
|
-
|
|
249
|
+
// You can also pass a `fetch` `Response`:
|
|
250
|
+
await client.customRouter.trainCustomRouter({
|
|
251
|
+
dataset_file: await fetch('https://somesite/file'),
|
|
252
|
+
language: 'english',
|
|
253
|
+
llm_providers:
|
|
254
|
+
'[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
|
|
255
|
+
maximize: true,
|
|
256
|
+
prompt_column: 'prompt',
|
|
257
|
+
});
|
|
27
258
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
259
|
+
// Finally, if none of the above are convenient, you can use our `toFile` helper:
|
|
260
|
+
await client.customRouter.trainCustomRouter({
|
|
261
|
+
dataset_file: await toFile(Buffer.from('my bytes'), 'file'),
|
|
262
|
+
language: 'english',
|
|
263
|
+
llm_providers:
|
|
264
|
+
'[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
|
|
265
|
+
maximize: true,
|
|
266
|
+
prompt_column: 'prompt',
|
|
267
|
+
});
|
|
268
|
+
await client.customRouter.trainCustomRouter({
|
|
269
|
+
dataset_file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
|
|
270
|
+
language: 'english',
|
|
271
|
+
llm_providers:
|
|
272
|
+
'[{"provider": "openai", "model": "gpt-4o"}, {"provider": "anthropic", "model": "claude-sonnet-4-5-20250929"}]',
|
|
273
|
+
maximize: true,
|
|
274
|
+
prompt_column: 'prompt',
|
|
31
275
|
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Handling errors
|
|
279
|
+
|
|
280
|
+
When the library is unable to connect to the API,
|
|
281
|
+
or if the API returns a non-success status code (i.e., 4xx or 5xx response),
|
|
282
|
+
a subclass of `APIError` will be thrown:
|
|
32
283
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
284
|
+
<!-- prettier-ignore -->
|
|
285
|
+
```ts
|
|
286
|
+
import NotDiamond from 'notdiamond';
|
|
287
|
+
|
|
288
|
+
const client = new NotDiamond();
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
await client.prompt.adapt.create({
|
|
292
|
+
fields: ['question'],
|
|
293
|
+
system_prompt: 'You are a helpful assistant.',
|
|
294
|
+
target_models: [
|
|
295
|
+
{
|
|
296
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
297
|
+
provider: 'anthropic',
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
model: 'gemini-2.5-flash',
|
|
301
|
+
provider: 'google',
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
template: 'Question: {question}\nAnswer:',
|
|
305
|
+
train_goldens: [
|
|
306
|
+
{ fields: { question: 'What is 2+2?' }, answer: '4' },
|
|
307
|
+
// Add at least 25 examples...
|
|
308
|
+
],
|
|
309
|
+
test_goldens: [
|
|
310
|
+
{ fields: { question: 'What is 3*3?' }, answer: '9' },
|
|
43
311
|
],
|
|
44
|
-
// Set the optimization criteria to latency
|
|
45
|
-
tradeoff: 'latency',
|
|
46
312
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.
|
|
51
|
-
|
|
313
|
+
} catch (err) {
|
|
314
|
+
if (err instanceof NotDiamond.APIConnectionError) {
|
|
315
|
+
console.log('The server could not be reached');
|
|
316
|
+
console.log(err.cause); // an underlying Error, likely from fetch()
|
|
317
|
+
} else if (err instanceof NotDiamond.RateLimitError) {
|
|
318
|
+
console.log('A 429 status code was received; we should back off a bit.');
|
|
319
|
+
} else if (err instanceof NotDiamond.APIError) {
|
|
320
|
+
console.log(err.status); // 400
|
|
321
|
+
console.log(err.name); // BadRequestError
|
|
322
|
+
console.log(err.headers); // {server: 'nginx', ...}
|
|
323
|
+
} else {
|
|
324
|
+
throw err;
|
|
52
325
|
}
|
|
53
|
-
|
|
54
|
-
// 3. Log the results
|
|
55
|
-
// Display the text response
|
|
56
|
-
console.log('LLM output:', result.content);
|
|
57
|
-
// Display the selected provider(s)
|
|
58
|
-
console.log('Selected providers:', result.providers);
|
|
59
|
-
// Show the unique session ID for this request
|
|
60
|
-
console.log('Session ID:', result.session_id);
|
|
61
326
|
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Error codes are as follows:
|
|
330
|
+
|
|
331
|
+
| Status Code | Error Type |
|
|
332
|
+
| ----------- | -------------------------- |
|
|
333
|
+
| 400 | `BadRequestError` |
|
|
334
|
+
| 401 | `AuthenticationError` |
|
|
335
|
+
| 403 | `PermissionDeniedError` |
|
|
336
|
+
| 404 | `NotFoundError` |
|
|
337
|
+
| 422 | `UnprocessableEntityError` |
|
|
338
|
+
| 429 | `RateLimitError` |
|
|
339
|
+
| >=500 | `InternalServerError` |
|
|
340
|
+
| N/A | `APIConnectionError` |
|
|
341
|
+
|
|
342
|
+
### Retries
|
|
343
|
+
|
|
344
|
+
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
|
345
|
+
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
|
|
346
|
+
429 Rate Limit, and >=500 Internal errors will all be retried by default.
|
|
347
|
+
|
|
348
|
+
You can use the `maxRetries` option to configure or disable this:
|
|
349
|
+
|
|
350
|
+
<!-- prettier-ignore -->
|
|
351
|
+
```js
|
|
352
|
+
// Configure the default for all requests:
|
|
353
|
+
const client = new NotDiamond({
|
|
354
|
+
maxRetries: 0, // default is 2
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// Or, configure per-request:
|
|
358
|
+
await client.prompt.adapt.create({
|
|
359
|
+
fields: ['question'],
|
|
360
|
+
system_prompt: 'You are a helpful assistant.',
|
|
361
|
+
target_models: [
|
|
362
|
+
{
|
|
363
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
364
|
+
provider: 'anthropic',
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
model: 'gemini-2.5-flash',
|
|
368
|
+
provider: 'google',
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
template: 'Question: {question}\nAnswer:',
|
|
372
|
+
train_goldens: [
|
|
373
|
+
{ fields: { question: 'What is 2+2?' }, answer: '4' },
|
|
374
|
+
// Add at least 25 examples...
|
|
375
|
+
],
|
|
376
|
+
test_goldens: [
|
|
377
|
+
{ fields: { question: 'What is 3*3?' }, answer: '9' },
|
|
378
|
+
],
|
|
379
|
+
}, {
|
|
380
|
+
maxRetries: 5,
|
|
381
|
+
});
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Timeouts
|
|
385
|
+
|
|
386
|
+
Requests time out after 1 minute by default. You can configure this with a `timeout` option:
|
|
387
|
+
|
|
388
|
+
<!-- prettier-ignore -->
|
|
389
|
+
```ts
|
|
390
|
+
// Configure the default for all requests:
|
|
391
|
+
const client = new NotDiamond({
|
|
392
|
+
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
|
|
393
|
+
});
|
|
62
394
|
|
|
63
|
-
|
|
395
|
+
// Override per-request (note: prompt adaptation may take 10-30 minutes, so increase timeout accordingly):
|
|
396
|
+
await client.prompt.getAdaptStatus('your-adaptation-run-id', {
|
|
397
|
+
timeout: 120 * 1000, // 2 minutes
|
|
398
|
+
});
|
|
64
399
|
```
|
|
65
400
|
|
|
66
|
-
|
|
401
|
+
On timeout, an `APIConnectionTimeoutError` is thrown.
|
|
402
|
+
|
|
403
|
+
Note that requests which time out will be [retried twice by default](#retries).
|
|
67
404
|
|
|
68
|
-
|
|
405
|
+
## Advanced Usage
|
|
69
406
|
|
|
70
|
-
|
|
71
|
-
import { NotDiamond, Tool } from 'notdiamond';
|
|
407
|
+
### Accessing raw Response data (e.g., headers)
|
|
72
408
|
|
|
73
|
-
|
|
409
|
+
The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
|
|
410
|
+
This method returns as soon as the headers for a successful response are received and does not consume the response body, so you are free to write custom parsing or streaming logic.
|
|
74
411
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
412
|
+
You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
|
|
413
|
+
Unlike `.asResponse()` this method consumes the body, returning once it is parsed.
|
|
414
|
+
|
|
415
|
+
<!-- prettier-ignore -->
|
|
416
|
+
```ts
|
|
417
|
+
const client = new NotDiamond();
|
|
418
|
+
|
|
419
|
+
const response = await client.prompt.adapt
|
|
420
|
+
.create({
|
|
421
|
+
fields: ['question'],
|
|
422
|
+
system_prompt: 'You are a helpful assistant.',
|
|
423
|
+
target_models: [
|
|
424
|
+
{
|
|
425
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
426
|
+
provider: 'anthropic',
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
model: 'gemini-2.5-flash',
|
|
430
|
+
provider: 'google',
|
|
89
431
|
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
async function toolCallingExample() {
|
|
95
|
-
const result = await notDiamond.modelSelect({
|
|
96
|
-
messages: [{ content: 'What is 12x12?', role: 'user' }],
|
|
97
|
-
llmProviders: [
|
|
98
|
-
{ provider: 'openai', model: 'gpt-4-1106-preview' },
|
|
99
|
-
{ provider: 'anthropic', model: 'claude-3-sonnet-20240229' },
|
|
100
432
|
],
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
433
|
+
template: 'Question: {question}\nAnswer:',
|
|
434
|
+
train_goldens: [
|
|
435
|
+
{ fields: { question: 'What is 2+2?' }, answer: '4' },
|
|
436
|
+
// Add at least 25 examples...
|
|
437
|
+
],
|
|
438
|
+
test_goldens: [
|
|
439
|
+
{ fields: { question: 'What is 3*3?' }, answer: '9' },
|
|
440
|
+
],
|
|
441
|
+
})
|
|
442
|
+
.asResponse();
|
|
443
|
+
console.log(response.headers.get('X-My-Header'));
|
|
444
|
+
console.log(response.statusText); // access the underlying Response object
|
|
445
|
+
|
|
446
|
+
const { data: adaptResponse, response: raw } = await client.prompt.adapt
|
|
447
|
+
.create({
|
|
448
|
+
fields: ['question'],
|
|
449
|
+
system_prompt: 'You are a helpful assistant.',
|
|
450
|
+
target_models: [
|
|
451
|
+
{
|
|
452
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
453
|
+
provider: 'anthropic',
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
model: 'gemini-2.5-flash',
|
|
457
|
+
provider: 'google',
|
|
458
|
+
},
|
|
459
|
+
],
|
|
460
|
+
template: 'Question: {question}\nAnswer:',
|
|
461
|
+
train_goldens: [
|
|
462
|
+
{ fields: { question: 'What is 2+2?' }, answer: '4' },
|
|
463
|
+
// Add at least 25 examples...
|
|
464
|
+
],
|
|
465
|
+
test_goldens: [
|
|
466
|
+
{ fields: { question: 'What is 3*3?' }, answer: '9' },
|
|
467
|
+
],
|
|
468
|
+
})
|
|
469
|
+
.withResponse();
|
|
470
|
+
console.log(raw.headers.get('X-My-Header'));
|
|
471
|
+
console.log(adaptResponse.adaptation_run_id);
|
|
472
|
+
```
|
|
108
473
|
|
|
109
|
-
|
|
110
|
-
console.error('Error:', result.detail);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
474
|
+
### Logging
|
|
113
475
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
476
|
+
> [!IMPORTANT]
|
|
477
|
+
> All log messages are intended for debugging only. The format and content of log messages
|
|
478
|
+
> may change between releases.
|
|
479
|
+
|
|
480
|
+
#### Log levels
|
|
481
|
+
|
|
482
|
+
The log level can be configured in two ways:
|
|
483
|
+
|
|
484
|
+
1. Via the `NOT_DIAMOND_LOG` environment variable
|
|
485
|
+
2. Using the `logLevel` client option (overrides the environment variable if set)
|
|
486
|
+
|
|
487
|
+
```ts
|
|
488
|
+
import NotDiamond from 'notdiamond';
|
|
489
|
+
|
|
490
|
+
const client = new NotDiamond({
|
|
491
|
+
logLevel: 'debug', // Show all log messages
|
|
492
|
+
});
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Available log levels, from most to least verbose:
|
|
496
|
+
|
|
497
|
+
- `'debug'` - Show debug messages, info, warnings, and errors
|
|
498
|
+
- `'info'` - Show info messages, warnings, and errors
|
|
499
|
+
- `'warn'` - Show warnings and errors (default)
|
|
500
|
+
- `'error'` - Show only errors
|
|
501
|
+
- `'off'` - Disable all logging
|
|
502
|
+
|
|
503
|
+
At the `'debug'` level, all HTTP requests and responses are logged, including headers and bodies.
|
|
504
|
+
Some authentication-related headers are redacted, but sensitive data in request and response bodies
|
|
505
|
+
may still be visible.
|
|
506
|
+
|
|
507
|
+
#### Custom logger
|
|
508
|
+
|
|
509
|
+
By default, this library logs to `globalThis.console`. You can also provide a custom logger.
|
|
510
|
+
Most logging libraries are supported, including [pino](https://www.npmjs.com/package/pino), [winston](https://www.npmjs.com/package/winston), [bunyan](https://www.npmjs.com/package/bunyan), [consola](https://www.npmjs.com/package/consola), [signale](https://www.npmjs.com/package/signale), and [@std/log](https://jsr.io/@std/log). If your logger doesn't work, please open an issue.
|
|
511
|
+
|
|
512
|
+
When providing a custom logger, the `logLevel` option still controls which messages are emitted, messages
|
|
513
|
+
below the configured level will not be sent to your logger.
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
import NotDiamond from 'notdiamond';
|
|
517
|
+
import pino from 'pino';
|
|
518
|
+
|
|
519
|
+
const logger = pino();
|
|
520
|
+
|
|
521
|
+
const client = new NotDiamond({
|
|
522
|
+
logger: logger.child({ name: 'NotDiamond' }),
|
|
523
|
+
logLevel: 'debug', // Send all messages to pino, allowing it to filter
|
|
524
|
+
});
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
### Making custom/undocumented requests
|
|
528
|
+
|
|
529
|
+
This library is typed for convenient access to the documented API. If you need to access undocumented
|
|
530
|
+
endpoints, params, or response properties, the library can still be used.
|
|
531
|
+
|
|
532
|
+
#### Undocumented endpoints
|
|
533
|
+
|
|
534
|
+
To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
|
|
535
|
+
Options on the client, such as retries, will be respected when making these requests.
|
|
536
|
+
|
|
537
|
+
```ts
|
|
538
|
+
await client.post('/some/path', {
|
|
539
|
+
body: { some_prop: 'foo' },
|
|
540
|
+
query: { some_query_arg: 'bar' },
|
|
541
|
+
});
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
#### Undocumented request params
|
|
545
|
+
|
|
546
|
+
To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
|
|
547
|
+
parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
|
|
548
|
+
send will be sent as-is.
|
|
549
|
+
|
|
550
|
+
```ts
|
|
551
|
+
client.prompt.adapt.create({
|
|
552
|
+
fields: ['question'],
|
|
553
|
+
system_prompt: 'You are a helpful assistant.',
|
|
554
|
+
target_models: [{ model: 'claude-sonnet-4-5-20250929', provider: 'anthropic' }],
|
|
555
|
+
template: 'Question: {question}\nAnswer:',
|
|
556
|
+
train_goldens: [{ fields: { question: 'What is 2+2?' }, answer: '4' }],
|
|
557
|
+
// @ts-expect-error experimental_feature is not yet public
|
|
558
|
+
experimental_feature: true,
|
|
559
|
+
});
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
|
|
563
|
+
extra param in the body.
|
|
117
564
|
|
|
118
|
-
|
|
565
|
+
If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
|
|
566
|
+
options.
|
|
567
|
+
|
|
568
|
+
#### Undocumented response properties
|
|
569
|
+
|
|
570
|
+
To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
|
|
571
|
+
the response object, or cast the response object to the requisite type. Like the request params, we do not
|
|
572
|
+
validate or strip extra properties from the response from the API.
|
|
573
|
+
|
|
574
|
+
### Customizing the fetch client
|
|
575
|
+
|
|
576
|
+
By default, this library expects a global `fetch` function is defined.
|
|
577
|
+
|
|
578
|
+
If you want to use a different `fetch` function, you can either polyfill the global:
|
|
579
|
+
|
|
580
|
+
```ts
|
|
581
|
+
import fetch from 'my-fetch';
|
|
582
|
+
|
|
583
|
+
globalThis.fetch = fetch;
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
Or pass it to the client:
|
|
587
|
+
|
|
588
|
+
```ts
|
|
589
|
+
import NotDiamond from 'notdiamond';
|
|
590
|
+
import fetch from 'my-fetch';
|
|
591
|
+
|
|
592
|
+
const client = new NotDiamond({ fetch });
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Fetch options
|
|
596
|
+
|
|
597
|
+
If you want to set custom `fetch` options without overriding the `fetch` function, you can provide a `fetchOptions` object when instantiating the client or making a request. (Request-specific options override client options.)
|
|
598
|
+
|
|
599
|
+
```ts
|
|
600
|
+
import NotDiamond from 'notdiamond';
|
|
601
|
+
|
|
602
|
+
const client = new NotDiamond({
|
|
603
|
+
fetchOptions: {
|
|
604
|
+
// `RequestInit` options
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
#### Configuring proxies
|
|
610
|
+
|
|
611
|
+
To modify proxy behavior, you can provide custom `fetchOptions` that add runtime-specific proxy
|
|
612
|
+
options to requests:
|
|
613
|
+
|
|
614
|
+
<img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/node.svg" align="top" width="18" height="21"> **Node** <sup>[[docs](https://github.com/nodejs/undici/blob/main/docs/docs/api/ProxyAgent.md#example---proxyagent-with-fetch)]</sup>
|
|
615
|
+
|
|
616
|
+
```ts
|
|
617
|
+
import NotDiamond from 'notdiamond';
|
|
618
|
+
import * as undici from 'undici';
|
|
619
|
+
|
|
620
|
+
const proxyAgent = new undici.ProxyAgent('http://localhost:8888');
|
|
621
|
+
const client = new NotDiamond({
|
|
622
|
+
fetchOptions: {
|
|
623
|
+
dispatcher: proxyAgent,
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
<img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/bun.svg" align="top" width="18" height="21"> **Bun** <sup>[[docs](https://bun.sh/guides/http/proxy)]</sup>
|
|
629
|
+
|
|
630
|
+
```ts
|
|
631
|
+
import NotDiamond from 'notdiamond';
|
|
632
|
+
|
|
633
|
+
const client = new NotDiamond({
|
|
634
|
+
fetchOptions: {
|
|
635
|
+
proxy: 'http://localhost:8888',
|
|
636
|
+
},
|
|
637
|
+
});
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
<img src="https://raw.githubusercontent.com/stainless-api/sdk-assets/refs/heads/main/deno.svg" align="top" width="18" height="21"> **Deno** <sup>[[docs](https://docs.deno.com/api/deno/~/Deno.createHttpClient)]</sup>
|
|
641
|
+
|
|
642
|
+
```ts
|
|
643
|
+
import NotDiamond from 'npm:notdiamond';
|
|
644
|
+
|
|
645
|
+
const httpClient = Deno.createHttpClient({ proxy: { url: 'http://localhost:8888' } });
|
|
646
|
+
const client = new NotDiamond({
|
|
647
|
+
fetchOptions: {
|
|
648
|
+
client: httpClient,
|
|
649
|
+
},
|
|
650
|
+
});
|
|
119
651
|
```
|
|
120
652
|
|
|
121
|
-
##
|
|
653
|
+
## Frequently Asked Questions
|
|
654
|
+
|
|
655
|
+
## Semantic versioning
|
|
656
|
+
|
|
657
|
+
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
|
|
658
|
+
|
|
659
|
+
1. Changes that only affect static types, without breaking runtime behavior.
|
|
660
|
+
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
|
|
661
|
+
3. Changes that we do not expect to impact the vast majority of users in practice.
|
|
662
|
+
|
|
663
|
+
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
|
|
122
664
|
|
|
123
|
-
|
|
665
|
+
We are keen for your feedback; please open an [issue](https://www.github.com/Not-Diamond/not-diamond-typescript/issues) with questions, bugs, or suggestions.
|
|
124
666
|
|
|
125
|
-
##
|
|
667
|
+
## Requirements
|
|
126
668
|
|
|
127
|
-
|
|
128
|
-
- **tradeoff**: The factor to optimize for (e.g., 'latency', 'cost', 'performance').
|
|
129
|
-
- **tools**: Custom functions that the AI can use to perform specific tasks.
|
|
130
|
-
- **maxModelDepth**: The maximum number of models to include in the response (for advanced use cases).
|
|
669
|
+
TypeScript >= 4.9 is supported.
|
|
131
670
|
|
|
132
|
-
|
|
671
|
+
The following runtimes are supported:
|
|
133
672
|
|
|
134
|
-
|
|
673
|
+
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
|
|
674
|
+
- Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
|
|
675
|
+
- Deno v1.28.0 or higher.
|
|
676
|
+
- Bun 1.0 or later.
|
|
677
|
+
- Cloudflare Workers.
|
|
678
|
+
- Vercel Edge Runtime.
|
|
679
|
+
- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
|
|
680
|
+
- Nitro v2.6 or greater.
|
|
135
681
|
|
|
136
|
-
|
|
682
|
+
Note that React Native is not supported at this time.
|
|
137
683
|
|
|
138
|
-
If you
|
|
684
|
+
If you are interested in other runtime environments, please open or upvote an issue on GitHub.
|
|
139
685
|
|
|
140
|
-
##
|
|
686
|
+
## Contributing
|
|
141
687
|
|
|
142
|
-
|
|
688
|
+
See [the contributing documentation](./CONTRIBUTING.md).
|