@ampt/ai 2.0.7 → 2.2.0
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 +7 -0
- package/dist/index.cjs +251 -55
- package/dist/index.d.cts +4 -62
- package/dist/index.d.ts +4 -62
- package/dist/index.js +248 -55
- package/package.json +4 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [2.2.0](https://github.com/getampt/cloud/compare/@ampt/ai-v2.1.0...@ampt/ai-v2.2.0) (2026-11-08)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- **packages:** ship security and reliability minors ([#2912](https://github.com/getampt/cloud/issues/2912)) ([7138f91](https://github.com/getampt/cloud/commit/7138f91af8faf8569b3568f757731e95ae21dc9b))
|
package/dist/index.cjs
CHANGED
|
@@ -20196,7 +20196,7 @@ function request(url, options) {
|
|
|
20196
20196
|
resolve(result);
|
|
20197
20197
|
}
|
|
20198
20198
|
};
|
|
20199
|
-
const req = import_https.default.request(url, { agent }, (res) => {
|
|
20199
|
+
const req = import_https.default.request(url, { agent, headers: options.headers }, (res) => {
|
|
20200
20200
|
const bufs = [];
|
|
20201
20201
|
res.on("data", (data) => bufs.push(data));
|
|
20202
20202
|
res.on("end", () => {
|
|
@@ -20218,8 +20218,10 @@ var ALLOW = 0;
|
|
|
20218
20218
|
var QuotaReader = class {
|
|
20219
20219
|
url;
|
|
20220
20220
|
baseKey;
|
|
20221
|
+
invokeQuotasEnabled;
|
|
20221
20222
|
constructor(params) {
|
|
20222
20223
|
if (params.url && params.token && params.cacheName) {
|
|
20224
|
+
this.invokeQuotasEnabled = params.invokeQuotasEnabled;
|
|
20223
20225
|
this.url = `${params.url}/cache/${params.cacheName}?token=${params.token}&key={KEY}`;
|
|
20224
20226
|
this.baseKey = params.key;
|
|
20225
20227
|
}
|
|
@@ -20251,6 +20253,9 @@ var QuotaReader = class {
|
|
|
20251
20253
|
if (!quotaReader) {
|
|
20252
20254
|
return 0 /* ALLOW */;
|
|
20253
20255
|
}
|
|
20256
|
+
if (!quotaReader.invokeQuotasEnabled && type === "invocations" /* INVOCATIONS */) {
|
|
20257
|
+
return 0 /* ALLOW */;
|
|
20258
|
+
}
|
|
20254
20259
|
return await quotaReader.getThrottleState(type);
|
|
20255
20260
|
}
|
|
20256
20261
|
};
|
|
@@ -20533,6 +20538,15 @@ function guessServiceRegion(url, headers) {
|
|
|
20533
20538
|
}
|
|
20534
20539
|
|
|
20535
20540
|
// ../../lib/runtime-logging/index.ts
|
|
20541
|
+
function serializeError(err) {
|
|
20542
|
+
return {
|
|
20543
|
+
message: err.message,
|
|
20544
|
+
stack: err.stack,
|
|
20545
|
+
code: err.code,
|
|
20546
|
+
name: err.name,
|
|
20547
|
+
...err.cause && { cause: serializeError(err.cause) }
|
|
20548
|
+
};
|
|
20549
|
+
}
|
|
20536
20550
|
function systemError(errOrMsg, _msg) {
|
|
20537
20551
|
const err = typeof errOrMsg === "string" ? void 0 : errOrMsg;
|
|
20538
20552
|
const msg = typeof errOrMsg === "string" ? errOrMsg : _msg;
|
|
@@ -20546,7 +20560,23 @@ function systemError(errOrMsg, _msg) {
|
|
|
20546
20560
|
msg,
|
|
20547
20561
|
reqId,
|
|
20548
20562
|
type,
|
|
20549
|
-
...err && { err:
|
|
20563
|
+
...err && { err: serializeError(err) }
|
|
20564
|
+
}) + "\n"
|
|
20565
|
+
);
|
|
20566
|
+
}
|
|
20567
|
+
function applicationWarning(errOrMsg, _msg) {
|
|
20568
|
+
const err = typeof errOrMsg === "string" ? void 0 : errOrMsg;
|
|
20569
|
+
const msg = typeof errOrMsg === "string" ? errOrMsg : _msg;
|
|
20570
|
+
const reqId = getInvocationId();
|
|
20571
|
+
const type = getInvocationType() || "system";
|
|
20572
|
+
process.stdout.write(
|
|
20573
|
+
JSON.stringify({
|
|
20574
|
+
time: Date.now(),
|
|
20575
|
+
level: 40,
|
|
20576
|
+
reqId,
|
|
20577
|
+
type,
|
|
20578
|
+
msg,
|
|
20579
|
+
...err && { err: serializeError(err) }
|
|
20550
20580
|
}) + "\n"
|
|
20551
20581
|
);
|
|
20552
20582
|
}
|
|
@@ -34869,6 +34899,9 @@ var SystemData = class _SystemData {
|
|
|
34869
34899
|
};
|
|
34870
34900
|
var systemData = SystemData.create();
|
|
34871
34901
|
|
|
34902
|
+
// ../../lib/ampt-utilities/src/compression.ts
|
|
34903
|
+
var import_node_zlib = require("zlib");
|
|
34904
|
+
|
|
34872
34905
|
// ../../lib/events-core/parse-after.ts
|
|
34873
34906
|
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
34874
34907
|
var import_utc = __toESM(require_utc(), 1);
|
|
@@ -34893,6 +34926,7 @@ function parseAfter(after, base) {
|
|
|
34893
34926
|
try {
|
|
34894
34927
|
const [num, unit] = after.toLowerCase().split(" ");
|
|
34895
34928
|
if (!validUnit(unit, ["seconds", "minutes", "hours", "days", "weeks", "months", "years"])) {
|
|
34929
|
+
applicationWarning(`Warning: invalid unit "${unit}" in 'after' config parameter`);
|
|
34896
34930
|
return NaN;
|
|
34897
34931
|
}
|
|
34898
34932
|
return import_dayjs.default.utc(base).add(Number.parseInt(num), unit).valueOf();
|
|
@@ -44548,6 +44582,66 @@ var modelInfoMap = {
|
|
|
44548
44582
|
return (json?.inputTextTokenCount ?? 0) * 10;
|
|
44549
44583
|
}
|
|
44550
44584
|
},
|
|
44585
|
+
"amazon.titan-embed-text-v2:0": {
|
|
44586
|
+
name: "Amazon Titan Embeddings V2",
|
|
44587
|
+
type: "embeddings" /* Embeddings */,
|
|
44588
|
+
streaming: false,
|
|
44589
|
+
provider: "Amazon",
|
|
44590
|
+
description: "",
|
|
44591
|
+
version: "v2",
|
|
44592
|
+
inferenceUsage: (body) => {
|
|
44593
|
+
const json = JSON.parse(Buffer.from(body).toString());
|
|
44594
|
+
return (json?.inputTextTokenCount ?? 0) * 2;
|
|
44595
|
+
}
|
|
44596
|
+
},
|
|
44597
|
+
"amazon.titan-text-express-v1": {
|
|
44598
|
+
name: "Amazon Titan Text Express",
|
|
44599
|
+
type: "language" /* Language */,
|
|
44600
|
+
streaming: true,
|
|
44601
|
+
provider: "Amazon",
|
|
44602
|
+
description: "",
|
|
44603
|
+
version: "v1.x",
|
|
44604
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44605
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 20 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
44606
|
+
}
|
|
44607
|
+
},
|
|
44608
|
+
"amazon.titan-text-lite-v1": {
|
|
44609
|
+
name: "Amazon Titan Text Lite",
|
|
44610
|
+
type: "language" /* Language */,
|
|
44611
|
+
streaming: true,
|
|
44612
|
+
provider: "Amazon",
|
|
44613
|
+
description: "",
|
|
44614
|
+
version: "v1.x",
|
|
44615
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44616
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 15 + outputSize / AVERAGE_BYTES_PER_TOKEN * 20);
|
|
44617
|
+
}
|
|
44618
|
+
},
|
|
44619
|
+
"amazon.titan-text-premier-v1:0": {
|
|
44620
|
+
name: "Amazon Titan Text Premier",
|
|
44621
|
+
type: "language" /* Language */,
|
|
44622
|
+
streaming: true,
|
|
44623
|
+
provider: "Amazon",
|
|
44624
|
+
description: "",
|
|
44625
|
+
version: "v1.x",
|
|
44626
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44627
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 50 + outputSize / AVERAGE_BYTES_PER_TOKEN * 150);
|
|
44628
|
+
}
|
|
44629
|
+
},
|
|
44630
|
+
// WIP: Need to change the interface
|
|
44631
|
+
// 'amazon.titan-image-generator-v1': {
|
|
44632
|
+
// name: 'Amazon: Titan Image Generator G1',
|
|
44633
|
+
// type: ModelType.Image,
|
|
44634
|
+
// streaming: false,
|
|
44635
|
+
// provider: 'Amazon',
|
|
44636
|
+
// description:
|
|
44637
|
+
// '',
|
|
44638
|
+
// version: '1.x',
|
|
44639
|
+
// inferenceUsage: (width: number, height: number, steps: number) => {
|
|
44640
|
+
// const large = width * height > 512 * 512
|
|
44641
|
+
// const highQuality = steps > 50
|
|
44642
|
+
// return Math.round((large ? 3600000 : 1800000) * (highQuality ? 2 : 1))
|
|
44643
|
+
// }
|
|
44644
|
+
// },
|
|
44551
44645
|
"anthropic.claude-instant-v1": {
|
|
44552
44646
|
name: "Claude Instant",
|
|
44553
44647
|
type: "language" /* Language */,
|
|
@@ -44556,29 +44650,29 @@ var modelInfoMap = {
|
|
|
44556
44650
|
description: "A faster and cheaper yet still very capable model, which can handle a range of tasks including casual dialogue, text analysis, summarization, and document question-answering.",
|
|
44557
44651
|
version: "v1.2",
|
|
44558
44652
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44559
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
44653
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 80 + outputSize / AVERAGE_BYTES_PER_TOKEN * 240);
|
|
44560
44654
|
}
|
|
44561
44655
|
},
|
|
44562
|
-
"anthropic.claude-
|
|
44656
|
+
"anthropic.claude-v2": {
|
|
44563
44657
|
name: "Claude",
|
|
44564
44658
|
type: "language" /* Language */,
|
|
44565
44659
|
streaming: true,
|
|
44566
44660
|
provider: "Anthropic",
|
|
44567
|
-
description: "
|
|
44568
|
-
version: "
|
|
44661
|
+
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
44662
|
+
version: "v2.0",
|
|
44569
44663
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44570
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
44664
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
44571
44665
|
}
|
|
44572
44666
|
},
|
|
44573
|
-
"anthropic.claude-v2": {
|
|
44667
|
+
"anthropic.claude-v2:1": {
|
|
44574
44668
|
name: "Claude",
|
|
44575
44669
|
type: "language" /* Language */,
|
|
44576
44670
|
streaming: true,
|
|
44577
44671
|
provider: "Anthropic",
|
|
44578
44672
|
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
44579
|
-
version: "v2",
|
|
44673
|
+
version: "v2.1",
|
|
44580
44674
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44581
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
44675
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
44582
44676
|
}
|
|
44583
44677
|
},
|
|
44584
44678
|
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
@@ -44587,11 +44681,35 @@ var modelInfoMap = {
|
|
|
44587
44681
|
streaming: true,
|
|
44588
44682
|
provider: "Anthropic",
|
|
44589
44683
|
description: "",
|
|
44590
|
-
version: "v1",
|
|
44684
|
+
version: "v1.0",
|
|
44591
44685
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44592
44686
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 300 + outputSize / AVERAGE_BYTES_PER_TOKEN * 1500);
|
|
44593
44687
|
}
|
|
44594
44688
|
},
|
|
44689
|
+
"anthropic.claude-3-haiku-20240307-v1:0": {
|
|
44690
|
+
name: "Claude 3 Haiku",
|
|
44691
|
+
type: "language" /* Language */,
|
|
44692
|
+
streaming: true,
|
|
44693
|
+
provider: "Anthropic",
|
|
44694
|
+
description: "",
|
|
44695
|
+
version: "v1.0",
|
|
44696
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44697
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 25 + outputSize / AVERAGE_BYTES_PER_TOKEN * 125);
|
|
44698
|
+
}
|
|
44699
|
+
},
|
|
44700
|
+
"anthropic.claude-3-opus-20240229-v1:0": {
|
|
44701
|
+
name: "Claude 3 Opus",
|
|
44702
|
+
region: "us-west-2",
|
|
44703
|
+
// as of 5/10/2024, this is the only region that supports this model
|
|
44704
|
+
type: "language" /* Language */,
|
|
44705
|
+
streaming: true,
|
|
44706
|
+
provider: "Anthropic",
|
|
44707
|
+
description: "",
|
|
44708
|
+
version: "v1.0",
|
|
44709
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44710
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 1500 + outputSize / AVERAGE_BYTES_PER_TOKEN * 7500);
|
|
44711
|
+
}
|
|
44712
|
+
},
|
|
44595
44713
|
"cohere.command-text-v14": {
|
|
44596
44714
|
name: "Command",
|
|
44597
44715
|
type: "language" /* Language */,
|
|
@@ -44649,23 +44767,54 @@ var modelInfoMap = {
|
|
|
44649
44767
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 75 + outputSize / AVERAGE_BYTES_PER_TOKEN * 100);
|
|
44650
44768
|
}
|
|
44651
44769
|
},
|
|
44652
|
-
"
|
|
44770
|
+
"meta.llama2-70b-chat-v1": {
|
|
44771
|
+
name: "Meta Llama 2 Chat (70B)",
|
|
44772
|
+
type: "language" /* Language */,
|
|
44773
|
+
streaming: true,
|
|
44774
|
+
provider: "Meta",
|
|
44775
|
+
description: "",
|
|
44776
|
+
version: "v1",
|
|
44777
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44778
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 195 + outputSize / AVERAGE_BYTES_PER_TOKEN * 256);
|
|
44779
|
+
}
|
|
44780
|
+
},
|
|
44781
|
+
"meta.llama3-8b-instruct-v1:0": {
|
|
44782
|
+
name: "Meta Llama 3 Instruct (8B)",
|
|
44783
|
+
type: "language" /* Language */,
|
|
44784
|
+
streaming: true,
|
|
44785
|
+
provider: "Meta",
|
|
44786
|
+
description: "",
|
|
44787
|
+
version: "v1.x",
|
|
44788
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44789
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 40 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
44790
|
+
}
|
|
44791
|
+
},
|
|
44792
|
+
"meta.llama3-70b-instruct-v1:0": {
|
|
44793
|
+
name: "Meta Llama 3 Instruct (70B)",
|
|
44794
|
+
type: "language" /* Language */,
|
|
44795
|
+
streaming: true,
|
|
44796
|
+
provider: "Meta",
|
|
44797
|
+
description: "",
|
|
44798
|
+
version: "v1.x",
|
|
44799
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44800
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 265 + outputSize / AVERAGE_BYTES_PER_TOKEN * 350);
|
|
44801
|
+
}
|
|
44802
|
+
},
|
|
44803
|
+
"stability.stable-diffusion-xl-v1": {
|
|
44653
44804
|
name: "Stable Diffusion XL",
|
|
44654
44805
|
type: "image" /* Image */,
|
|
44655
44806
|
streaming: false,
|
|
44656
44807
|
provider: "Stability AI",
|
|
44657
44808
|
description: "Deep learning, text-to-image model used to generate detailed images conditioned on text descriptions, inpainting, outpainting, and generating image-to-image translations.",
|
|
44658
|
-
version: "
|
|
44809
|
+
version: "v1.x",
|
|
44659
44810
|
inferenceUsage: (width, height, steps) => {
|
|
44660
|
-
const large = width * height > 512 * 512;
|
|
44661
44811
|
const highQuality = steps > 50;
|
|
44662
|
-
return Math.round(
|
|
44812
|
+
return Math.round(4e6 * (highQuality ? 2 : 1));
|
|
44663
44813
|
}
|
|
44664
44814
|
},
|
|
44665
44815
|
"mistral.mistral-7b-instruct-v0:2": {
|
|
44666
44816
|
name: "Mistral Instruct (7B)",
|
|
44667
|
-
region:
|
|
44668
|
-
// at time of writing, this is the only region that supports this model
|
|
44817
|
+
// region: 'us-west-2',
|
|
44669
44818
|
type: "language" /* Language */,
|
|
44670
44819
|
streaming: true,
|
|
44671
44820
|
provider: "Mistral",
|
|
@@ -44677,8 +44826,7 @@ var modelInfoMap = {
|
|
|
44677
44826
|
},
|
|
44678
44827
|
"mistral.mixtral-8x7b-instruct-v0:1": {
|
|
44679
44828
|
name: "MixTral Instruct (8x7B)",
|
|
44680
|
-
region:
|
|
44681
|
-
// at time of writing, this is the only region that supports this model
|
|
44829
|
+
// region: 'us-west-2',
|
|
44682
44830
|
type: "language" /* Language */,
|
|
44683
44831
|
streaming: true,
|
|
44684
44832
|
provider: "Mistral",
|
|
@@ -44687,6 +44835,18 @@ var modelInfoMap = {
|
|
|
44687
44835
|
inferenceUsage: (inputSize, outputSize) => {
|
|
44688
44836
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 45 + outputSize / AVERAGE_BYTES_PER_TOKEN * 70);
|
|
44689
44837
|
}
|
|
44838
|
+
},
|
|
44839
|
+
"mistral.mistral-large-2402-v1:0": {
|
|
44840
|
+
name: "Mistral Large",
|
|
44841
|
+
// region: 'us-west-2',
|
|
44842
|
+
type: "language" /* Language */,
|
|
44843
|
+
streaming: true,
|
|
44844
|
+
provider: "Mistral",
|
|
44845
|
+
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
44846
|
+
version: "v0.1",
|
|
44847
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
44848
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
44849
|
+
}
|
|
44690
44850
|
}
|
|
44691
44851
|
};
|
|
44692
44852
|
function getModelInfo(id) {
|
|
@@ -44703,7 +44863,7 @@ function trackImageInference(width, height, steps, modelInfo) {
|
|
|
44703
44863
|
function trackEmbeddingsInference(result, modelInfo) {
|
|
44704
44864
|
telemetry_default.count("inferenceUsage", modelInfo.inferenceUsage(result), "ai");
|
|
44705
44865
|
}
|
|
44706
|
-
async function _invoke(options,
|
|
44866
|
+
async function _invoke(options, release5) {
|
|
44707
44867
|
const contentType = options.contentType ?? "application/json";
|
|
44708
44868
|
const accept = options.accept ?? "application/json";
|
|
44709
44869
|
const body = contentType === "application/json" ? JSON.stringify(options.body) : options.body;
|
|
@@ -44727,19 +44887,41 @@ async function _invoke(options, lock) {
|
|
|
44727
44887
|
const iterator = result.body[Symbol.asyncIterator]();
|
|
44728
44888
|
responseBody = new ReadableStream({
|
|
44729
44889
|
async pull(controller) {
|
|
44730
|
-
|
|
44731
|
-
|
|
44732
|
-
|
|
44733
|
-
|
|
44734
|
-
|
|
44735
|
-
|
|
44736
|
-
|
|
44737
|
-
|
|
44738
|
-
|
|
44739
|
-
|
|
44740
|
-
|
|
44890
|
+
let completed = false;
|
|
44891
|
+
try {
|
|
44892
|
+
const { value, done } = await iterator.next();
|
|
44893
|
+
if (done) {
|
|
44894
|
+
controller.close();
|
|
44895
|
+
completed = true;
|
|
44896
|
+
} else {
|
|
44897
|
+
if (!value.chunk?.bytes) {
|
|
44898
|
+
console.warn("Error in LLM response stream:", value);
|
|
44899
|
+
return;
|
|
44900
|
+
}
|
|
44901
|
+
if (modelInfo.type === "language" /* Language */) {
|
|
44902
|
+
trackLanguageInference(0, value.chunk.bytes.length, modelInfo);
|
|
44903
|
+
}
|
|
44904
|
+
controller.enqueue(value.chunk.bytes);
|
|
44741
44905
|
}
|
|
44742
|
-
|
|
44906
|
+
} catch (err) {
|
|
44907
|
+
controller.error(err);
|
|
44908
|
+
await release5();
|
|
44909
|
+
return;
|
|
44910
|
+
}
|
|
44911
|
+
if (completed) {
|
|
44912
|
+
await release5();
|
|
44913
|
+
}
|
|
44914
|
+
},
|
|
44915
|
+
async cancel() {
|
|
44916
|
+
const [releaseResult, cleanupResult] = await Promise.allSettled([
|
|
44917
|
+
release5(),
|
|
44918
|
+
Promise.resolve().then(() => iterator.return?.())
|
|
44919
|
+
]);
|
|
44920
|
+
if (releaseResult.status === "rejected") {
|
|
44921
|
+
throw releaseResult.reason;
|
|
44922
|
+
}
|
|
44923
|
+
if (cleanupResult.status === "rejected") {
|
|
44924
|
+
throw cleanupResult.reason;
|
|
44743
44925
|
}
|
|
44744
44926
|
}
|
|
44745
44927
|
});
|
|
@@ -44752,12 +44934,12 @@ async function _invoke(options, lock) {
|
|
|
44752
44934
|
trackEmbeddingsInference(result.body, modelInfo);
|
|
44753
44935
|
}
|
|
44754
44936
|
responseBody = new ReadableStream({
|
|
44755
|
-
|
|
44937
|
+
pull(controller) {
|
|
44756
44938
|
controller.enqueue(result.body);
|
|
44757
44939
|
controller.close();
|
|
44758
|
-
await releaseLock(lock);
|
|
44759
44940
|
}
|
|
44760
44941
|
});
|
|
44942
|
+
await release5();
|
|
44761
44943
|
} else {
|
|
44762
44944
|
throw new Error("Model returned an invalid response");
|
|
44763
44945
|
}
|
|
@@ -44771,10 +44953,12 @@ async function invoke2(options) {
|
|
|
44771
44953
|
if (!lock.acquired) {
|
|
44772
44954
|
throw new Error("Max concurrency reached");
|
|
44773
44955
|
}
|
|
44956
|
+
let releasePromise;
|
|
44957
|
+
const release5 = () => releasePromise ??= releaseLock(lock);
|
|
44774
44958
|
try {
|
|
44775
|
-
return await _invoke(options,
|
|
44959
|
+
return await _invoke(options, release5);
|
|
44776
44960
|
} catch (err) {
|
|
44777
|
-
await
|
|
44961
|
+
await release5();
|
|
44778
44962
|
throw err;
|
|
44779
44963
|
}
|
|
44780
44964
|
}
|
|
@@ -45043,16 +45227,21 @@ var ChatMessage = class {
|
|
|
45043
45227
|
};
|
|
45044
45228
|
var adapters = {
|
|
45045
45229
|
"anthropic.claude-instant-v1": AnthropicClaudeChatAdapter,
|
|
45046
|
-
"anthropic.claude-v1": AnthropicClaudeChatAdapter,
|
|
45047
45230
|
"anthropic.claude-v2": AnthropicClaudeChatAdapter,
|
|
45048
45231
|
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45232
|
+
"anthropic.claude-3-haiku-20240307-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45233
|
+
"anthropic.claude-3-opus-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
45049
45234
|
"ai21.j2-mid-v1": Ai21JurassicChatAdapter,
|
|
45050
45235
|
"ai21.j2-ultra-v1": Ai21JurassicChatAdapter,
|
|
45051
45236
|
"cohere.command-text-v14": CohereCommandChatAdapter,
|
|
45052
45237
|
"cohere.command-light-text-v14": CohereCommandChatAdapter,
|
|
45053
45238
|
"meta.llama2-13b-chat-v1": MetaLlamaChatAdapter,
|
|
45239
|
+
"meta.llama2-70b-chat-v1": MetaLlamaChatAdapter,
|
|
45240
|
+
"meta.llama3-8b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
45241
|
+
"meta.llama3-70b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
45054
45242
|
"mistral.mistral-7b-instruct-v0:2": MixtralAIChatAdapter,
|
|
45055
|
-
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter
|
|
45243
|
+
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter,
|
|
45244
|
+
"mistral.mistral-large-2402-v1:0": MixtralAIChatAdapter
|
|
45056
45245
|
};
|
|
45057
45246
|
async function chat(messages, options = {}) {
|
|
45058
45247
|
const modelId = options.modelId ?? "anthropic.claude-instant-v1";
|
|
@@ -45068,16 +45257,21 @@ async function chat(messages, options = {}) {
|
|
|
45068
45257
|
chat.models = async () => {
|
|
45069
45258
|
return [
|
|
45070
45259
|
"anthropic.claude-instant-v1",
|
|
45071
|
-
"anthropic.claude-v1",
|
|
45072
45260
|
"anthropic.claude-v2",
|
|
45073
45261
|
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
45262
|
+
"anthropic.claude-3-haiku-20240307-v1:0",
|
|
45263
|
+
"anthropic.claude-3-opus-20240229-v1:0",
|
|
45074
45264
|
"ai21.j2-mid-v1",
|
|
45075
45265
|
"ai21.j2-ultra-v1",
|
|
45076
45266
|
"cohere.command-text-v14",
|
|
45077
45267
|
"cohere.command-light-text-v14",
|
|
45078
45268
|
"meta.llama2-13b-chat-v1",
|
|
45269
|
+
"meta.llama2-70b-chat-v1",
|
|
45270
|
+
"meta.llama3-8b-instruct-v1:0",
|
|
45271
|
+
"meta.llama3-70b-instruct-v1:0",
|
|
45079
45272
|
"mistral.mistral-7b-instruct-v0:2",
|
|
45080
|
-
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
45273
|
+
"mistral.mixtral-8x7b-instruct-v0:1",
|
|
45274
|
+
"mistral.mistral-large-2402-v1:0"
|
|
45081
45275
|
];
|
|
45082
45276
|
};
|
|
45083
45277
|
|
|
@@ -45111,11 +45305,12 @@ var CohereEmbedAdapter = class {
|
|
|
45111
45305
|
// src/embed/index.ts
|
|
45112
45306
|
var adapters2 = {
|
|
45113
45307
|
"amazon.titan-embed-text-v1": AmazonTitanEmbedTextAdapter,
|
|
45308
|
+
"amazon.titan-embed-text-v2:0": AmazonTitanEmbedTextAdapter,
|
|
45114
45309
|
"cohere.embed-english-v3": CohereEmbedAdapter,
|
|
45115
45310
|
"cohere.embed-multilingual-v3": CohereEmbedAdapter
|
|
45116
45311
|
};
|
|
45117
45312
|
async function embed(input, options = {}) {
|
|
45118
|
-
const modelId = options.modelId ?? "amazon.titan-embed-text-
|
|
45313
|
+
const modelId = options.modelId ?? "amazon.titan-embed-text-v2:0";
|
|
45119
45314
|
const AdapterClass = adapters2[modelId];
|
|
45120
45315
|
if (!AdapterClass) {
|
|
45121
45316
|
throw new Error(`No adapter found for model ${modelId}`);
|
|
@@ -45131,7 +45326,7 @@ embed.models = async () => {
|
|
|
45131
45326
|
|
|
45132
45327
|
// src/render.ts
|
|
45133
45328
|
async function render(prompt, options = {}) {
|
|
45134
|
-
const modelId = options.modelId ?? "stability.stable-diffusion-xl-
|
|
45329
|
+
const modelId = options.modelId ?? "stability.stable-diffusion-xl-v1";
|
|
45135
45330
|
const body = {
|
|
45136
45331
|
text_prompts: [
|
|
45137
45332
|
{
|
|
@@ -45141,8 +45336,8 @@ async function render(prompt, options = {}) {
|
|
|
45141
45336
|
cfg_scale: options.scale ?? 10,
|
|
45142
45337
|
seed: options.seed ?? 20,
|
|
45143
45338
|
steps: options.steps ?? 50,
|
|
45144
|
-
width: options.width ??
|
|
45145
|
-
height: options.height ??
|
|
45339
|
+
width: options.width ?? 1024,
|
|
45340
|
+
height: options.height ?? 1024
|
|
45146
45341
|
};
|
|
45147
45342
|
const response = await invoke2({ body, modelId });
|
|
45148
45343
|
if (!response.body) {
|
|
@@ -45158,7 +45353,7 @@ async function render(prompt, options = {}) {
|
|
|
45158
45353
|
return new Response(responseBody, { headers: { "Content-Type": "image/png" } });
|
|
45159
45354
|
}
|
|
45160
45355
|
render.models = async () => {
|
|
45161
|
-
return ["stability.stable-diffusion-xl-
|
|
45356
|
+
return ["stability.stable-diffusion-xl-v1"];
|
|
45162
45357
|
};
|
|
45163
45358
|
|
|
45164
45359
|
// src/summarize/adapters/anthropic.claude.sonnet.ts
|
|
@@ -45264,7 +45459,7 @@ var MixtralAISummarizeAdapter = class {
|
|
|
45264
45459
|
// src/summarize/index.ts
|
|
45265
45460
|
var adapters3 = {
|
|
45266
45461
|
"anthropic.claude-instant-v1": AnthropicClaudeSummarizeAdapter,
|
|
45267
|
-
|
|
45462
|
+
// 'anthropic.claude-v1': AnthropicClaudeSummarizeAdapter,
|
|
45268
45463
|
"anthropic.claude-v2": AnthropicClaudeSummarizeAdapter,
|
|
45269
45464
|
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetSummarizeAdapter,
|
|
45270
45465
|
"mistral.mistral-7b-instruct-v0:2": MixtralAISummarizeAdapter,
|
|
@@ -45284,7 +45479,7 @@ async function summarize(input, options = {}) {
|
|
|
45284
45479
|
summarize.models = async () => {
|
|
45285
45480
|
return [
|
|
45286
45481
|
"anthropic.claude-instant-v1",
|
|
45287
|
-
|
|
45482
|
+
// 'anthropic.claude-v1',
|
|
45288
45483
|
"anthropic.claude-v2",
|
|
45289
45484
|
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
45290
45485
|
"mistral.mistral-7b-instruct-v0:2",
|
|
@@ -55492,7 +55687,7 @@ createAggregatedClient2(commands4, Translate);
|
|
|
55492
55687
|
// src/translate.ts
|
|
55493
55688
|
var region2 = process.env.AWS_REGION ?? "us-east-1";
|
|
55494
55689
|
var client = new Translate({ credentialDefaultProvider: credentialsProvider, region: region2 });
|
|
55495
|
-
async function _translate(input, options,
|
|
55690
|
+
async function _translate(input, options, release5) {
|
|
55496
55691
|
const auto = options.sourceLanguage === "auto";
|
|
55497
55692
|
const result = await client.translateText({
|
|
55498
55693
|
SourceLanguageCode: options.sourceLanguage,
|
|
@@ -55506,12 +55701,11 @@ async function _translate(input, options, lock) {
|
|
|
55506
55701
|
const comprehendUsage = auto ? Math.max(3e4, input.length * 100) : 0;
|
|
55507
55702
|
const translateUsage = input.length * 1500;
|
|
55508
55703
|
telemetry_default.count("inferenceUsage", comprehendUsage + translateUsage, "ai");
|
|
55509
|
-
|
|
55510
|
-
responseBody = new ReadableStream({
|
|
55511
|
-
|
|
55704
|
+
await release5();
|
|
55705
|
+
const responseBody = new ReadableStream({
|
|
55706
|
+
pull(controller) {
|
|
55512
55707
|
controller.enqueue(Buffer.from(translatedText, "utf8"));
|
|
55513
55708
|
controller.close();
|
|
55514
|
-
await releaseLock(lock);
|
|
55515
55709
|
}
|
|
55516
55710
|
});
|
|
55517
55711
|
return new Response(responseBody, {
|
|
@@ -55539,10 +55733,12 @@ async function translate(input, options) {
|
|
|
55539
55733
|
if (!lock.acquired) {
|
|
55540
55734
|
throw new Error("Max concurrency reached");
|
|
55541
55735
|
}
|
|
55736
|
+
let releasePromise;
|
|
55737
|
+
const release5 = () => releasePromise ??= releaseLock(lock);
|
|
55542
55738
|
try {
|
|
55543
|
-
return await _translate(input, options,
|
|
55739
|
+
return await _translate(input, options, release5);
|
|
55544
55740
|
} catch (err) {
|
|
55545
|
-
await
|
|
55741
|
+
await release5();
|
|
55546
55742
|
throw err;
|
|
55547
55743
|
}
|
|
55548
55744
|
}
|
|
@@ -55550,7 +55746,7 @@ async function translate(input, options) {
|
|
|
55550
55746
|
// src/index.ts
|
|
55551
55747
|
if (process.env.AMPT_RUNTIME_NAME === "nodejs18-beta") {
|
|
55552
55748
|
console.error(
|
|
55553
|
-
'@ampt/ai requires the nodejs18 runtime. Please add "runtime": "
|
|
55749
|
+
'@ampt/ai requires the nodejs18 runtime or higher. Please add "runtime": "nodejs20" to the "ampt" section of your package.json.'
|
|
55554
55750
|
);
|
|
55555
55751
|
}
|
|
55556
55752
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Translate } from '@aws-sdk/client-translate';
|
|
2
2
|
|
|
3
|
-
type ModelId = '
|
|
3
|
+
type ModelId = 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | 'amazon.titan-text-premier-v1:0' | 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-instant-v1' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'stability.stable-diffusion-xl-v1';
|
|
4
4
|
declare function models(): Promise<string[]>;
|
|
5
5
|
declare enum ModelType {
|
|
6
6
|
Embeddings = "embeddings",
|
|
@@ -42,64 +42,6 @@ type ModelInfoMap = {
|
|
|
42
42
|
* Note: we track usage in micro-cents/uc (1,000,000ths of a cent, or 100,000,000ths of a dollar) because
|
|
43
43
|
* the quota system only works with integers.
|
|
44
44
|
*
|
|
45
|
-
* AI21 Jurassic-2 Mid:
|
|
46
|
-
* - $0.0125 per 1000 input tokens: 1250 uc per token
|
|
47
|
-
* - $0.0125 per 1000 output tokens: 1250 uc per token
|
|
48
|
-
*
|
|
49
|
-
* AI21 Jurassic-2 Ultra:
|
|
50
|
-
* - $0.0188 per 1000 input tokens: 1880 uc per token
|
|
51
|
-
* - $0.0188 per 1000 output tokens: 1880 uc per token
|
|
52
|
-
*
|
|
53
|
-
* Claude Instant:
|
|
54
|
-
* - $0.00163 per 1000 input tokens: 163 uc per token
|
|
55
|
-
* - $0.00551 per 1000 output tokens: 551 uc per token
|
|
56
|
-
*
|
|
57
|
-
* Claude:
|
|
58
|
-
* - $0.01102 per 1000 input tokens: 1102 uc per token
|
|
59
|
-
* - $0.03268 per 1000 output tokens: 3268 uc per token
|
|
60
|
-
*
|
|
61
|
-
* Claude 3 Sonnet:
|
|
62
|
-
* - $0.00300 per 1000 input tokens: 300 uc per token
|
|
63
|
-
* - $0.01500 per 1000 output tokens: 1500 uc per token
|
|
64
|
-
*
|
|
65
|
-
* Cohere Command:
|
|
66
|
-
* - $0.0015 per 1000 input tokens: 150 uc per token
|
|
67
|
-
* - $0.0020 per 1000 output tokens: 200 uc per token
|
|
68
|
-
*
|
|
69
|
-
* Cohere Command Light:
|
|
70
|
-
* - $0.0003 per 1000 input tokens: 30 uc per token
|
|
71
|
-
* - $0.0006 per 1000 output tokens: 60 uc per token
|
|
72
|
-
*
|
|
73
|
-
* Cohere Embed - English:
|
|
74
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
75
|
-
*
|
|
76
|
-
* Cohere Embed - Multilingual:
|
|
77
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
78
|
-
*
|
|
79
|
-
* Meta Llama 2 Chat (13B):
|
|
80
|
-
* - $0.00075 per 1000 input tokens: 75 uc per token
|
|
81
|
-
* - $0.001 per 1000 output tokens: 100 uc per token
|
|
82
|
-
*
|
|
83
|
-
* Mistral 7B:
|
|
84
|
-
* - $.00015 per 1000 input tokens: 15 uc per token
|
|
85
|
-
* - $.0002 per 1000 output tokens: 20 uc per token
|
|
86
|
-
*
|
|
87
|
-
* MixTral 8x7B:
|
|
88
|
-
* - $0.00045 per 1000 input tokens: 45 uc per token
|
|
89
|
-
* - $0.0007 per 1000 output tokens: 70 uc per token
|
|
90
|
-
*
|
|
91
|
-
* Stable Diffusion XL:
|
|
92
|
-
*
|
|
93
|
-
* small format (512x512 or smaller):
|
|
94
|
-
* - standard quality: 1800000 per image
|
|
95
|
-
* - high quality: 3600000 per image
|
|
96
|
-
*
|
|
97
|
-
* large format (larger than 512x512):
|
|
98
|
-
* - standard quality: 3600000 per image (2x more expensive than small format)
|
|
99
|
-
* - high quality: 7200000 per image (2x more expensive than small format)
|
|
100
|
-
*
|
|
101
|
-
* Amazon Titan Embeddings:
|
|
102
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
103
45
|
*/
|
|
104
46
|
declare const modelInfoMap: ModelInfoMap;
|
|
105
47
|
declare function getModelInfo(id: ModelId): EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
|
|
@@ -138,7 +80,7 @@ interface ChatOptions {
|
|
|
138
80
|
modelId?: ChatModelId;
|
|
139
81
|
maxTokens?: number;
|
|
140
82
|
}
|
|
141
|
-
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-
|
|
83
|
+
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0';
|
|
142
84
|
/**
|
|
143
85
|
* Send messages to the model and return the completion
|
|
144
86
|
* @param messages Array of messages to send to the model
|
|
@@ -149,7 +91,7 @@ declare namespace chat {
|
|
|
149
91
|
var models: () => Promise<ModelId[]>;
|
|
150
92
|
}
|
|
151
93
|
|
|
152
|
-
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
94
|
+
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
153
95
|
type Embedding = number[];
|
|
154
96
|
interface EmbedOptions {
|
|
155
97
|
modelId?: EmbedModelId;
|
|
@@ -176,7 +118,7 @@ interface SummarizeOptions {
|
|
|
176
118
|
modelId?: SummarizeModelId;
|
|
177
119
|
maxTokens?: number;
|
|
178
120
|
}
|
|
179
|
-
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-
|
|
121
|
+
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
180
122
|
declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
|
|
181
123
|
declare namespace summarize {
|
|
182
124
|
var models: () => Promise<ModelId[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Translate } from '@aws-sdk/client-translate';
|
|
2
2
|
|
|
3
|
-
type ModelId = '
|
|
3
|
+
type ModelId = 'amazon.titan-text-express-v1' | 'amazon.titan-text-lite-v1' | 'amazon.titan-text-premier-v1:0' | 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'anthropic.claude-v2' | 'anthropic.claude-v2:1' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'anthropic.claude-instant-v1' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0' | 'stability.stable-diffusion-xl-v1';
|
|
4
4
|
declare function models(): Promise<string[]>;
|
|
5
5
|
declare enum ModelType {
|
|
6
6
|
Embeddings = "embeddings",
|
|
@@ -42,64 +42,6 @@ type ModelInfoMap = {
|
|
|
42
42
|
* Note: we track usage in micro-cents/uc (1,000,000ths of a cent, or 100,000,000ths of a dollar) because
|
|
43
43
|
* the quota system only works with integers.
|
|
44
44
|
*
|
|
45
|
-
* AI21 Jurassic-2 Mid:
|
|
46
|
-
* - $0.0125 per 1000 input tokens: 1250 uc per token
|
|
47
|
-
* - $0.0125 per 1000 output tokens: 1250 uc per token
|
|
48
|
-
*
|
|
49
|
-
* AI21 Jurassic-2 Ultra:
|
|
50
|
-
* - $0.0188 per 1000 input tokens: 1880 uc per token
|
|
51
|
-
* - $0.0188 per 1000 output tokens: 1880 uc per token
|
|
52
|
-
*
|
|
53
|
-
* Claude Instant:
|
|
54
|
-
* - $0.00163 per 1000 input tokens: 163 uc per token
|
|
55
|
-
* - $0.00551 per 1000 output tokens: 551 uc per token
|
|
56
|
-
*
|
|
57
|
-
* Claude:
|
|
58
|
-
* - $0.01102 per 1000 input tokens: 1102 uc per token
|
|
59
|
-
* - $0.03268 per 1000 output tokens: 3268 uc per token
|
|
60
|
-
*
|
|
61
|
-
* Claude 3 Sonnet:
|
|
62
|
-
* - $0.00300 per 1000 input tokens: 300 uc per token
|
|
63
|
-
* - $0.01500 per 1000 output tokens: 1500 uc per token
|
|
64
|
-
*
|
|
65
|
-
* Cohere Command:
|
|
66
|
-
* - $0.0015 per 1000 input tokens: 150 uc per token
|
|
67
|
-
* - $0.0020 per 1000 output tokens: 200 uc per token
|
|
68
|
-
*
|
|
69
|
-
* Cohere Command Light:
|
|
70
|
-
* - $0.0003 per 1000 input tokens: 30 uc per token
|
|
71
|
-
* - $0.0006 per 1000 output tokens: 60 uc per token
|
|
72
|
-
*
|
|
73
|
-
* Cohere Embed - English:
|
|
74
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
75
|
-
*
|
|
76
|
-
* Cohere Embed - Multilingual:
|
|
77
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
78
|
-
*
|
|
79
|
-
* Meta Llama 2 Chat (13B):
|
|
80
|
-
* - $0.00075 per 1000 input tokens: 75 uc per token
|
|
81
|
-
* - $0.001 per 1000 output tokens: 100 uc per token
|
|
82
|
-
*
|
|
83
|
-
* Mistral 7B:
|
|
84
|
-
* - $.00015 per 1000 input tokens: 15 uc per token
|
|
85
|
-
* - $.0002 per 1000 output tokens: 20 uc per token
|
|
86
|
-
*
|
|
87
|
-
* MixTral 8x7B:
|
|
88
|
-
* - $0.00045 per 1000 input tokens: 45 uc per token
|
|
89
|
-
* - $0.0007 per 1000 output tokens: 70 uc per token
|
|
90
|
-
*
|
|
91
|
-
* Stable Diffusion XL:
|
|
92
|
-
*
|
|
93
|
-
* small format (512x512 or smaller):
|
|
94
|
-
* - standard quality: 1800000 per image
|
|
95
|
-
* - high quality: 3600000 per image
|
|
96
|
-
*
|
|
97
|
-
* large format (larger than 512x512):
|
|
98
|
-
* - standard quality: 3600000 per image (2x more expensive than small format)
|
|
99
|
-
* - high quality: 7200000 per image (2x more expensive than small format)
|
|
100
|
-
*
|
|
101
|
-
* Amazon Titan Embeddings:
|
|
102
|
-
* - $0.0001 for 1000 input tokens: 10 uc per token
|
|
103
45
|
*/
|
|
104
46
|
declare const modelInfoMap: ModelInfoMap;
|
|
105
47
|
declare function getModelInfo(id: ModelId): EmbeddingsModelInfo | LanguageModelInfo | ImageModelInfo;
|
|
@@ -138,7 +80,7 @@ interface ChatOptions {
|
|
|
138
80
|
modelId?: ChatModelId;
|
|
139
81
|
maxTokens?: number;
|
|
140
82
|
}
|
|
141
|
-
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v1' | 'anthropic.claude-
|
|
83
|
+
type ChatModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'anthropic.claude-3-haiku-20240307-v1:0' | 'anthropic.claude-3-opus-20240229-v1:0' | 'ai21.j2-mid-v1' | 'ai21.j2-ultra-v1' | 'cohere.command-text-v14' | 'cohere.command-light-text-v14' | 'meta.llama2-13b-chat-v1' | 'meta.llama2-70b-chat-v1' | 'meta.llama3-8b-instruct-v1:0' | 'meta.llama3-70b-instruct-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1' | 'mistral.mistral-large-2402-v1:0';
|
|
142
84
|
/**
|
|
143
85
|
* Send messages to the model and return the completion
|
|
144
86
|
* @param messages Array of messages to send to the model
|
|
@@ -149,7 +91,7 @@ declare namespace chat {
|
|
|
149
91
|
var models: () => Promise<ModelId[]>;
|
|
150
92
|
}
|
|
151
93
|
|
|
152
|
-
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
94
|
+
type EmbedModelId = 'amazon.titan-embed-text-v1' | 'amazon.titan-embed-text-v2:0' | 'cohere.embed-english-v3' | 'cohere.embed-multilingual-v3';
|
|
153
95
|
type Embedding = number[];
|
|
154
96
|
interface EmbedOptions {
|
|
155
97
|
modelId?: EmbedModelId;
|
|
@@ -176,7 +118,7 @@ interface SummarizeOptions {
|
|
|
176
118
|
modelId?: SummarizeModelId;
|
|
177
119
|
maxTokens?: number;
|
|
178
120
|
}
|
|
179
|
-
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-
|
|
121
|
+
type SummarizeModelId = 'anthropic.claude-instant-v1' | 'anthropic.claude-v2' | 'anthropic.claude-3-sonnet-20240229-v1:0' | 'mistral.mistral-7b-instruct-v0:2' | 'mistral.mixtral-8x7b-instruct-v0:1';
|
|
180
122
|
declare function summarize(input: string, options?: SummarizeOptions): Promise<Response>;
|
|
181
123
|
declare namespace summarize {
|
|
182
124
|
var models: () => Promise<ModelId[]>;
|
package/dist/index.js
CHANGED
|
@@ -7125,7 +7125,7 @@ function request(url, options) {
|
|
|
7125
7125
|
resolve(result);
|
|
7126
7126
|
}
|
|
7127
7127
|
};
|
|
7128
|
-
const req = https.request(url, { agent }, (res) => {
|
|
7128
|
+
const req = https.request(url, { agent, headers: options.headers }, (res) => {
|
|
7129
7129
|
const bufs = [];
|
|
7130
7130
|
res.on("data", (data) => bufs.push(data));
|
|
7131
7131
|
res.on("end", () => {
|
|
@@ -7147,8 +7147,10 @@ var ALLOW = 0;
|
|
|
7147
7147
|
var QuotaReader = class {
|
|
7148
7148
|
url;
|
|
7149
7149
|
baseKey;
|
|
7150
|
+
invokeQuotasEnabled;
|
|
7150
7151
|
constructor(params) {
|
|
7151
7152
|
if (params.url && params.token && params.cacheName) {
|
|
7153
|
+
this.invokeQuotasEnabled = params.invokeQuotasEnabled;
|
|
7152
7154
|
this.url = `${params.url}/cache/${params.cacheName}?token=${params.token}&key={KEY}`;
|
|
7153
7155
|
this.baseKey = params.key;
|
|
7154
7156
|
}
|
|
@@ -7180,6 +7182,9 @@ var QuotaReader = class {
|
|
|
7180
7182
|
if (!quotaReader) {
|
|
7181
7183
|
return 0 /* ALLOW */;
|
|
7182
7184
|
}
|
|
7185
|
+
if (!quotaReader.invokeQuotasEnabled && type === "invocations" /* INVOCATIONS */) {
|
|
7186
|
+
return 0 /* ALLOW */;
|
|
7187
|
+
}
|
|
7183
7188
|
return await quotaReader.getThrottleState(type);
|
|
7184
7189
|
}
|
|
7185
7190
|
};
|
|
@@ -7462,6 +7467,15 @@ function guessServiceRegion(url, headers) {
|
|
|
7462
7467
|
}
|
|
7463
7468
|
|
|
7464
7469
|
// ../../lib/runtime-logging/index.ts
|
|
7470
|
+
function serializeError(err) {
|
|
7471
|
+
return {
|
|
7472
|
+
message: err.message,
|
|
7473
|
+
stack: err.stack,
|
|
7474
|
+
code: err.code,
|
|
7475
|
+
name: err.name,
|
|
7476
|
+
...err.cause && { cause: serializeError(err.cause) }
|
|
7477
|
+
};
|
|
7478
|
+
}
|
|
7465
7479
|
function systemError(errOrMsg, _msg) {
|
|
7466
7480
|
const err = typeof errOrMsg === "string" ? void 0 : errOrMsg;
|
|
7467
7481
|
const msg = typeof errOrMsg === "string" ? errOrMsg : _msg;
|
|
@@ -7475,7 +7489,23 @@ function systemError(errOrMsg, _msg) {
|
|
|
7475
7489
|
msg,
|
|
7476
7490
|
reqId,
|
|
7477
7491
|
type,
|
|
7478
|
-
...err && { err:
|
|
7492
|
+
...err && { err: serializeError(err) }
|
|
7493
|
+
}) + "\n"
|
|
7494
|
+
);
|
|
7495
|
+
}
|
|
7496
|
+
function applicationWarning(errOrMsg, _msg) {
|
|
7497
|
+
const err = typeof errOrMsg === "string" ? void 0 : errOrMsg;
|
|
7498
|
+
const msg = typeof errOrMsg === "string" ? errOrMsg : _msg;
|
|
7499
|
+
const reqId = getInvocationId();
|
|
7500
|
+
const type = getInvocationType() || "system";
|
|
7501
|
+
process.stdout.write(
|
|
7502
|
+
JSON.stringify({
|
|
7503
|
+
time: Date.now(),
|
|
7504
|
+
level: 40,
|
|
7505
|
+
reqId,
|
|
7506
|
+
type,
|
|
7507
|
+
msg,
|
|
7508
|
+
...err && { err: serializeError(err) }
|
|
7479
7509
|
}) + "\n"
|
|
7480
7510
|
);
|
|
7481
7511
|
}
|
|
@@ -21712,6 +21742,7 @@ function parseAfter(after, base) {
|
|
|
21712
21742
|
try {
|
|
21713
21743
|
const [num, unit] = after.toLowerCase().split(" ");
|
|
21714
21744
|
if (!validUnit(unit, ["seconds", "minutes", "hours", "days", "weeks", "months", "years"])) {
|
|
21745
|
+
applicationWarning(`Warning: invalid unit "${unit}" in 'after' config parameter`);
|
|
21715
21746
|
return NaN;
|
|
21716
21747
|
}
|
|
21717
21748
|
return import_dayjs.default.utc(base).add(Number.parseInt(num), unit).valueOf();
|
|
@@ -31366,6 +31397,66 @@ var modelInfoMap = {
|
|
|
31366
31397
|
return (json?.inputTextTokenCount ?? 0) * 10;
|
|
31367
31398
|
}
|
|
31368
31399
|
},
|
|
31400
|
+
"amazon.titan-embed-text-v2:0": {
|
|
31401
|
+
name: "Amazon Titan Embeddings V2",
|
|
31402
|
+
type: "embeddings" /* Embeddings */,
|
|
31403
|
+
streaming: false,
|
|
31404
|
+
provider: "Amazon",
|
|
31405
|
+
description: "",
|
|
31406
|
+
version: "v2",
|
|
31407
|
+
inferenceUsage: (body) => {
|
|
31408
|
+
const json = JSON.parse(Buffer.from(body).toString());
|
|
31409
|
+
return (json?.inputTextTokenCount ?? 0) * 2;
|
|
31410
|
+
}
|
|
31411
|
+
},
|
|
31412
|
+
"amazon.titan-text-express-v1": {
|
|
31413
|
+
name: "Amazon Titan Text Express",
|
|
31414
|
+
type: "language" /* Language */,
|
|
31415
|
+
streaming: true,
|
|
31416
|
+
provider: "Amazon",
|
|
31417
|
+
description: "",
|
|
31418
|
+
version: "v1.x",
|
|
31419
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31420
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 20 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
31421
|
+
}
|
|
31422
|
+
},
|
|
31423
|
+
"amazon.titan-text-lite-v1": {
|
|
31424
|
+
name: "Amazon Titan Text Lite",
|
|
31425
|
+
type: "language" /* Language */,
|
|
31426
|
+
streaming: true,
|
|
31427
|
+
provider: "Amazon",
|
|
31428
|
+
description: "",
|
|
31429
|
+
version: "v1.x",
|
|
31430
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31431
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 15 + outputSize / AVERAGE_BYTES_PER_TOKEN * 20);
|
|
31432
|
+
}
|
|
31433
|
+
},
|
|
31434
|
+
"amazon.titan-text-premier-v1:0": {
|
|
31435
|
+
name: "Amazon Titan Text Premier",
|
|
31436
|
+
type: "language" /* Language */,
|
|
31437
|
+
streaming: true,
|
|
31438
|
+
provider: "Amazon",
|
|
31439
|
+
description: "",
|
|
31440
|
+
version: "v1.x",
|
|
31441
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31442
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 50 + outputSize / AVERAGE_BYTES_PER_TOKEN * 150);
|
|
31443
|
+
}
|
|
31444
|
+
},
|
|
31445
|
+
// WIP: Need to change the interface
|
|
31446
|
+
// 'amazon.titan-image-generator-v1': {
|
|
31447
|
+
// name: 'Amazon: Titan Image Generator G1',
|
|
31448
|
+
// type: ModelType.Image,
|
|
31449
|
+
// streaming: false,
|
|
31450
|
+
// provider: 'Amazon',
|
|
31451
|
+
// description:
|
|
31452
|
+
// '',
|
|
31453
|
+
// version: '1.x',
|
|
31454
|
+
// inferenceUsage: (width: number, height: number, steps: number) => {
|
|
31455
|
+
// const large = width * height > 512 * 512
|
|
31456
|
+
// const highQuality = steps > 50
|
|
31457
|
+
// return Math.round((large ? 3600000 : 1800000) * (highQuality ? 2 : 1))
|
|
31458
|
+
// }
|
|
31459
|
+
// },
|
|
31369
31460
|
"anthropic.claude-instant-v1": {
|
|
31370
31461
|
name: "Claude Instant",
|
|
31371
31462
|
type: "language" /* Language */,
|
|
@@ -31374,29 +31465,29 @@ var modelInfoMap = {
|
|
|
31374
31465
|
description: "A faster and cheaper yet still very capable model, which can handle a range of tasks including casual dialogue, text analysis, summarization, and document question-answering.",
|
|
31375
31466
|
version: "v1.2",
|
|
31376
31467
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31377
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
31468
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 80 + outputSize / AVERAGE_BYTES_PER_TOKEN * 240);
|
|
31378
31469
|
}
|
|
31379
31470
|
},
|
|
31380
|
-
"anthropic.claude-
|
|
31471
|
+
"anthropic.claude-v2": {
|
|
31381
31472
|
name: "Claude",
|
|
31382
31473
|
type: "language" /* Language */,
|
|
31383
31474
|
streaming: true,
|
|
31384
31475
|
provider: "Anthropic",
|
|
31385
|
-
description: "
|
|
31386
|
-
version: "
|
|
31476
|
+
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
31477
|
+
version: "v2.0",
|
|
31387
31478
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31388
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
31479
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
31389
31480
|
}
|
|
31390
31481
|
},
|
|
31391
|
-
"anthropic.claude-v2": {
|
|
31482
|
+
"anthropic.claude-v2:1": {
|
|
31392
31483
|
name: "Claude",
|
|
31393
31484
|
type: "language" /* Language */,
|
|
31394
31485
|
streaming: true,
|
|
31395
31486
|
provider: "Anthropic",
|
|
31396
31487
|
description: "Anthropic's most powerful model, which excels at a wide range of tasks from sophisticated dialogue and creative content generation to detailed instruction following.",
|
|
31397
|
-
version: "v2",
|
|
31488
|
+
version: "v2.1",
|
|
31398
31489
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31399
|
-
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN *
|
|
31490
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
31400
31491
|
}
|
|
31401
31492
|
},
|
|
31402
31493
|
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
@@ -31405,11 +31496,35 @@ var modelInfoMap = {
|
|
|
31405
31496
|
streaming: true,
|
|
31406
31497
|
provider: "Anthropic",
|
|
31407
31498
|
description: "",
|
|
31408
|
-
version: "v1",
|
|
31499
|
+
version: "v1.0",
|
|
31409
31500
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31410
31501
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 300 + outputSize / AVERAGE_BYTES_PER_TOKEN * 1500);
|
|
31411
31502
|
}
|
|
31412
31503
|
},
|
|
31504
|
+
"anthropic.claude-3-haiku-20240307-v1:0": {
|
|
31505
|
+
name: "Claude 3 Haiku",
|
|
31506
|
+
type: "language" /* Language */,
|
|
31507
|
+
streaming: true,
|
|
31508
|
+
provider: "Anthropic",
|
|
31509
|
+
description: "",
|
|
31510
|
+
version: "v1.0",
|
|
31511
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31512
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 25 + outputSize / AVERAGE_BYTES_PER_TOKEN * 125);
|
|
31513
|
+
}
|
|
31514
|
+
},
|
|
31515
|
+
"anthropic.claude-3-opus-20240229-v1:0": {
|
|
31516
|
+
name: "Claude 3 Opus",
|
|
31517
|
+
region: "us-west-2",
|
|
31518
|
+
// as of 5/10/2024, this is the only region that supports this model
|
|
31519
|
+
type: "language" /* Language */,
|
|
31520
|
+
streaming: true,
|
|
31521
|
+
provider: "Anthropic",
|
|
31522
|
+
description: "",
|
|
31523
|
+
version: "v1.0",
|
|
31524
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31525
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 1500 + outputSize / AVERAGE_BYTES_PER_TOKEN * 7500);
|
|
31526
|
+
}
|
|
31527
|
+
},
|
|
31413
31528
|
"cohere.command-text-v14": {
|
|
31414
31529
|
name: "Command",
|
|
31415
31530
|
type: "language" /* Language */,
|
|
@@ -31467,23 +31582,54 @@ var modelInfoMap = {
|
|
|
31467
31582
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 75 + outputSize / AVERAGE_BYTES_PER_TOKEN * 100);
|
|
31468
31583
|
}
|
|
31469
31584
|
},
|
|
31470
|
-
"
|
|
31585
|
+
"meta.llama2-70b-chat-v1": {
|
|
31586
|
+
name: "Meta Llama 2 Chat (70B)",
|
|
31587
|
+
type: "language" /* Language */,
|
|
31588
|
+
streaming: true,
|
|
31589
|
+
provider: "Meta",
|
|
31590
|
+
description: "",
|
|
31591
|
+
version: "v1",
|
|
31592
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31593
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 195 + outputSize / AVERAGE_BYTES_PER_TOKEN * 256);
|
|
31594
|
+
}
|
|
31595
|
+
},
|
|
31596
|
+
"meta.llama3-8b-instruct-v1:0": {
|
|
31597
|
+
name: "Meta Llama 3 Instruct (8B)",
|
|
31598
|
+
type: "language" /* Language */,
|
|
31599
|
+
streaming: true,
|
|
31600
|
+
provider: "Meta",
|
|
31601
|
+
description: "",
|
|
31602
|
+
version: "v1.x",
|
|
31603
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31604
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 40 + outputSize / AVERAGE_BYTES_PER_TOKEN * 60);
|
|
31605
|
+
}
|
|
31606
|
+
},
|
|
31607
|
+
"meta.llama3-70b-instruct-v1:0": {
|
|
31608
|
+
name: "Meta Llama 3 Instruct (70B)",
|
|
31609
|
+
type: "language" /* Language */,
|
|
31610
|
+
streaming: true,
|
|
31611
|
+
provider: "Meta",
|
|
31612
|
+
description: "",
|
|
31613
|
+
version: "v1.x",
|
|
31614
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31615
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 265 + outputSize / AVERAGE_BYTES_PER_TOKEN * 350);
|
|
31616
|
+
}
|
|
31617
|
+
},
|
|
31618
|
+
"stability.stable-diffusion-xl-v1": {
|
|
31471
31619
|
name: "Stable Diffusion XL",
|
|
31472
31620
|
type: "image" /* Image */,
|
|
31473
31621
|
streaming: false,
|
|
31474
31622
|
provider: "Stability AI",
|
|
31475
31623
|
description: "Deep learning, text-to-image model used to generate detailed images conditioned on text descriptions, inpainting, outpainting, and generating image-to-image translations.",
|
|
31476
|
-
version: "
|
|
31624
|
+
version: "v1.x",
|
|
31477
31625
|
inferenceUsage: (width, height, steps) => {
|
|
31478
|
-
const large = width * height > 512 * 512;
|
|
31479
31626
|
const highQuality = steps > 50;
|
|
31480
|
-
return Math.round(
|
|
31627
|
+
return Math.round(4e6 * (highQuality ? 2 : 1));
|
|
31481
31628
|
}
|
|
31482
31629
|
},
|
|
31483
31630
|
"mistral.mistral-7b-instruct-v0:2": {
|
|
31484
31631
|
name: "Mistral Instruct (7B)",
|
|
31485
|
-
region:
|
|
31486
|
-
// at time of writing, this is the only region that supports this model
|
|
31632
|
+
// region: 'us-west-2',
|
|
31487
31633
|
type: "language" /* Language */,
|
|
31488
31634
|
streaming: true,
|
|
31489
31635
|
provider: "Mistral",
|
|
@@ -31495,8 +31641,7 @@ var modelInfoMap = {
|
|
|
31495
31641
|
},
|
|
31496
31642
|
"mistral.mixtral-8x7b-instruct-v0:1": {
|
|
31497
31643
|
name: "MixTral Instruct (8x7B)",
|
|
31498
|
-
region:
|
|
31499
|
-
// at time of writing, this is the only region that supports this model
|
|
31644
|
+
// region: 'us-west-2',
|
|
31500
31645
|
type: "language" /* Language */,
|
|
31501
31646
|
streaming: true,
|
|
31502
31647
|
provider: "Mistral",
|
|
@@ -31505,6 +31650,18 @@ var modelInfoMap = {
|
|
|
31505
31650
|
inferenceUsage: (inputSize, outputSize) => {
|
|
31506
31651
|
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 45 + outputSize / AVERAGE_BYTES_PER_TOKEN * 70);
|
|
31507
31652
|
}
|
|
31653
|
+
},
|
|
31654
|
+
"mistral.mistral-large-2402-v1:0": {
|
|
31655
|
+
name: "Mistral Large",
|
|
31656
|
+
// region: 'us-west-2',
|
|
31657
|
+
type: "language" /* Language */,
|
|
31658
|
+
streaming: true,
|
|
31659
|
+
provider: "Mistral",
|
|
31660
|
+
description: "Ideal for text summarization, question and answering, text classification, text completion, and code generation.",
|
|
31661
|
+
version: "v0.1",
|
|
31662
|
+
inferenceUsage: (inputSize, outputSize) => {
|
|
31663
|
+
return Math.round(inputSize / AVERAGE_BYTES_PER_TOKEN * 800 + outputSize / AVERAGE_BYTES_PER_TOKEN * 2400);
|
|
31664
|
+
}
|
|
31508
31665
|
}
|
|
31509
31666
|
};
|
|
31510
31667
|
function getModelInfo(id) {
|
|
@@ -31521,7 +31678,7 @@ function trackImageInference(width, height, steps, modelInfo) {
|
|
|
31521
31678
|
function trackEmbeddingsInference(result, modelInfo) {
|
|
31522
31679
|
telemetry_default.count("inferenceUsage", modelInfo.inferenceUsage(result), "ai");
|
|
31523
31680
|
}
|
|
31524
|
-
async function _invoke(options,
|
|
31681
|
+
async function _invoke(options, release4) {
|
|
31525
31682
|
const contentType = options.contentType ?? "application/json";
|
|
31526
31683
|
const accept = options.accept ?? "application/json";
|
|
31527
31684
|
const body = contentType === "application/json" ? JSON.stringify(options.body) : options.body;
|
|
@@ -31545,19 +31702,41 @@ async function _invoke(options, lock) {
|
|
|
31545
31702
|
const iterator = result.body[Symbol.asyncIterator]();
|
|
31546
31703
|
responseBody = new ReadableStream({
|
|
31547
31704
|
async pull(controller) {
|
|
31548
|
-
|
|
31549
|
-
|
|
31550
|
-
|
|
31551
|
-
|
|
31552
|
-
|
|
31553
|
-
|
|
31554
|
-
|
|
31555
|
-
|
|
31556
|
-
|
|
31557
|
-
|
|
31558
|
-
|
|
31705
|
+
let completed = false;
|
|
31706
|
+
try {
|
|
31707
|
+
const { value, done } = await iterator.next();
|
|
31708
|
+
if (done) {
|
|
31709
|
+
controller.close();
|
|
31710
|
+
completed = true;
|
|
31711
|
+
} else {
|
|
31712
|
+
if (!value.chunk?.bytes) {
|
|
31713
|
+
console.warn("Error in LLM response stream:", value);
|
|
31714
|
+
return;
|
|
31715
|
+
}
|
|
31716
|
+
if (modelInfo.type === "language" /* Language */) {
|
|
31717
|
+
trackLanguageInference(0, value.chunk.bytes.length, modelInfo);
|
|
31718
|
+
}
|
|
31719
|
+
controller.enqueue(value.chunk.bytes);
|
|
31559
31720
|
}
|
|
31560
|
-
|
|
31721
|
+
} catch (err) {
|
|
31722
|
+
controller.error(err);
|
|
31723
|
+
await release4();
|
|
31724
|
+
return;
|
|
31725
|
+
}
|
|
31726
|
+
if (completed) {
|
|
31727
|
+
await release4();
|
|
31728
|
+
}
|
|
31729
|
+
},
|
|
31730
|
+
async cancel() {
|
|
31731
|
+
const [releaseResult, cleanupResult] = await Promise.allSettled([
|
|
31732
|
+
release4(),
|
|
31733
|
+
Promise.resolve().then(() => iterator.return?.())
|
|
31734
|
+
]);
|
|
31735
|
+
if (releaseResult.status === "rejected") {
|
|
31736
|
+
throw releaseResult.reason;
|
|
31737
|
+
}
|
|
31738
|
+
if (cleanupResult.status === "rejected") {
|
|
31739
|
+
throw cleanupResult.reason;
|
|
31561
31740
|
}
|
|
31562
31741
|
}
|
|
31563
31742
|
});
|
|
@@ -31570,12 +31749,12 @@ async function _invoke(options, lock) {
|
|
|
31570
31749
|
trackEmbeddingsInference(result.body, modelInfo);
|
|
31571
31750
|
}
|
|
31572
31751
|
responseBody = new ReadableStream({
|
|
31573
|
-
|
|
31752
|
+
pull(controller) {
|
|
31574
31753
|
controller.enqueue(result.body);
|
|
31575
31754
|
controller.close();
|
|
31576
|
-
await releaseLock(lock);
|
|
31577
31755
|
}
|
|
31578
31756
|
});
|
|
31757
|
+
await release4();
|
|
31579
31758
|
} else {
|
|
31580
31759
|
throw new Error("Model returned an invalid response");
|
|
31581
31760
|
}
|
|
@@ -31589,10 +31768,12 @@ async function invoke2(options) {
|
|
|
31589
31768
|
if (!lock.acquired) {
|
|
31590
31769
|
throw new Error("Max concurrency reached");
|
|
31591
31770
|
}
|
|
31771
|
+
let releasePromise;
|
|
31772
|
+
const release4 = () => releasePromise ??= releaseLock(lock);
|
|
31592
31773
|
try {
|
|
31593
|
-
return await _invoke(options,
|
|
31774
|
+
return await _invoke(options, release4);
|
|
31594
31775
|
} catch (err) {
|
|
31595
|
-
await
|
|
31776
|
+
await release4();
|
|
31596
31777
|
throw err;
|
|
31597
31778
|
}
|
|
31598
31779
|
}
|
|
@@ -31861,16 +32042,21 @@ var ChatMessage = class {
|
|
|
31861
32042
|
};
|
|
31862
32043
|
var adapters = {
|
|
31863
32044
|
"anthropic.claude-instant-v1": AnthropicClaudeChatAdapter,
|
|
31864
|
-
"anthropic.claude-v1": AnthropicClaudeChatAdapter,
|
|
31865
32045
|
"anthropic.claude-v2": AnthropicClaudeChatAdapter,
|
|
31866
32046
|
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
32047
|
+
"anthropic.claude-3-haiku-20240307-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
32048
|
+
"anthropic.claude-3-opus-20240229-v1:0": AnthropicClaudeSonnetChatAdapter,
|
|
31867
32049
|
"ai21.j2-mid-v1": Ai21JurassicChatAdapter,
|
|
31868
32050
|
"ai21.j2-ultra-v1": Ai21JurassicChatAdapter,
|
|
31869
32051
|
"cohere.command-text-v14": CohereCommandChatAdapter,
|
|
31870
32052
|
"cohere.command-light-text-v14": CohereCommandChatAdapter,
|
|
31871
32053
|
"meta.llama2-13b-chat-v1": MetaLlamaChatAdapter,
|
|
32054
|
+
"meta.llama2-70b-chat-v1": MetaLlamaChatAdapter,
|
|
32055
|
+
"meta.llama3-8b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
32056
|
+
"meta.llama3-70b-instruct-v1:0": MetaLlamaChatAdapter,
|
|
31872
32057
|
"mistral.mistral-7b-instruct-v0:2": MixtralAIChatAdapter,
|
|
31873
|
-
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter
|
|
32058
|
+
"mistral.mixtral-8x7b-instruct-v0:1": MixtralAIChatAdapter,
|
|
32059
|
+
"mistral.mistral-large-2402-v1:0": MixtralAIChatAdapter
|
|
31874
32060
|
};
|
|
31875
32061
|
async function chat(messages, options = {}) {
|
|
31876
32062
|
const modelId = options.modelId ?? "anthropic.claude-instant-v1";
|
|
@@ -31886,16 +32072,21 @@ async function chat(messages, options = {}) {
|
|
|
31886
32072
|
chat.models = async () => {
|
|
31887
32073
|
return [
|
|
31888
32074
|
"anthropic.claude-instant-v1",
|
|
31889
|
-
"anthropic.claude-v1",
|
|
31890
32075
|
"anthropic.claude-v2",
|
|
31891
32076
|
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
32077
|
+
"anthropic.claude-3-haiku-20240307-v1:0",
|
|
32078
|
+
"anthropic.claude-3-opus-20240229-v1:0",
|
|
31892
32079
|
"ai21.j2-mid-v1",
|
|
31893
32080
|
"ai21.j2-ultra-v1",
|
|
31894
32081
|
"cohere.command-text-v14",
|
|
31895
32082
|
"cohere.command-light-text-v14",
|
|
31896
32083
|
"meta.llama2-13b-chat-v1",
|
|
32084
|
+
"meta.llama2-70b-chat-v1",
|
|
32085
|
+
"meta.llama3-8b-instruct-v1:0",
|
|
32086
|
+
"meta.llama3-70b-instruct-v1:0",
|
|
31897
32087
|
"mistral.mistral-7b-instruct-v0:2",
|
|
31898
|
-
"mistral.mixtral-8x7b-instruct-v0:1"
|
|
32088
|
+
"mistral.mixtral-8x7b-instruct-v0:1",
|
|
32089
|
+
"mistral.mistral-large-2402-v1:0"
|
|
31899
32090
|
];
|
|
31900
32091
|
};
|
|
31901
32092
|
|
|
@@ -31929,11 +32120,12 @@ var CohereEmbedAdapter = class {
|
|
|
31929
32120
|
// src/embed/index.ts
|
|
31930
32121
|
var adapters2 = {
|
|
31931
32122
|
"amazon.titan-embed-text-v1": AmazonTitanEmbedTextAdapter,
|
|
32123
|
+
"amazon.titan-embed-text-v2:0": AmazonTitanEmbedTextAdapter,
|
|
31932
32124
|
"cohere.embed-english-v3": CohereEmbedAdapter,
|
|
31933
32125
|
"cohere.embed-multilingual-v3": CohereEmbedAdapter
|
|
31934
32126
|
};
|
|
31935
32127
|
async function embed(input, options = {}) {
|
|
31936
|
-
const modelId = options.modelId ?? "amazon.titan-embed-text-
|
|
32128
|
+
const modelId = options.modelId ?? "amazon.titan-embed-text-v2:0";
|
|
31937
32129
|
const AdapterClass = adapters2[modelId];
|
|
31938
32130
|
if (!AdapterClass) {
|
|
31939
32131
|
throw new Error(`No adapter found for model ${modelId}`);
|
|
@@ -31949,7 +32141,7 @@ embed.models = async () => {
|
|
|
31949
32141
|
|
|
31950
32142
|
// src/render.ts
|
|
31951
32143
|
async function render(prompt, options = {}) {
|
|
31952
|
-
const modelId = options.modelId ?? "stability.stable-diffusion-xl-
|
|
32144
|
+
const modelId = options.modelId ?? "stability.stable-diffusion-xl-v1";
|
|
31953
32145
|
const body = {
|
|
31954
32146
|
text_prompts: [
|
|
31955
32147
|
{
|
|
@@ -31959,8 +32151,8 @@ async function render(prompt, options = {}) {
|
|
|
31959
32151
|
cfg_scale: options.scale ?? 10,
|
|
31960
32152
|
seed: options.seed ?? 20,
|
|
31961
32153
|
steps: options.steps ?? 50,
|
|
31962
|
-
width: options.width ??
|
|
31963
|
-
height: options.height ??
|
|
32154
|
+
width: options.width ?? 1024,
|
|
32155
|
+
height: options.height ?? 1024
|
|
31964
32156
|
};
|
|
31965
32157
|
const response = await invoke2({ body, modelId });
|
|
31966
32158
|
if (!response.body) {
|
|
@@ -31976,7 +32168,7 @@ async function render(prompt, options = {}) {
|
|
|
31976
32168
|
return new Response(responseBody, { headers: { "Content-Type": "image/png" } });
|
|
31977
32169
|
}
|
|
31978
32170
|
render.models = async () => {
|
|
31979
|
-
return ["stability.stable-diffusion-xl-
|
|
32171
|
+
return ["stability.stable-diffusion-xl-v1"];
|
|
31980
32172
|
};
|
|
31981
32173
|
|
|
31982
32174
|
// src/summarize/adapters/anthropic.claude.sonnet.ts
|
|
@@ -32082,7 +32274,7 @@ var MixtralAISummarizeAdapter = class {
|
|
|
32082
32274
|
// src/summarize/index.ts
|
|
32083
32275
|
var adapters3 = {
|
|
32084
32276
|
"anthropic.claude-instant-v1": AnthropicClaudeSummarizeAdapter,
|
|
32085
|
-
|
|
32277
|
+
// 'anthropic.claude-v1': AnthropicClaudeSummarizeAdapter,
|
|
32086
32278
|
"anthropic.claude-v2": AnthropicClaudeSummarizeAdapter,
|
|
32087
32279
|
"anthropic.claude-3-sonnet-20240229-v1:0": AnthropicClaudeSonnetSummarizeAdapter,
|
|
32088
32280
|
"mistral.mistral-7b-instruct-v0:2": MixtralAISummarizeAdapter,
|
|
@@ -32102,7 +32294,7 @@ async function summarize(input, options = {}) {
|
|
|
32102
32294
|
summarize.models = async () => {
|
|
32103
32295
|
return [
|
|
32104
32296
|
"anthropic.claude-instant-v1",
|
|
32105
|
-
|
|
32297
|
+
// 'anthropic.claude-v1',
|
|
32106
32298
|
"anthropic.claude-v2",
|
|
32107
32299
|
"anthropic.claude-3-sonnet-20240229-v1:0",
|
|
32108
32300
|
"mistral.mistral-7b-instruct-v0:2",
|
|
@@ -42306,7 +42498,7 @@ createAggregatedClient2(commands4, Translate);
|
|
|
42306
42498
|
// src/translate.ts
|
|
42307
42499
|
var region2 = process.env.AWS_REGION ?? "us-east-1";
|
|
42308
42500
|
var client = new Translate({ credentialDefaultProvider: credentialsProvider, region: region2 });
|
|
42309
|
-
async function _translate(input, options,
|
|
42501
|
+
async function _translate(input, options, release4) {
|
|
42310
42502
|
const auto = options.sourceLanguage === "auto";
|
|
42311
42503
|
const result = await client.translateText({
|
|
42312
42504
|
SourceLanguageCode: options.sourceLanguage,
|
|
@@ -42320,12 +42512,11 @@ async function _translate(input, options, lock) {
|
|
|
42320
42512
|
const comprehendUsage = auto ? Math.max(3e4, input.length * 100) : 0;
|
|
42321
42513
|
const translateUsage = input.length * 1500;
|
|
42322
42514
|
telemetry_default.count("inferenceUsage", comprehendUsage + translateUsage, "ai");
|
|
42323
|
-
|
|
42324
|
-
responseBody = new ReadableStream({
|
|
42325
|
-
|
|
42515
|
+
await release4();
|
|
42516
|
+
const responseBody = new ReadableStream({
|
|
42517
|
+
pull(controller) {
|
|
42326
42518
|
controller.enqueue(Buffer.from(translatedText, "utf8"));
|
|
42327
42519
|
controller.close();
|
|
42328
|
-
await releaseLock(lock);
|
|
42329
42520
|
}
|
|
42330
42521
|
});
|
|
42331
42522
|
return new Response(responseBody, {
|
|
@@ -42353,10 +42544,12 @@ async function translate(input, options) {
|
|
|
42353
42544
|
if (!lock.acquired) {
|
|
42354
42545
|
throw new Error("Max concurrency reached");
|
|
42355
42546
|
}
|
|
42547
|
+
let releasePromise;
|
|
42548
|
+
const release4 = () => releasePromise ??= releaseLock(lock);
|
|
42356
42549
|
try {
|
|
42357
|
-
return await _translate(input, options,
|
|
42550
|
+
return await _translate(input, options, release4);
|
|
42358
42551
|
} catch (err) {
|
|
42359
|
-
await
|
|
42552
|
+
await release4();
|
|
42360
42553
|
throw err;
|
|
42361
42554
|
}
|
|
42362
42555
|
}
|
|
@@ -42364,7 +42557,7 @@ async function translate(input, options) {
|
|
|
42364
42557
|
// src/index.ts
|
|
42365
42558
|
if (process.env.AMPT_RUNTIME_NAME === "nodejs18-beta") {
|
|
42366
42559
|
console.error(
|
|
42367
|
-
'@ampt/ai requires the nodejs18 runtime. Please add "runtime": "
|
|
42560
|
+
'@ampt/ai requires the nodejs18 runtime or higher. Please add "runtime": "nodejs20" to the "ampt" section of your package.json.'
|
|
42368
42561
|
);
|
|
42369
42562
|
}
|
|
42370
42563
|
export {
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampt/ai",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"prepublishOnly": "npm run build",
|
|
10
|
-
"build": "tsup"
|
|
10
|
+
"build": "tsup",
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"typecheck": "tsc -b ."
|
|
11
13
|
},
|
|
12
14
|
"exports": {
|
|
13
15
|
".": {
|