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/dist/index.cjs
DELETED
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const dotenv = require('dotenv');
|
|
4
|
-
const openai = require('@langchain/openai');
|
|
5
|
-
const messages = require('@langchain/core/messages');
|
|
6
|
-
const anthropic = require('@langchain/anthropic');
|
|
7
|
-
const googleGenai = require('@langchain/google-genai');
|
|
8
|
-
const mistralai = require('@langchain/mistralai');
|
|
9
|
-
const chat_models = require('@langchain/core/language_models/chat_models');
|
|
10
|
-
const axios = require('axios');
|
|
11
|
-
const cohere = require('@langchain/cohere');
|
|
12
|
-
const togetherai = require('@langchain/community/chat_models/togetherai');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
|
-
|
|
16
|
-
function _interopNamespaceCompat(e) {
|
|
17
|
-
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
18
|
-
const n = Object.create(null);
|
|
19
|
-
if (e) {
|
|
20
|
-
for (const k in e) {
|
|
21
|
-
n[k] = e[k];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return n;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const dotenv__namespace = /*#__PURE__*/_interopNamespaceCompat(dotenv);
|
|
29
|
-
const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
30
|
-
|
|
31
|
-
const version = "1.1.4";
|
|
32
|
-
const packageJson = {
|
|
33
|
-
version: version};
|
|
34
|
-
|
|
35
|
-
class ChatPerplexity extends chat_models.BaseChatModel {
|
|
36
|
-
_generate(messages, options, runManager) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
"Method not implemented." + JSON.stringify(messages) + JSON.stringify(options) + JSON.stringify(runManager)
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
apiKey;
|
|
42
|
-
model;
|
|
43
|
-
constructor({ apiKey, model }) {
|
|
44
|
-
super({});
|
|
45
|
-
this.apiKey = apiKey;
|
|
46
|
-
this.model = model;
|
|
47
|
-
}
|
|
48
|
-
_llmType() {
|
|
49
|
-
return "perplexity";
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Invokes the Perplexity model.
|
|
53
|
-
* @param messages The messages to send to the model.
|
|
54
|
-
* @returns The results of the model.
|
|
55
|
-
*/
|
|
56
|
-
async invoke(messages$1) {
|
|
57
|
-
try {
|
|
58
|
-
const { data } = await axios__default.post(
|
|
59
|
-
"https://api.perplexity.ai/chat/completions",
|
|
60
|
-
{
|
|
61
|
-
model: this.model,
|
|
62
|
-
messages: messages$1.map((m) => ({
|
|
63
|
-
role: m._getType() === "human" ? "user" : m._getType(),
|
|
64
|
-
content: m.content
|
|
65
|
-
}))
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
headers: {
|
|
69
|
-
Authorization: `Bearer ${this.apiKey}`
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
return new messages.AIMessage(data.choices[0].message.content);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (axios__default.isAxiosError(error) && error.response) {
|
|
76
|
-
throw new Error(`Perplexity API error: ${error.response.statusText}`);
|
|
77
|
-
}
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const SupportedProvider = {
|
|
84
|
-
OPENAI: "openai",
|
|
85
|
-
ANTHROPIC: "anthropic",
|
|
86
|
-
GOOGLE: "google",
|
|
87
|
-
MISTRAL: "mistral",
|
|
88
|
-
PERPLEXITY: "perplexity",
|
|
89
|
-
COHERE: "cohere",
|
|
90
|
-
TOGETHERAI: "togetherai"
|
|
91
|
-
};
|
|
92
|
-
const SupportedModel = {
|
|
93
|
-
GPT_3_5_TURBO: "gpt-3.5-turbo",
|
|
94
|
-
GPT_3_5_TURBO_0125: "gpt-3.5-turbo-0125",
|
|
95
|
-
GPT_4: "gpt-4",
|
|
96
|
-
GPT_4_0613: "gpt-4-0613",
|
|
97
|
-
GPT_4_1106_PREVIEW: "gpt-4-1106-preview",
|
|
98
|
-
GPT_4_TURBO: "gpt-4-turbo",
|
|
99
|
-
GPT_4_TURBO_PREVIEW: "gpt-4-turbo-preview",
|
|
100
|
-
GPT_4_TURBO_2024_04_09: "gpt-4-turbo-2024-04-09",
|
|
101
|
-
GPT_4O_2024_05_13: "gpt-4o-2024-05-13",
|
|
102
|
-
GPT_4O_2024_08_06: "gpt-4o-2024-08-06",
|
|
103
|
-
GPT_4O: "gpt-4o",
|
|
104
|
-
GPT_4O_MINI_2024_07_18: "gpt-4o-mini-2024-07-18",
|
|
105
|
-
GPT_4O_MINI: "gpt-4o-mini",
|
|
106
|
-
GPT_4_0125_PREVIEW: "gpt-4-0125-preview",
|
|
107
|
-
GPT_4_1: "gpt-4.1",
|
|
108
|
-
GPT_4_1_2025_04_14: "gpt-4.1-2025-04-14",
|
|
109
|
-
GPT_4_1_MINI: "gpt-4.1-mini",
|
|
110
|
-
GPT_4_1_MINI_2025_04_14: "gpt-4.1-mini-2025-04-14",
|
|
111
|
-
GPT_4_1_NANO: "gpt-4.1-nano",
|
|
112
|
-
GPT_4_1_NANO_2025_04_14: "gpt-4.1-nano-2025-04-14",
|
|
113
|
-
CHATGPT_4O_LATEST: "chatgpt-4o-latest",
|
|
114
|
-
CLAUDE_2_1: "claude-2.1",
|
|
115
|
-
CLAUDE_3_OPUS_20240229: "claude-3-opus-20240229",
|
|
116
|
-
CLAUDE_3_SONNET_20240229: "claude-3-sonnet-20240229",
|
|
117
|
-
CLAUDE_3_5_SONNET_20240620: "claude-3-5-sonnet-20240620",
|
|
118
|
-
CLAUDE_3_5_SONNET_20241022: "claude-3-5-sonnet-20241022",
|
|
119
|
-
CLAUDE_3_5_SONNET_LATEST: "claude-3-5-sonnet-latest",
|
|
120
|
-
CLAUDE_3_HAIKU_20240307: "claude-3-haiku-20240307",
|
|
121
|
-
CLAUDE_3_5_HAIKU_20241022: "claude-3-5-haiku-20241022",
|
|
122
|
-
CLAUDE_3_7_SONNET_LATEST: "claude-3-7-sonnet-latest",
|
|
123
|
-
CLAUDE_3_7_SONNET_20250219: "claude-3-7-sonnet-20250219",
|
|
124
|
-
CLAUDE_OPUS_4_20250514: "claude-opus-4-20250514",
|
|
125
|
-
CLAUDE_SONNET_4_20250514: "claude-sonnet-4-20250514",
|
|
126
|
-
CLAUDE_OPUS_4_0: "claude-opus-4-0",
|
|
127
|
-
CLAUDE_SONNET_4_0: "claude-sonnet-4-0",
|
|
128
|
-
CLAUDE_SONNET_4_5: "claude-sonnet-4-5",
|
|
129
|
-
CLAUDE_SONNET_4_5_20250929: "claude-sonnet-4-5-20250929",
|
|
130
|
-
CLAUDE_HAIKU_4_5: "claude-haiku-4-5",
|
|
131
|
-
CLAUDE_HAIKU_4_5_20251001: "claude-haiku-4-5-20251001",
|
|
132
|
-
GEMINI_PRO: "gemini-pro",
|
|
133
|
-
GEMINI_1_PRO_LATEST: "gemini-1.0-pro-latest",
|
|
134
|
-
GEMINI_15_PRO_LATEST: "gemini-1.5-pro-latest",
|
|
135
|
-
GEMINI_15_PRO_EXP_0801: "gemini-1.5-pro-exp-0801",
|
|
136
|
-
GEMINI_15_FLASH_LATEST: "gemini-1.5-flash-latest",
|
|
137
|
-
GEMINI_2_0_FLASH: "gemini-2.0-flash",
|
|
138
|
-
GEMINI_2_0_FLASH_001: "gemini-2.0-flash-001",
|
|
139
|
-
GEMINI_2_5_FLASH: "gemini-2.5-flash",
|
|
140
|
-
GEMINI_2_5_PRO: "gemini-2.5-pro",
|
|
141
|
-
COMMAND_R: "command-r",
|
|
142
|
-
COMMAND_R_PLUS: "command-r-plus",
|
|
143
|
-
MISTRAL_LARGE_LATEST: "mistral-large-latest",
|
|
144
|
-
MISTRAL_LARGE_2407: "mistral-large-2407",
|
|
145
|
-
MISTRAL_LARGE_2402: "mistral-large-2402",
|
|
146
|
-
MISTRAL_MEDIUM_LATEST: "mistral-medium-latest",
|
|
147
|
-
MISTRAL_SMALL_LATEST: "mistral-small-latest",
|
|
148
|
-
CODESTRAL_LATEST: "codestral-latest",
|
|
149
|
-
OPEN_MISTRAL_7B: "open-mistral-7b",
|
|
150
|
-
OPEN_MIXTRAL_8X7B: "open-mixtral-8x7b",
|
|
151
|
-
OPEN_MIXTRAL_8X22B: "open-mixtral-8x22b",
|
|
152
|
-
MISTRAL_7B_INSTRUCT_V0_2: "Mistral-7B-Instruct-v0.2",
|
|
153
|
-
MIXTRAL_8X7B_INSTRUCT_V0_1: "Mixtral-8x7B-Instruct-v0.1",
|
|
154
|
-
MIXTRAL_8X22B_INSTRUCT_V0_1: "Mixtral-8x22B-Instruct-v0.1",
|
|
155
|
-
LLAMA_3_70B_CHAT_HF: "Llama-3-70b-chat-hf",
|
|
156
|
-
LLAMA_3_8B_CHAT_HF: "Llama-3-8b-chat-hf",
|
|
157
|
-
QWEN2_72B_INSTRUCT: "Qwen2-72B-Instruct",
|
|
158
|
-
LLAMA_3_1_8B_INSTRUCT_TURBO: "Meta-Llama-3.1-8B-Instruct-Turbo",
|
|
159
|
-
LLAMA_3_1_70B_INSTRUCT_TURBO: "Meta-Llama-3.1-70B-Instruct-Turbo",
|
|
160
|
-
LLAMA_3_1_405B_INSTRUCT_TURBO: "Meta-Llama-3.1-405B-Instruct-Turbo",
|
|
161
|
-
PERPLEXITY_SONAR: "sonar",
|
|
162
|
-
OPEN_MISTRAL_NEMO: "open-mistral-nemo",
|
|
163
|
-
DEEPSEEK_R1: "DeepSeek-R1"
|
|
164
|
-
};
|
|
165
|
-
({
|
|
166
|
-
[SupportedProvider.OPENAI]: [
|
|
167
|
-
SupportedModel.GPT_3_5_TURBO,
|
|
168
|
-
SupportedModel.GPT_3_5_TURBO_0125,
|
|
169
|
-
SupportedModel.GPT_4,
|
|
170
|
-
SupportedModel.GPT_4_0613,
|
|
171
|
-
SupportedModel.GPT_4_1106_PREVIEW,
|
|
172
|
-
SupportedModel.GPT_4_TURBO,
|
|
173
|
-
SupportedModel.GPT_4_TURBO_PREVIEW,
|
|
174
|
-
SupportedModel.GPT_4_TURBO_2024_04_09,
|
|
175
|
-
SupportedModel.GPT_4O_2024_05_13,
|
|
176
|
-
SupportedModel.GPT_4O_2024_08_06,
|
|
177
|
-
SupportedModel.GPT_4O,
|
|
178
|
-
SupportedModel.GPT_4O_MINI_2024_07_18,
|
|
179
|
-
SupportedModel.GPT_4O_MINI,
|
|
180
|
-
SupportedModel.GPT_4_0125_PREVIEW,
|
|
181
|
-
SupportedModel.CHATGPT_4O_LATEST,
|
|
182
|
-
SupportedModel.GPT_4_1,
|
|
183
|
-
SupportedModel.GPT_4_1_2025_04_14,
|
|
184
|
-
SupportedModel.GPT_4_1_MINI,
|
|
185
|
-
SupportedModel.GPT_4_1_MINI_2025_04_14,
|
|
186
|
-
SupportedModel.GPT_4_1_NANO,
|
|
187
|
-
SupportedModel.GPT_4_1_NANO_2025_04_14
|
|
188
|
-
],
|
|
189
|
-
[SupportedProvider.ANTHROPIC]: [
|
|
190
|
-
SupportedModel.CLAUDE_2_1,
|
|
191
|
-
SupportedModel.CLAUDE_3_OPUS_20240229,
|
|
192
|
-
SupportedModel.CLAUDE_3_SONNET_20240229,
|
|
193
|
-
SupportedModel.CLAUDE_3_5_SONNET_20240620,
|
|
194
|
-
SupportedModel.CLAUDE_3_5_SONNET_20241022,
|
|
195
|
-
SupportedModel.CLAUDE_3_5_SONNET_LATEST,
|
|
196
|
-
SupportedModel.CLAUDE_3_HAIKU_20240307,
|
|
197
|
-
SupportedModel.CLAUDE_3_5_HAIKU_20241022,
|
|
198
|
-
SupportedModel.CLAUDE_3_7_SONNET_LATEST,
|
|
199
|
-
SupportedModel.CLAUDE_3_7_SONNET_20250219,
|
|
200
|
-
SupportedModel.CLAUDE_OPUS_4_20250514,
|
|
201
|
-
SupportedModel.CLAUDE_SONNET_4_20250514,
|
|
202
|
-
SupportedModel.CLAUDE_OPUS_4_0,
|
|
203
|
-
SupportedModel.CLAUDE_SONNET_4_0,
|
|
204
|
-
SupportedModel.CLAUDE_SONNET_4_5,
|
|
205
|
-
SupportedModel.CLAUDE_SONNET_4_5_20250929,
|
|
206
|
-
SupportedModel.CLAUDE_HAIKU_4_5,
|
|
207
|
-
SupportedModel.CLAUDE_HAIKU_4_5_20251001
|
|
208
|
-
],
|
|
209
|
-
[SupportedProvider.GOOGLE]: [
|
|
210
|
-
SupportedModel.GEMINI_PRO,
|
|
211
|
-
SupportedModel.GEMINI_1_PRO_LATEST,
|
|
212
|
-
SupportedModel.GEMINI_15_PRO_LATEST,
|
|
213
|
-
SupportedModel.GEMINI_15_PRO_EXP_0801,
|
|
214
|
-
SupportedModel.GEMINI_15_FLASH_LATEST,
|
|
215
|
-
SupportedModel.GEMINI_2_0_FLASH,
|
|
216
|
-
SupportedModel.GEMINI_2_0_FLASH_001,
|
|
217
|
-
SupportedModel.GEMINI_2_5_FLASH,
|
|
218
|
-
SupportedModel.GEMINI_2_5_PRO
|
|
219
|
-
],
|
|
220
|
-
[SupportedProvider.MISTRAL]: [
|
|
221
|
-
SupportedModel.MISTRAL_LARGE_LATEST,
|
|
222
|
-
SupportedModel.MISTRAL_LARGE_2407,
|
|
223
|
-
SupportedModel.MISTRAL_LARGE_2402,
|
|
224
|
-
SupportedModel.MISTRAL_MEDIUM_LATEST,
|
|
225
|
-
SupportedModel.MISTRAL_SMALL_LATEST,
|
|
226
|
-
SupportedModel.CODESTRAL_LATEST,
|
|
227
|
-
SupportedModel.OPEN_MISTRAL_7B,
|
|
228
|
-
SupportedModel.OPEN_MIXTRAL_8X7B,
|
|
229
|
-
SupportedModel.OPEN_MIXTRAL_8X22B,
|
|
230
|
-
SupportedModel.OPEN_MISTRAL_NEMO
|
|
231
|
-
],
|
|
232
|
-
[SupportedProvider.PERPLEXITY]: [SupportedModel.PERPLEXITY_SONAR],
|
|
233
|
-
[SupportedProvider.COHERE]: [
|
|
234
|
-
SupportedModel.COMMAND_R,
|
|
235
|
-
SupportedModel.COMMAND_R_PLUS
|
|
236
|
-
],
|
|
237
|
-
[SupportedProvider.TOGETHERAI]: [
|
|
238
|
-
SupportedModel.MISTRAL_7B_INSTRUCT_V0_2,
|
|
239
|
-
SupportedModel.MIXTRAL_8X7B_INSTRUCT_V0_1,
|
|
240
|
-
SupportedModel.MIXTRAL_8X22B_INSTRUCT_V0_1,
|
|
241
|
-
SupportedModel.LLAMA_3_70B_CHAT_HF,
|
|
242
|
-
SupportedModel.LLAMA_3_8B_CHAT_HF,
|
|
243
|
-
SupportedModel.QWEN2_72B_INSTRUCT,
|
|
244
|
-
SupportedModel.LLAMA_3_1_8B_INSTRUCT_TURBO,
|
|
245
|
-
SupportedModel.LLAMA_3_1_70B_INSTRUCT_TURBO,
|
|
246
|
-
SupportedModel.LLAMA_3_1_405B_INSTRUCT_TURBO,
|
|
247
|
-
SupportedModel.DEEPSEEK_R1
|
|
248
|
-
]
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
function getLangChainModel(provider, llmKeys, responseModel) {
|
|
252
|
-
const { OPENAI, ANTHROPIC, GOOGLE, MISTRAL, PERPLEXITY, COHERE, TOGETHERAI } = SupportedProvider;
|
|
253
|
-
switch (provider.provider) {
|
|
254
|
-
case OPENAI:
|
|
255
|
-
if (responseModel) {
|
|
256
|
-
return new openai.ChatOpenAI({
|
|
257
|
-
modelName: provider.model,
|
|
258
|
-
apiKey: llmKeys.openai || process.env.OPENAI_API_KEY
|
|
259
|
-
}).withStructuredOutput(responseModel);
|
|
260
|
-
}
|
|
261
|
-
return new openai.ChatOpenAI({
|
|
262
|
-
modelName: provider.model,
|
|
263
|
-
apiKey: llmKeys.openai || process.env.OPENAI_API_KEY
|
|
264
|
-
});
|
|
265
|
-
case ANTHROPIC:
|
|
266
|
-
if (responseModel) {
|
|
267
|
-
return new anthropic.ChatAnthropic({
|
|
268
|
-
modelName: provider.model,
|
|
269
|
-
anthropicApiKey: llmKeys.anthropic || process.env.ANTHROPIC_API_KEY
|
|
270
|
-
}).withStructuredOutput(responseModel);
|
|
271
|
-
}
|
|
272
|
-
return new anthropic.ChatAnthropic({
|
|
273
|
-
modelName: provider.model,
|
|
274
|
-
anthropicApiKey: llmKeys.anthropic || process.env.ANTHROPIC_API_KEY
|
|
275
|
-
});
|
|
276
|
-
case GOOGLE:
|
|
277
|
-
if (responseModel) {
|
|
278
|
-
return new googleGenai.ChatGoogleGenerativeAI({
|
|
279
|
-
modelName: provider.model,
|
|
280
|
-
apiKey: llmKeys.google || process.env.GOOGLE_API_KEY
|
|
281
|
-
}).withStructuredOutput(responseModel);
|
|
282
|
-
}
|
|
283
|
-
return new googleGenai.ChatGoogleGenerativeAI({
|
|
284
|
-
modelName: provider.model,
|
|
285
|
-
apiKey: llmKeys.google || process.env.GOOGLE_API_KEY
|
|
286
|
-
});
|
|
287
|
-
case MISTRAL:
|
|
288
|
-
if (responseModel) {
|
|
289
|
-
return new mistralai.ChatMistralAI({
|
|
290
|
-
modelName: provider.model,
|
|
291
|
-
apiKey: llmKeys.mistral || process.env.MISTRAL_API_KEY
|
|
292
|
-
}).withStructuredOutput(responseModel);
|
|
293
|
-
}
|
|
294
|
-
return new mistralai.ChatMistralAI({
|
|
295
|
-
modelName: provider.model,
|
|
296
|
-
apiKey: llmKeys.mistral || process.env.MISTRAL_API_KEY
|
|
297
|
-
});
|
|
298
|
-
case PERPLEXITY:
|
|
299
|
-
if (responseModel) {
|
|
300
|
-
return new ChatPerplexity({
|
|
301
|
-
apiKey: llmKeys.perplexity || process.env.PPLX_API_KEY || "",
|
|
302
|
-
model: provider.model
|
|
303
|
-
}).withStructuredOutput(responseModel);
|
|
304
|
-
}
|
|
305
|
-
return new ChatPerplexity({
|
|
306
|
-
apiKey: llmKeys.perplexity || process.env.PPLX_API_KEY || "",
|
|
307
|
-
model: provider.model
|
|
308
|
-
});
|
|
309
|
-
case COHERE:
|
|
310
|
-
if (responseModel) {
|
|
311
|
-
return new cohere.ChatCohere({
|
|
312
|
-
apiKey: process.env.COHERE_API_KEY || llmKeys.cohere,
|
|
313
|
-
model: provider.model
|
|
314
|
-
}).withStructuredOutput(responseModel);
|
|
315
|
-
}
|
|
316
|
-
return new cohere.ChatCohere({
|
|
317
|
-
apiKey: process.env.COHERE_API_KEY || llmKeys.cohere,
|
|
318
|
-
model: provider.model
|
|
319
|
-
});
|
|
320
|
-
case TOGETHERAI:
|
|
321
|
-
if (responseModel) {
|
|
322
|
-
return new togetherai.ChatTogetherAI({
|
|
323
|
-
apiKey: process.env.TOGETHERAI_API_KEY || llmKeys.togetherai,
|
|
324
|
-
model: getTogetheraiModel(provider.model)
|
|
325
|
-
}).withStructuredOutput(responseModel);
|
|
326
|
-
}
|
|
327
|
-
return new togetherai.ChatTogetherAI({
|
|
328
|
-
apiKey: process.env.TOGETHERAI_API_KEY || llmKeys.togetherai,
|
|
329
|
-
model: getTogetheraiModel(provider.model)
|
|
330
|
-
});
|
|
331
|
-
default:
|
|
332
|
-
throw new Error(`Unsupported provider: ${provider.provider}`);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
const getTogetheraiModel = (model) => {
|
|
336
|
-
if (model === SupportedModel.MISTRAL_7B_INSTRUCT_V0_2 || model === SupportedModel.MIXTRAL_8X7B_INSTRUCT_V0_1 || model === SupportedModel.MIXTRAL_8X22B_INSTRUCT_V0_1) {
|
|
337
|
-
return `mistralai/${model}`;
|
|
338
|
-
}
|
|
339
|
-
if (model === SupportedModel.LLAMA_3_70B_CHAT_HF || model === SupportedModel.LLAMA_3_8B_CHAT_HF || model === SupportedModel.LLAMA_3_1_8B_INSTRUCT_TURBO || model === SupportedModel.LLAMA_3_1_70B_INSTRUCT_TURBO || model === SupportedModel.LLAMA_3_1_405B_INSTRUCT_TURBO) {
|
|
340
|
-
return `meta-llama/${model}`;
|
|
341
|
-
}
|
|
342
|
-
if (model === SupportedModel.QWEN2_72B_INSTRUCT) {
|
|
343
|
-
return `Qwen/${model}`;
|
|
344
|
-
}
|
|
345
|
-
return model;
|
|
346
|
-
};
|
|
347
|
-
async function callLLM(provider, options, llmKeys, runtimeArgs) {
|
|
348
|
-
const model = getLangChainModel(provider, llmKeys, options.responseModel);
|
|
349
|
-
const langChainMessages = extendProviderSystemPrompt(
|
|
350
|
-
options.messages.map(convertToLangChainMessage),
|
|
351
|
-
options,
|
|
352
|
-
provider
|
|
353
|
-
);
|
|
354
|
-
const response = await model.invoke(langChainMessages, runtimeArgs);
|
|
355
|
-
return extractContent(response);
|
|
356
|
-
}
|
|
357
|
-
function extendProviderSystemPrompt(messages$1, options, provider) {
|
|
358
|
-
const matchingProvider = options.llmProviders.find(
|
|
359
|
-
(p) => p.provider === provider.provider && p.model === provider.model
|
|
360
|
-
);
|
|
361
|
-
if (matchingProvider && matchingProvider.systemPrompt) {
|
|
362
|
-
messages$1.unshift(new messages.SystemMessage(matchingProvider.systemPrompt));
|
|
363
|
-
}
|
|
364
|
-
return messages$1;
|
|
365
|
-
}
|
|
366
|
-
function convertToLangChainMessage(msg) {
|
|
367
|
-
switch (msg.role) {
|
|
368
|
-
case "user":
|
|
369
|
-
return new messages.HumanMessage(msg.content);
|
|
370
|
-
case "assistant":
|
|
371
|
-
return new messages.AIMessage(msg.content);
|
|
372
|
-
case "system":
|
|
373
|
-
return new messages.SystemMessage(msg.content);
|
|
374
|
-
default:
|
|
375
|
-
return new messages.HumanMessage(msg.content);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
async function* callLLMStream(provider, options, llmKeys, runtimeArgs) {
|
|
379
|
-
const model = getLangChainModel(provider, llmKeys, options.responseModel);
|
|
380
|
-
const langChainMessages = extendProviderSystemPrompt(
|
|
381
|
-
options.messages.map(convertToLangChainMessage),
|
|
382
|
-
options,
|
|
383
|
-
provider
|
|
384
|
-
);
|
|
385
|
-
const stream = await model.stream(langChainMessages, runtimeArgs);
|
|
386
|
-
for await (const chunk of stream) {
|
|
387
|
-
yield extractContent(chunk);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
function extractContent(response) {
|
|
391
|
-
if ("content" in response) {
|
|
392
|
-
return typeof response.content === "string" ? response.content : JSON.stringify(response.content);
|
|
393
|
-
}
|
|
394
|
-
return typeof response === "string" ? response : JSON.stringify(response);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const SDK_VERSION = packageJson.version;
|
|
398
|
-
dotenv__namespace.config();
|
|
399
|
-
const DEFAULT_TIMEOUT = 5;
|
|
400
|
-
const BASE_URL = "https://api.notdiamond.ai";
|
|
401
|
-
class NotDiamond {
|
|
402
|
-
apiKey;
|
|
403
|
-
apiUrl;
|
|
404
|
-
modelSelectUrl;
|
|
405
|
-
feedbackUrl;
|
|
406
|
-
createUrl;
|
|
407
|
-
llmKeys;
|
|
408
|
-
constructor(options = {}) {
|
|
409
|
-
this.apiKey = options.apiKey || process.env.NOTDIAMOND_API_KEY || "";
|
|
410
|
-
this.apiUrl = options.apiUrl || process.env.NOTDIAMOND_API_URL || BASE_URL;
|
|
411
|
-
this.llmKeys = options.llmKeys || {};
|
|
412
|
-
this.modelSelectUrl = `${this.apiUrl}/v2/modelRouter/modelSelect`;
|
|
413
|
-
this.feedbackUrl = `${this.apiUrl}/v2/report/metrics/feedback`;
|
|
414
|
-
this.createUrl = `${this.apiUrl}/v2/preferences/userPreferenceCreate`;
|
|
415
|
-
}
|
|
416
|
-
getAuthHeader() {
|
|
417
|
-
return `Bearer ${this.apiKey}`;
|
|
418
|
-
}
|
|
419
|
-
async postRequest(url, body) {
|
|
420
|
-
try {
|
|
421
|
-
const response = await axios__default.post(url, body, {
|
|
422
|
-
headers: {
|
|
423
|
-
Authorization: this.getAuthHeader(),
|
|
424
|
-
Accept: "application/json",
|
|
425
|
-
"Content-Type": "application/json",
|
|
426
|
-
"User-Agent": `TS-SDK/${SDK_VERSION}`
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
return response.data;
|
|
430
|
-
} catch (error) {
|
|
431
|
-
if (axios__default.isAxiosError(error) && error.response) {
|
|
432
|
-
return { detail: "An error occurred." };
|
|
433
|
-
}
|
|
434
|
-
console.error("error", error);
|
|
435
|
-
return { detail: "An unexpected error occurred." };
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Selects the best model for the given messages.
|
|
440
|
-
* @param options The options for the model.
|
|
441
|
-
* @returns The results of the model.
|
|
442
|
-
*/
|
|
443
|
-
async modelSelect(options) {
|
|
444
|
-
const requestBody = {
|
|
445
|
-
messages: options.messages,
|
|
446
|
-
llm_providers: options.llmProviders.map((provider) => ({
|
|
447
|
-
provider: provider.provider,
|
|
448
|
-
model: provider.model,
|
|
449
|
-
...provider.contextLength !== void 0 && {
|
|
450
|
-
context_length: provider.contextLength
|
|
451
|
-
},
|
|
452
|
-
...provider.customInputPrice !== void 0 && {
|
|
453
|
-
input_price: provider.customInputPrice
|
|
454
|
-
},
|
|
455
|
-
...provider.inputPrice !== void 0 && {
|
|
456
|
-
input_price: provider.inputPrice
|
|
457
|
-
},
|
|
458
|
-
...provider.customOutputPrice !== void 0 && {
|
|
459
|
-
output_price: provider.customOutputPrice
|
|
460
|
-
},
|
|
461
|
-
...provider.outputPrice !== void 0 && {
|
|
462
|
-
output_price: provider.outputPrice
|
|
463
|
-
},
|
|
464
|
-
...provider.customLatency !== void 0 && {
|
|
465
|
-
latency: provider.customLatency
|
|
466
|
-
},
|
|
467
|
-
...provider.latency !== void 0 && { latency: provider.latency },
|
|
468
|
-
...provider.isCustom !== void 0 && {
|
|
469
|
-
is_custom: provider.isCustom
|
|
470
|
-
}
|
|
471
|
-
})),
|
|
472
|
-
...options.tradeoff && {
|
|
473
|
-
tradeoff: options.tradeoff
|
|
474
|
-
},
|
|
475
|
-
...options.maxModelDepth && {
|
|
476
|
-
max_model_depth: options.maxModelDepth
|
|
477
|
-
},
|
|
478
|
-
...options.tools && { tools: options.tools },
|
|
479
|
-
...options.hashContent !== void 0 && {
|
|
480
|
-
hash_content: options.hashContent
|
|
481
|
-
},
|
|
482
|
-
...options.preferenceId && { preference_id: options.preferenceId },
|
|
483
|
-
...options.timeout ? { timeout: options.timeout } : {
|
|
484
|
-
timeout: DEFAULT_TIMEOUT
|
|
485
|
-
},
|
|
486
|
-
...options.default && { default: options.default },
|
|
487
|
-
...options.previousSession && {
|
|
488
|
-
previous_session: options.previousSession
|
|
489
|
-
},
|
|
490
|
-
...options.responseModel && {
|
|
491
|
-
response_model: options.responseModel
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
return this.postRequest(
|
|
495
|
-
this.modelSelectUrl,
|
|
496
|
-
requestBody
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Sends feedback to the NotDiamond API.
|
|
501
|
-
* @param options The options for the feedback.
|
|
502
|
-
* @returns The results of the feedback.
|
|
503
|
-
*/
|
|
504
|
-
async feedback(options) {
|
|
505
|
-
return this.postRequest(this.feedbackUrl, {
|
|
506
|
-
session_id: options.sessionId,
|
|
507
|
-
feedback: options.feedback,
|
|
508
|
-
provider: options.provider
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Creates a preference id.
|
|
513
|
-
* @returns The preference id.
|
|
514
|
-
*/
|
|
515
|
-
async createPreferenceId() {
|
|
516
|
-
const response = await this.postRequest(
|
|
517
|
-
this.createUrl,
|
|
518
|
-
{}
|
|
519
|
-
);
|
|
520
|
-
if ("preference_id" in response) {
|
|
521
|
-
return response.preference_id;
|
|
522
|
-
}
|
|
523
|
-
throw new Error("Invalid response: preference_id not found");
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
*
|
|
527
|
-
* @param options The options for the model.
|
|
528
|
-
* @returns A promise that resolves to the results of the model.
|
|
529
|
-
*/
|
|
530
|
-
async acreate(options, runtimeArgs = {}) {
|
|
531
|
-
const selectedModel = await this.modelSelect(options);
|
|
532
|
-
const { providers } = selectedModel;
|
|
533
|
-
const content = await callLLM(
|
|
534
|
-
providers[0],
|
|
535
|
-
options,
|
|
536
|
-
this.llmKeys,
|
|
537
|
-
runtimeArgs
|
|
538
|
-
);
|
|
539
|
-
return { content, providers };
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
*
|
|
543
|
-
* @param options The options for the model.
|
|
544
|
-
* @param callback Optional callback function to handle the result.
|
|
545
|
-
* @returns A promise that resolves to the results of the model or a callback function
|
|
546
|
-
*/
|
|
547
|
-
create(options, runtimeArgs = {}, callback) {
|
|
548
|
-
const promise = this.acreate(options, runtimeArgs);
|
|
549
|
-
if (callback) {
|
|
550
|
-
promise.then((result) => callback(null, result)).catch((error) => callback(error));
|
|
551
|
-
} else {
|
|
552
|
-
return promise;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Streams the results of the model asynchronously.
|
|
557
|
-
* @param options The options for the model.
|
|
558
|
-
* @returns A promise that resolves to an object containing the provider and an AsyncIterable of strings.
|
|
559
|
-
*/
|
|
560
|
-
async astream(options, runtimeArgs = {}) {
|
|
561
|
-
const selectedModel = await this.modelSelect(options);
|
|
562
|
-
const { providers } = selectedModel;
|
|
563
|
-
const stream = await Promise.resolve(
|
|
564
|
-
callLLMStream(
|
|
565
|
-
providers?.[0] || options.default,
|
|
566
|
-
options,
|
|
567
|
-
this.llmKeys,
|
|
568
|
-
runtimeArgs
|
|
569
|
-
)
|
|
570
|
-
);
|
|
571
|
-
return {
|
|
572
|
-
provider: providers?.[0] || options.default,
|
|
573
|
-
stream
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Streams the results of the model.
|
|
578
|
-
* @param options The options for the model.
|
|
579
|
-
* @param callback Optional callback function to handle each chunk of the stream.
|
|
580
|
-
* @returns A promise that resolves to an object containing the provider and an AsyncIterable of strings or a callback function
|
|
581
|
-
*/
|
|
582
|
-
stream(options, runtimeArgs = {}, callback) {
|
|
583
|
-
if (!options.llmProviders || options.llmProviders.length === 0) {
|
|
584
|
-
throw new Error("No LLM providers specified");
|
|
585
|
-
}
|
|
586
|
-
const promise = this.astream(options, runtimeArgs);
|
|
587
|
-
if (callback) {
|
|
588
|
-
promise.then(async ({ provider, stream }) => {
|
|
589
|
-
for await (const chunk of stream) {
|
|
590
|
-
callback(null, { provider, chunk });
|
|
591
|
-
}
|
|
592
|
-
}).catch((error) => callback(error));
|
|
593
|
-
} else {
|
|
594
|
-
return promise;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
exports.NotDiamond = NotDiamond;
|
|
600
|
-
exports.SupportedModel = SupportedModel;
|
|
601
|
-
exports.SupportedProvider = SupportedProvider;
|