notdiamond 0.3.10 → 0.3.12
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/dist/index.cjs +48 -15
- package/dist/index.d.cts +6 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +49 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
|
|
|
30
30
|
|
|
31
31
|
const name = "notdiamond";
|
|
32
32
|
const type = "module";
|
|
33
|
-
const version = "0.
|
|
33
|
+
const version = "1.0.0";
|
|
34
34
|
const author = "not-diamond";
|
|
35
35
|
const license = "MIT";
|
|
36
36
|
const description = "TS/JS client for the NotDiamond API";
|
|
@@ -282,7 +282,8 @@ const SupportedModel = {
|
|
|
282
282
|
LLAMA_3_1_8B_INSTRUCT_TURBO: "Meta-Llama-3.1-8B-Instruct-Turbo",
|
|
283
283
|
LLAMA_3_1_70B_INSTRUCT_TURBO: "Meta-Llama-3.1-70B-Instruct-Turbo",
|
|
284
284
|
LLAMA_3_1_405B_INSTRUCT_TURBO: "Meta-Llama-3.1-405B-Instruct-Turbo",
|
|
285
|
-
LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online"
|
|
285
|
+
LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online",
|
|
286
|
+
OPEN_MISTRAL_NEMO: "open-mistral-nemo"
|
|
286
287
|
};
|
|
287
288
|
({
|
|
288
289
|
[SupportedProvider.OPENAI]: [
|
|
@@ -328,7 +329,8 @@ const SupportedModel = {
|
|
|
328
329
|
SupportedModel.CODESTRAL_LATEST,
|
|
329
330
|
SupportedModel.OPEN_MISTRAL_7B,
|
|
330
331
|
SupportedModel.OPEN_MIXTRAL_8X7B,
|
|
331
|
-
SupportedModel.OPEN_MIXTRAL_8X22B
|
|
332
|
+
SupportedModel.OPEN_MIXTRAL_8X22B,
|
|
333
|
+
SupportedModel.OPEN_MISTRAL_NEMO
|
|
332
334
|
],
|
|
333
335
|
[SupportedProvider.PERPLEXITY]: [
|
|
334
336
|
SupportedModel.LLAMA_3_1_SONAR_LARGE_128K_ONLINE
|
|
@@ -436,10 +438,23 @@ function getLangChainModel(provider, llmKeys, responseModel) {
|
|
|
436
438
|
}
|
|
437
439
|
async function callLLM(provider, options, llmKeys) {
|
|
438
440
|
const model = getLangChainModel(provider, llmKeys, options.responseModel);
|
|
439
|
-
const langChainMessages =
|
|
441
|
+
const langChainMessages = extendProviderSystemPrompt(
|
|
442
|
+
options.messages.map(convertToLangChainMessage),
|
|
443
|
+
options,
|
|
444
|
+
provider
|
|
445
|
+
);
|
|
440
446
|
const response = await model.invoke(langChainMessages);
|
|
441
447
|
return extractContent(response);
|
|
442
448
|
}
|
|
449
|
+
function extendProviderSystemPrompt(messages$1, options, provider) {
|
|
450
|
+
const matchingProvider = options.llmProviders.find(
|
|
451
|
+
(p) => p.provider === provider.provider && p.model === provider.model
|
|
452
|
+
);
|
|
453
|
+
if (matchingProvider && matchingProvider.systemPrompt) {
|
|
454
|
+
messages$1.unshift(new messages.SystemMessage(matchingProvider.systemPrompt));
|
|
455
|
+
}
|
|
456
|
+
return messages$1;
|
|
457
|
+
}
|
|
443
458
|
function convertToLangChainMessage(msg) {
|
|
444
459
|
switch (msg.role) {
|
|
445
460
|
case "user":
|
|
@@ -454,7 +469,11 @@ function convertToLangChainMessage(msg) {
|
|
|
454
469
|
}
|
|
455
470
|
async function* callLLMStream(provider, options, llmKeys) {
|
|
456
471
|
const model = getLangChainModel(provider, llmKeys, options.responseModel);
|
|
457
|
-
const langChainMessages =
|
|
472
|
+
const langChainMessages = extendProviderSystemPrompt(
|
|
473
|
+
options.messages.map(convertToLangChainMessage),
|
|
474
|
+
options,
|
|
475
|
+
provider
|
|
476
|
+
);
|
|
458
477
|
const stream = await model.stream(langChainMessages);
|
|
459
478
|
for await (const chunk of stream) {
|
|
460
479
|
yield extractContent(chunk);
|
|
@@ -476,7 +495,7 @@ var __publicField = (obj, key, value) => {
|
|
|
476
495
|
const SDK_VERSION = packageJson.version;
|
|
477
496
|
dotenv__namespace.config();
|
|
478
497
|
const DEFAULT_TIMEOUT = 5;
|
|
479
|
-
const BASE_URL = "https://
|
|
498
|
+
const BASE_URL = "https://api.notdiamond.ai";
|
|
480
499
|
class NotDiamond {
|
|
481
500
|
constructor(options = {}) {
|
|
482
501
|
__publicField(this, "apiKey");
|
|
@@ -528,12 +547,21 @@ class NotDiamond {
|
|
|
528
547
|
...provider.contextLength !== void 0 && {
|
|
529
548
|
context_length: provider.contextLength
|
|
530
549
|
},
|
|
550
|
+
...provider.customInputPrice !== void 0 && {
|
|
551
|
+
input_price: provider.customInputPrice
|
|
552
|
+
},
|
|
531
553
|
...provider.inputPrice !== void 0 && {
|
|
532
554
|
input_price: provider.inputPrice
|
|
533
555
|
},
|
|
556
|
+
...provider.customOutputPrice !== void 0 && {
|
|
557
|
+
output_price: provider.customOutputPrice
|
|
558
|
+
},
|
|
534
559
|
...provider.outputPrice !== void 0 && {
|
|
535
560
|
output_price: provider.outputPrice
|
|
536
561
|
},
|
|
562
|
+
...provider.customLatency !== void 0 && {
|
|
563
|
+
latency: provider.customLatency
|
|
564
|
+
},
|
|
537
565
|
...provider.latency !== void 0 && { latency: provider.latency },
|
|
538
566
|
...provider.isCustom !== void 0 && {
|
|
539
567
|
is_custom: provider.isCustom
|
|
@@ -625,17 +653,23 @@ class NotDiamond {
|
|
|
625
653
|
async astream(options) {
|
|
626
654
|
const selectedModel = await this.modelSelect(options);
|
|
627
655
|
const { providers } = selectedModel;
|
|
628
|
-
console.log("providers received from modelSelect", providers);
|
|
629
656
|
const stream = await Promise.resolve(
|
|
630
|
-
callLLMStream(
|
|
657
|
+
callLLMStream(
|
|
658
|
+
providers?.[0] || {
|
|
659
|
+
provider: "openai",
|
|
660
|
+
model: "gpt-3.5-turbo"
|
|
661
|
+
},
|
|
662
|
+
options,
|
|
663
|
+
this.llmKeys
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
return {
|
|
667
|
+
provider: providers?.[0] || {
|
|
631
668
|
provider: "openai",
|
|
632
669
|
model: "gpt-3.5-turbo"
|
|
633
|
-
},
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
provider: "openai",
|
|
637
|
-
model: "gpt-3.5-turbo"
|
|
638
|
-
}, stream };
|
|
670
|
+
},
|
|
671
|
+
stream
|
|
672
|
+
};
|
|
639
673
|
}
|
|
640
674
|
/**
|
|
641
675
|
* Streams the results of the model.
|
|
@@ -647,7 +681,6 @@ class NotDiamond {
|
|
|
647
681
|
if (!options.llmProviders || options.llmProviders.length === 0) {
|
|
648
682
|
throw new Error("No LLM providers specified");
|
|
649
683
|
}
|
|
650
|
-
console.log("options received from stream", options);
|
|
651
684
|
const promise = this.astream(options);
|
|
652
685
|
if (callback) {
|
|
653
686
|
promise.then(async ({ provider, stream }) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -59,12 +59,13 @@ declare const SupportedModel: {
|
|
|
59
59
|
readonly LLAMA_3_1_70B_INSTRUCT_TURBO: "Meta-Llama-3.1-70B-Instruct-Turbo";
|
|
60
60
|
readonly LLAMA_3_1_405B_INSTRUCT_TURBO: "Meta-Llama-3.1-405B-Instruct-Turbo";
|
|
61
61
|
readonly LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online";
|
|
62
|
+
readonly OPEN_MISTRAL_NEMO: "open-mistral-nemo";
|
|
62
63
|
};
|
|
63
64
|
declare const ProviderModelMap: {
|
|
64
65
|
readonly openai: readonly ["gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-4", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-turbo", "gpt-4-turbo-preview", "gpt-4-turbo-2024-04-09", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o", "gpt-4o-mini-2024-07-18", "gpt-4o-mini", "gpt-4-0125-preview", "o1-preview", "o1-preview-2024-09-12", "o1-mini", "o1-mini-2024-09-12"];
|
|
65
66
|
readonly anthropic: readonly ["claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-5-sonnet-20240620", "claude-3-haiku-20240307"];
|
|
66
67
|
readonly google: readonly ["gemini-pro", "gemini-1.0-pro-latest", "gemini-1.5-pro-latest", "gemini-1.5-pro-exp-0801", "gemini-1.5-flash-latest"];
|
|
67
|
-
readonly mistral: readonly ["mistral-large-latest", "mistral-large-2407", "mistral-large-2402", "mistral-medium-latest", "mistral-small-latest", "codestral-latest", "open-mistral-7b", "open-mixtral-8x7b", "open-mixtral-8x22b"];
|
|
68
|
+
readonly mistral: readonly ["mistral-large-latest", "mistral-large-2407", "mistral-large-2402", "mistral-medium-latest", "mistral-small-latest", "codestral-latest", "open-mistral-7b", "open-mixtral-8x7b", "open-mixtral-8x22b", "open-mistral-nemo"];
|
|
68
69
|
readonly perplexity: readonly ["llama-3.1-sonar-large-128k-online"];
|
|
69
70
|
readonly cohere: readonly ["command-r", "command-r-plus"];
|
|
70
71
|
readonly together: readonly ["Mistral-7B-Instruct-v0.2", "Mixtral-8x7B-Instruct-v0.1", "Mixtral-8x22B-Instruct-v0.1", "Llama-3-70b-chat-hf", "Llama-3-8b-chat-hf", "Qwen2-72B-Instruct", "Meta-Llama-3.1-8B-Instruct-Turbo", "Meta-Llama-3.1-70B-Instruct-Turbo", "Meta-Llama-3.1-405B-Instruct-Turbo"];
|
|
@@ -77,9 +78,13 @@ interface Provider<T extends SupportedProviderType = SupportedProviderType> {
|
|
|
77
78
|
model: ModelForProvider<T>;
|
|
78
79
|
contextLength?: number;
|
|
79
80
|
inputPrice?: number;
|
|
81
|
+
customInputPrice?: number;
|
|
80
82
|
outputPrice?: number;
|
|
83
|
+
customOutputPrice?: number;
|
|
81
84
|
latency?: number;
|
|
85
|
+
customLatency?: number;
|
|
82
86
|
isCustom?: boolean;
|
|
87
|
+
systemPrompt?: string;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
interface NotDiamondOptions {
|
package/dist/index.d.mts
CHANGED
|
@@ -59,12 +59,13 @@ declare const SupportedModel: {
|
|
|
59
59
|
readonly LLAMA_3_1_70B_INSTRUCT_TURBO: "Meta-Llama-3.1-70B-Instruct-Turbo";
|
|
60
60
|
readonly LLAMA_3_1_405B_INSTRUCT_TURBO: "Meta-Llama-3.1-405B-Instruct-Turbo";
|
|
61
61
|
readonly LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online";
|
|
62
|
+
readonly OPEN_MISTRAL_NEMO: "open-mistral-nemo";
|
|
62
63
|
};
|
|
63
64
|
declare const ProviderModelMap: {
|
|
64
65
|
readonly openai: readonly ["gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-4", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-turbo", "gpt-4-turbo-preview", "gpt-4-turbo-2024-04-09", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o", "gpt-4o-mini-2024-07-18", "gpt-4o-mini", "gpt-4-0125-preview", "o1-preview", "o1-preview-2024-09-12", "o1-mini", "o1-mini-2024-09-12"];
|
|
65
66
|
readonly anthropic: readonly ["claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-5-sonnet-20240620", "claude-3-haiku-20240307"];
|
|
66
67
|
readonly google: readonly ["gemini-pro", "gemini-1.0-pro-latest", "gemini-1.5-pro-latest", "gemini-1.5-pro-exp-0801", "gemini-1.5-flash-latest"];
|
|
67
|
-
readonly mistral: readonly ["mistral-large-latest", "mistral-large-2407", "mistral-large-2402", "mistral-medium-latest", "mistral-small-latest", "codestral-latest", "open-mistral-7b", "open-mixtral-8x7b", "open-mixtral-8x22b"];
|
|
68
|
+
readonly mistral: readonly ["mistral-large-latest", "mistral-large-2407", "mistral-large-2402", "mistral-medium-latest", "mistral-small-latest", "codestral-latest", "open-mistral-7b", "open-mixtral-8x7b", "open-mixtral-8x22b", "open-mistral-nemo"];
|
|
68
69
|
readonly perplexity: readonly ["llama-3.1-sonar-large-128k-online"];
|
|
69
70
|
readonly cohere: readonly ["command-r", "command-r-plus"];
|
|
70
71
|
readonly together: readonly ["Mistral-7B-Instruct-v0.2", "Mixtral-8x7B-Instruct-v0.1", "Mixtral-8x22B-Instruct-v0.1", "Llama-3-70b-chat-hf", "Llama-3-8b-chat-hf", "Qwen2-72B-Instruct", "Meta-Llama-3.1-8B-Instruct-Turbo", "Meta-Llama-3.1-70B-Instruct-Turbo", "Meta-Llama-3.1-405B-Instruct-Turbo"];
|
|
@@ -77,9 +78,13 @@ interface Provider<T extends SupportedProviderType = SupportedProviderType> {
|
|
|
77
78
|
model: ModelForProvider<T>;
|
|
78
79
|
contextLength?: number;
|
|
79
80
|
inputPrice?: number;
|
|
81
|
+
customInputPrice?: number;
|
|
80
82
|
outputPrice?: number;
|
|
83
|
+
customOutputPrice?: number;
|
|
81
84
|
latency?: number;
|
|
85
|
+
customLatency?: number;
|
|
82
86
|
isCustom?: boolean;
|
|
87
|
+
systemPrompt?: string;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
interface NotDiamondOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -59,12 +59,13 @@ declare const SupportedModel: {
|
|
|
59
59
|
readonly LLAMA_3_1_70B_INSTRUCT_TURBO: "Meta-Llama-3.1-70B-Instruct-Turbo";
|
|
60
60
|
readonly LLAMA_3_1_405B_INSTRUCT_TURBO: "Meta-Llama-3.1-405B-Instruct-Turbo";
|
|
61
61
|
readonly LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online";
|
|
62
|
+
readonly OPEN_MISTRAL_NEMO: "open-mistral-nemo";
|
|
62
63
|
};
|
|
63
64
|
declare const ProviderModelMap: {
|
|
64
65
|
readonly openai: readonly ["gpt-3.5-turbo", "gpt-3.5-turbo-0125", "gpt-4", "gpt-4-0613", "gpt-4-1106-preview", "gpt-4-turbo", "gpt-4-turbo-preview", "gpt-4-turbo-2024-04-09", "gpt-4o-2024-05-13", "gpt-4o-2024-08-06", "gpt-4o", "gpt-4o-mini-2024-07-18", "gpt-4o-mini", "gpt-4-0125-preview", "o1-preview", "o1-preview-2024-09-12", "o1-mini", "o1-mini-2024-09-12"];
|
|
65
66
|
readonly anthropic: readonly ["claude-2.1", "claude-3-opus-20240229", "claude-3-sonnet-20240229", "claude-3-5-sonnet-20240620", "claude-3-haiku-20240307"];
|
|
66
67
|
readonly google: readonly ["gemini-pro", "gemini-1.0-pro-latest", "gemini-1.5-pro-latest", "gemini-1.5-pro-exp-0801", "gemini-1.5-flash-latest"];
|
|
67
|
-
readonly mistral: readonly ["mistral-large-latest", "mistral-large-2407", "mistral-large-2402", "mistral-medium-latest", "mistral-small-latest", "codestral-latest", "open-mistral-7b", "open-mixtral-8x7b", "open-mixtral-8x22b"];
|
|
68
|
+
readonly mistral: readonly ["mistral-large-latest", "mistral-large-2407", "mistral-large-2402", "mistral-medium-latest", "mistral-small-latest", "codestral-latest", "open-mistral-7b", "open-mixtral-8x7b", "open-mixtral-8x22b", "open-mistral-nemo"];
|
|
68
69
|
readonly perplexity: readonly ["llama-3.1-sonar-large-128k-online"];
|
|
69
70
|
readonly cohere: readonly ["command-r", "command-r-plus"];
|
|
70
71
|
readonly together: readonly ["Mistral-7B-Instruct-v0.2", "Mixtral-8x7B-Instruct-v0.1", "Mixtral-8x22B-Instruct-v0.1", "Llama-3-70b-chat-hf", "Llama-3-8b-chat-hf", "Qwen2-72B-Instruct", "Meta-Llama-3.1-8B-Instruct-Turbo", "Meta-Llama-3.1-70B-Instruct-Turbo", "Meta-Llama-3.1-405B-Instruct-Turbo"];
|
|
@@ -77,9 +78,13 @@ interface Provider<T extends SupportedProviderType = SupportedProviderType> {
|
|
|
77
78
|
model: ModelForProvider<T>;
|
|
78
79
|
contextLength?: number;
|
|
79
80
|
inputPrice?: number;
|
|
81
|
+
customInputPrice?: number;
|
|
80
82
|
outputPrice?: number;
|
|
83
|
+
customOutputPrice?: number;
|
|
81
84
|
latency?: number;
|
|
85
|
+
customLatency?: number;
|
|
82
86
|
isCustom?: boolean;
|
|
87
|
+
systemPrompt?: string;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
interface NotDiamondOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as dotenv from 'dotenv';
|
|
2
2
|
import { ChatOpenAI } from '@langchain/openai';
|
|
3
|
-
import { AIMessage,
|
|
3
|
+
import { AIMessage, SystemMessage, HumanMessage } from '@langchain/core/messages';
|
|
4
4
|
import { ChatAnthropic } from '@langchain/anthropic';
|
|
5
5
|
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
|
|
6
6
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
@@ -11,7 +11,7 @@ import { ChatTogetherAI } from '@langchain/community/chat_models/togetherai';
|
|
|
11
11
|
|
|
12
12
|
const name = "notdiamond";
|
|
13
13
|
const type = "module";
|
|
14
|
-
const version = "0.
|
|
14
|
+
const version = "1.0.0";
|
|
15
15
|
const author = "not-diamond";
|
|
16
16
|
const license = "MIT";
|
|
17
17
|
const description = "TS/JS client for the NotDiamond API";
|
|
@@ -263,7 +263,8 @@ const SupportedModel = {
|
|
|
263
263
|
LLAMA_3_1_8B_INSTRUCT_TURBO: "Meta-Llama-3.1-8B-Instruct-Turbo",
|
|
264
264
|
LLAMA_3_1_70B_INSTRUCT_TURBO: "Meta-Llama-3.1-70B-Instruct-Turbo",
|
|
265
265
|
LLAMA_3_1_405B_INSTRUCT_TURBO: "Meta-Llama-3.1-405B-Instruct-Turbo",
|
|
266
|
-
LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online"
|
|
266
|
+
LLAMA_3_1_SONAR_LARGE_128K_ONLINE: "llama-3.1-sonar-large-128k-online",
|
|
267
|
+
OPEN_MISTRAL_NEMO: "open-mistral-nemo"
|
|
267
268
|
};
|
|
268
269
|
({
|
|
269
270
|
[SupportedProvider.OPENAI]: [
|
|
@@ -309,7 +310,8 @@ const SupportedModel = {
|
|
|
309
310
|
SupportedModel.CODESTRAL_LATEST,
|
|
310
311
|
SupportedModel.OPEN_MISTRAL_7B,
|
|
311
312
|
SupportedModel.OPEN_MIXTRAL_8X7B,
|
|
312
|
-
SupportedModel.OPEN_MIXTRAL_8X22B
|
|
313
|
+
SupportedModel.OPEN_MIXTRAL_8X22B,
|
|
314
|
+
SupportedModel.OPEN_MISTRAL_NEMO
|
|
313
315
|
],
|
|
314
316
|
[SupportedProvider.PERPLEXITY]: [
|
|
315
317
|
SupportedModel.LLAMA_3_1_SONAR_LARGE_128K_ONLINE
|
|
@@ -417,10 +419,23 @@ function getLangChainModel(provider, llmKeys, responseModel) {
|
|
|
417
419
|
}
|
|
418
420
|
async function callLLM(provider, options, llmKeys) {
|
|
419
421
|
const model = getLangChainModel(provider, llmKeys, options.responseModel);
|
|
420
|
-
const langChainMessages =
|
|
422
|
+
const langChainMessages = extendProviderSystemPrompt(
|
|
423
|
+
options.messages.map(convertToLangChainMessage),
|
|
424
|
+
options,
|
|
425
|
+
provider
|
|
426
|
+
);
|
|
421
427
|
const response = await model.invoke(langChainMessages);
|
|
422
428
|
return extractContent(response);
|
|
423
429
|
}
|
|
430
|
+
function extendProviderSystemPrompt(messages, options, provider) {
|
|
431
|
+
const matchingProvider = options.llmProviders.find(
|
|
432
|
+
(p) => p.provider === provider.provider && p.model === provider.model
|
|
433
|
+
);
|
|
434
|
+
if (matchingProvider && matchingProvider.systemPrompt) {
|
|
435
|
+
messages.unshift(new SystemMessage(matchingProvider.systemPrompt));
|
|
436
|
+
}
|
|
437
|
+
return messages;
|
|
438
|
+
}
|
|
424
439
|
function convertToLangChainMessage(msg) {
|
|
425
440
|
switch (msg.role) {
|
|
426
441
|
case "user":
|
|
@@ -435,7 +450,11 @@ function convertToLangChainMessage(msg) {
|
|
|
435
450
|
}
|
|
436
451
|
async function* callLLMStream(provider, options, llmKeys) {
|
|
437
452
|
const model = getLangChainModel(provider, llmKeys, options.responseModel);
|
|
438
|
-
const langChainMessages =
|
|
453
|
+
const langChainMessages = extendProviderSystemPrompt(
|
|
454
|
+
options.messages.map(convertToLangChainMessage),
|
|
455
|
+
options,
|
|
456
|
+
provider
|
|
457
|
+
);
|
|
439
458
|
const stream = await model.stream(langChainMessages);
|
|
440
459
|
for await (const chunk of stream) {
|
|
441
460
|
yield extractContent(chunk);
|
|
@@ -457,7 +476,7 @@ var __publicField = (obj, key, value) => {
|
|
|
457
476
|
const SDK_VERSION = packageJson.version;
|
|
458
477
|
dotenv.config();
|
|
459
478
|
const DEFAULT_TIMEOUT = 5;
|
|
460
|
-
const BASE_URL = "https://
|
|
479
|
+
const BASE_URL = "https://api.notdiamond.ai";
|
|
461
480
|
class NotDiamond {
|
|
462
481
|
constructor(options = {}) {
|
|
463
482
|
__publicField(this, "apiKey");
|
|
@@ -509,12 +528,21 @@ class NotDiamond {
|
|
|
509
528
|
...provider.contextLength !== void 0 && {
|
|
510
529
|
context_length: provider.contextLength
|
|
511
530
|
},
|
|
531
|
+
...provider.customInputPrice !== void 0 && {
|
|
532
|
+
input_price: provider.customInputPrice
|
|
533
|
+
},
|
|
512
534
|
...provider.inputPrice !== void 0 && {
|
|
513
535
|
input_price: provider.inputPrice
|
|
514
536
|
},
|
|
537
|
+
...provider.customOutputPrice !== void 0 && {
|
|
538
|
+
output_price: provider.customOutputPrice
|
|
539
|
+
},
|
|
515
540
|
...provider.outputPrice !== void 0 && {
|
|
516
541
|
output_price: provider.outputPrice
|
|
517
542
|
},
|
|
543
|
+
...provider.customLatency !== void 0 && {
|
|
544
|
+
latency: provider.customLatency
|
|
545
|
+
},
|
|
518
546
|
...provider.latency !== void 0 && { latency: provider.latency },
|
|
519
547
|
...provider.isCustom !== void 0 && {
|
|
520
548
|
is_custom: provider.isCustom
|
|
@@ -606,17 +634,23 @@ class NotDiamond {
|
|
|
606
634
|
async astream(options) {
|
|
607
635
|
const selectedModel = await this.modelSelect(options);
|
|
608
636
|
const { providers } = selectedModel;
|
|
609
|
-
console.log("providers received from modelSelect", providers);
|
|
610
637
|
const stream = await Promise.resolve(
|
|
611
|
-
callLLMStream(
|
|
638
|
+
callLLMStream(
|
|
639
|
+
providers?.[0] || {
|
|
640
|
+
provider: "openai",
|
|
641
|
+
model: "gpt-3.5-turbo"
|
|
642
|
+
},
|
|
643
|
+
options,
|
|
644
|
+
this.llmKeys
|
|
645
|
+
)
|
|
646
|
+
);
|
|
647
|
+
return {
|
|
648
|
+
provider: providers?.[0] || {
|
|
612
649
|
provider: "openai",
|
|
613
650
|
model: "gpt-3.5-turbo"
|
|
614
|
-
},
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
provider: "openai",
|
|
618
|
-
model: "gpt-3.5-turbo"
|
|
619
|
-
}, stream };
|
|
651
|
+
},
|
|
652
|
+
stream
|
|
653
|
+
};
|
|
620
654
|
}
|
|
621
655
|
/**
|
|
622
656
|
* Streams the results of the model.
|
|
@@ -628,7 +662,6 @@ class NotDiamond {
|
|
|
628
662
|
if (!options.llmProviders || options.llmProviders.length === 0) {
|
|
629
663
|
throw new Error("No LLM providers specified");
|
|
630
664
|
}
|
|
631
|
-
console.log("options received from stream", options);
|
|
632
665
|
const promise = this.astream(options);
|
|
633
666
|
if (callback) {
|
|
634
667
|
promise.then(async ({ provider, stream }) => {
|